Commit 8cddd645 authored by Aleksey Shirokih's avatar Aleksey Shirokih
Browse files

Move to python3. initial

parent 6524a628
...@@ -14,4 +14,5 @@ share/ ...@@ -14,4 +14,5 @@ share/
include/ include/
lib/ lib/
share/ share/
var/ var/
\ No newline at end of file venv/
...@@ -5,15 +5,15 @@ certifi==2016.9.26 ...@@ -5,15 +5,15 @@ certifi==2016.9.26
paramiko==2.1.2 paramiko==2.1.2
cffi>=0.8.5 cffi>=0.8.5
futures>=2.2.0 futures>=2.2.0
future==0.16.0
peewee==2.10.2 peewee==2.10.2
pycparser>=2.10 pycparser>=2.10
singledispatch>=3.4.0.0 singledispatch>=3.4.0.0
six>=1.8.0 six>=1.8.0
tornado==4.4.2 tornado==4.5.2
ansible ansible
setuptools>=11.3 setuptools>=11.3
packaging packaging
appdirs appdirs
netaddr netaddr
#gittornado jmespath==0.9.3
jmespath==0.9.3
\ No newline at end of file
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Python modules # Python modules
from builtins import object
import base64 import base64
# Third-party modules # Third-party modules
...@@ -14,6 +15,7 @@ import tornado.web ...@@ -14,6 +15,7 @@ import tornado.web
# Tower modules # Tower modules
from tower.models.user import User from tower.models.user import User
from future.utils import with_metaclass
class BaseHandler(tornado.web.RequestHandler): class BaseHandler(tornado.web.RequestHandler):
...@@ -71,8 +73,7 @@ def open_api(method): ...@@ -71,8 +73,7 @@ def open_api(method):
return method return method
class API(object): class API(with_metaclass(APIBase, object)):
__metaclass__ = APIBase
name = None name = None
def __init__(self, handler): def __init__(self, handler):
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
from __future__ import absolute_import from __future__ import absolute_import
from builtins import str
from builtins import zip
from builtins import range
import datetime import datetime
# Python modules # Python modules
import logging import logging
...@@ -210,7 +213,7 @@ class DeployHandler(BaseHandler): ...@@ -210,7 +213,7 @@ class DeployHandler(BaseHandler):
def on_data(self, data): def on_data(self, data):
def qlog(x): def qlog(x):
if x.endswith("\n"): if x.decode('utf-8').endswith("\n"):
return x[:-1] return x[:-1]
else: else:
return x return x
...@@ -232,7 +235,7 @@ class DeployHandler(BaseHandler): ...@@ -232,7 +235,7 @@ class DeployHandler(BaseHandler):
except tornado.iostream.StreamClosedError: except tornado.iostream.StreamClosedError:
pass pass
recap = [0, 0, 0, 0] recap = [0, 0, 0, 0]
for v in self.recap.itervalues(): for v in self.recap.values():
recap = [(x + y) for x, y in zip(recap, v)] recap = [(x + y) for x, y in zip(recap, v)]
with db.atomic(): with db.atomic():
self.job_log.complete_ts = datetime.datetime.now() self.job_log.complete_ts = datetime.datetime.now()
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
# Python modules # Python modules
from __future__ import absolute_import from __future__ import absolute_import
from builtins import str
import json import json
import logging import logging
import peewee import peewee
...@@ -44,7 +45,7 @@ class JSONRPCHandler(BaseHandler): ...@@ -44,7 +45,7 @@ class JSONRPCHandler(BaseHandler):
raise HTTPError(404, "Invalid API: %s" % api_name) raise HTTPError(404, "Invalid API: %s" % api_name)
# Parse request # Parse request
try: try:
req = json.loads(self.request.body) req = json.loads(self.request.body.decode('utf-8'))
except ValueError as why: except ValueError as why:
raise HTTPError(400, "Bad request: %s" % why) raise HTTPError(400, "Bad request: %s" % why)
# Parse request # Parse request
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
# Third-party modules # Third-party modules
from __future__ import absolute_import from __future__ import absolute_import
from builtins import str
import peewee import peewee
from .base import API, api, APIError from .base import API, api, APIError
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
# Python modules # Python modules
from __future__ import absolute_import from __future__ import absolute_import
from builtins import str
from builtins import range
import os import os
# Third-party modules # Third-party modules
...@@ -55,7 +57,7 @@ class ServiceAPI(API): ...@@ -55,7 +57,7 @@ class ServiceAPI(API):
if "forms" not in cfg or not cfg["forms"]: if "forms" not in cfg or not cfg["forms"]:
return r return r
sc = cfg["forms"][service] sc = cfg["forms"][service]
for k, v in sc.iteritems(): for k, v in sc.items():
if "description" in k: if "description" in k:
continue continue
r[k] = v.get("default", None) r[k] = v.get("default", None)
...@@ -78,7 +80,7 @@ class ServiceAPI(API): ...@@ -78,7 +80,7 @@ class ServiceAPI(API):
"autoheight": "true", "autoheight": "true",
"template": descr.get("description", "") "template": descr.get("description", "")
} }
for k, v in descr.iteritems(): for k, v in descr.items():
if "description" in k: if "description" in k:
continue continue
c = { c = {
......
...@@ -54,7 +54,7 @@ class UIHandler(tornado.web.RequestHandler): ...@@ -54,7 +54,7 @@ class UIHandler(tornado.web.RequestHandler):
ssize = len(js) ssize = len(js)
js = jsmin.jsmin(js) js = jsmin.jsmin(js)
logger.info("Minifying JS: %s -> %s", ssize, len(js)) logger.info("Minifying JS: %s -> %s", ssize, len(js))
self.hash = hashlib.sha256(js).hexdigest()[:8] self.hash = hashlib.sha256(js.encode(encoding='utf-8')).hexdigest()[:8]
cache_path = os.path.join(self.CACHE_ROOT, "%s.js" % self.hash) cache_path = os.path.join(self.CACHE_ROOT, "%s.js" % self.hash)
if not os.path.isfile(cache_path): if not os.path.isfile(cache_path):
logger.info("Writing cached JS to %s", cache_path) logger.info("Writing cached JS to %s", cache_path)
...@@ -72,6 +72,6 @@ class UIHandler(tornado.web.RequestHandler): ...@@ -72,6 +72,6 @@ class UIHandler(tornado.web.RequestHandler):
if fp.startswith("/ui/"): if fp.startswith("/ui/"):
fp = fp[4:] fp = fp[4:]
fp = os.path.join(self.root, fp) fp = os.path.join(self.root, fp)
with open(fp) as f: with open(fp, 'r') as f:
hash = hashlib.sha256(f.read()).hexdigest()[:8] hash = hashlib.sha256(f.read().encode(encoding='utf-8')).hexdigest()[:8]
return "%s?%s" % (path, hash) return "%s?%s" % (path, hash)
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
from __future__ import print_function from __future__ import print_function
import Queue from future import standard_library
standard_library.install_aliases()
from builtins import range
import queue
import argparse import argparse
# Python modules # Python modules
import os import os
...@@ -60,7 +63,7 @@ def collect_crashinfo(options, args): ...@@ -60,7 +63,7 @@ def collect_crashinfo(options, args):
env = Environment.get(Environment.name == options.env) env = Environment.get(Environment.name == options.env)
except Environment.DoesNotExist: except Environment.DoesNotExist:
die("Invalid environment: '%s'" % options.env) die("Invalid environment: '%s'" % options.env)
q = Queue.Queue() q = queue.Queue()
# Start workers # Start workers
workers = [] workers = []
for i in range(options.jobs): for i in range(options.jobs):
......
...@@ -33,7 +33,7 @@ class OrderedDictYAMLLoader(yaml.Loader): ...@@ -33,7 +33,7 @@ class OrderedDictYAMLLoader(yaml.Loader):
key = self.construct_object(key_node, deep=deep) key = self.construct_object(key_node, deep=deep)
try: try:
hash(key) hash(key)
except TypeError, exc: except TypeError as exc:
raise yaml.constructor.ConstructorError('while constructing a mapping', raise yaml.constructor.ConstructorError('while constructing a mapping',
node.start_mark, 'found unacceptable key (%s)' % exc, node.start_mark, 'found unacceptable key (%s)' % exc,
key_node.start_mark) key_node.start_mark)
......
from builtins import object
from peewee import Model, CharField, TextField from peewee import Model, CharField, TextField
class Settings(Model): class Settings(Model):
class Meta: class Meta(object):
db_table = "settings" db_table = "settings"
key = CharField(primary_key=True) key = CharField(primary_key=True)
......
from builtins import object
from peewee import Model, CharField, BooleanField from peewee import Model, CharField, BooleanField
class User(Model): class User(Model):
class Meta: class Meta(object):
db_table = "user" db_table = "user"
name = CharField(unique=True) name = CharField(unique=True)
......
from builtins import object
from peewee import Model, CharField, BooleanField from peewee import Model, CharField, BooleanField
def migrate(migrator): def migrate(migrator):
class User(Model): class User(Model):
class Meta: class Meta(object):
database = migrator.db database = migrator.db
db_table = "user" db_table = "user"
......
from builtins import object
from peewee import Model, CharField, TextField from peewee import Model, CharField, TextField
class Environment(Model): class Environment(Model):
class Meta: class Meta(object):
db_table = "environment" db_table = "environment"
name = CharField(unique=True) name = CharField(unique=True)
......
from builtins import object
from peewee import Model, CharField, TextField from peewee import Model, CharField, TextField
class Datacenter(Model): class Datacenter(Model):
class Meta: class Meta(object):
db_table = "datacenter" db_table = "datacenter"
name = CharField(unique=True) name = CharField(unique=True)
......
from builtins import object
from peewee import Model, CharField, TextField, ForeignKeyField from peewee import Model, CharField, TextField, ForeignKeyField
class Environment(Model): class Environment(Model):
class Meta: class Meta(object):
db_table = "environment" db_table = "environment"
class Pool(Model): class Pool(Model):
class Meta: class Meta(object):
db_table = "pool" db_table = "pool"
indexes = ( indexes = (
(("environment_id", "name"), True), (("environment_id", "name"), True),
......
from builtins import object
from peewee import Model, CharField, TextField, ForeignKeyField from peewee import Model, CharField, TextField, ForeignKeyField
class Environment(Model): class Environment(Model):
class Meta: class Meta(object):
db_table = "environment" db_table = "environment"
class Datacenter(Model): class Datacenter(Model):
class Meta: class Meta(object):
db_table = "datacenter" db_table = "datacenter"
class Node(Model): class Node(Model):
class Meta: class Meta(object):
db_table = "node" db_table = "node"
indexes = ( indexes = (
(("environment", "name"), True), (("environment", "name"), True),
......
from builtins import object
from peewee import (Model, CharField, TextField, ForeignKeyField, from peewee import (Model, CharField, TextField, ForeignKeyField,
DateTimeField, BooleanField, IntegerField) DateTimeField, BooleanField, IntegerField)
class Environment(Model): class Environment(Model):
class Meta: class Meta(object):
db_table = "environment" db_table = "environment"
class JobLog(Model): class JobLog(Model):
class Meta: class Meta(object):
db_table = "joblog" db_table = "joblog"
start_ts = DateTimeField() start_ts = DateTimeField()
......
from builtins import object
from peewee import Model, CharField, IntegerField, ForeignKeyField from peewee import Model, CharField, IntegerField, ForeignKeyField
class Environment(Model): class Environment(Model):
class Meta: class Meta(object):
db_table = "environment" db_table = "environment"
class Pool(Model): class Pool(Model):
class Meta: class Meta(object):
db_table = "pool" db_table = "pool"
class Node(Model): class Node(Model):
class Meta: class Meta(object):
db_table = "node" db_table = "node"
class Service(Model): class Service(Model):
class Meta: class Meta(object):
db_table = "service" db_table = "service"
environment = ForeignKeyField(Environment, on_delete="RESTRICT") environment = ForeignKeyField(Environment, on_delete="RESTRICT")
......
from builtins import object
from peewee import (Model, CharField, TextField, ForeignKeyField, from peewee import (Model, CharField, TextField, ForeignKeyField,
DateTimeField, BooleanField) DateTimeField, BooleanField)
class Environment(Model): class Environment(Model):
class Meta: class Meta(object):
db_table = "environment" db_table = "environment"
class PullLog(Model): class PullLog(Model):
class Meta: class Meta(object):
db_table = "pulllog" db_table = "pulllog"
start_ts = DateTimeField() start_ts = DateTimeField()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment