refactor: pep8

This commit is contained in:
DoroWu 2018-02-25 16:21:54 +08:00
parent 0de27e4a31
commit 338b97b063

View file

@ -3,12 +3,18 @@ from flask import (Flask,
abort, abort,
) )
import os import os
import json
from functools import wraps
import subprocess
import time
# Flask app # Flask app
app = Flask(__name__, app = Flask(
__name__,
static_folder='static', static_url_path='', static_folder='static', static_url_path='',
instance_relative_config=True) instance_relative_config=True
)
CONFIG = os.environ.get('CONFIG') or 'config.Development' CONFIG = os.environ.get('CONFIG') or 'config.Development'
app.config.from_object('config.Default') app.config.from_object('config.Default')
app.config.from_object(CONFIG) app.config.from_object(CONFIG)
@ -18,16 +24,8 @@ import logging
from log.config import LoggingConfiguration from log.config import LoggingConfiguration
LoggingConfiguration.set( LoggingConfiguration.set(
logging.DEBUG if os.getenv('DEBUG') else logging.INFO, logging.DEBUG if os.getenv('DEBUG') else logging.INFO,
'lightop.log', name='Web') '/var/log/web.log'
)
import json
from functools import wraps
import subprocess
import time
FIRST = True
def exception_to_json(func): def exception_to_json(func):
@ -68,7 +66,8 @@ HTML_INDEX = '''<html><head>
g = d.getElementsByTagName('body')[0], g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth, x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight; y = w.innerHeight|| e.clientHeight|| g.clientHeight;
window.location.href = "redirect.html?width=" + x + "&height=" + (parseInt(y)); var url = "redirect.html?width=" + x + "&height=" + (parseInt(y));
window.location.href = url;
</script> </script>
<title>Page Redirection</title> <title>Page Redirection</title>
</head><body></body></html>''' </head><body></body></html>'''
@ -104,18 +103,28 @@ def redirectme():
env['height'] = request.args['height'] env['height'] = request.args['height']
# sed # sed
subprocess.check_call(r"sed -i 's#^command=/usr/bin/Xvfb.*$#command=/usr/bin/Xvfb :1 -screen 0 {width}x{height}x16#' /etc/supervisor/conf.d/supervisord.conf".format(**env), cmd = (
shell=True) 'sed -i \'s#'
'^command=/usr/bin/Xvfb.*$'
'#'
'command=/usr/bin/Xvfb :1 -screen 0 {width}x{height}x16'
'#\' /etc/supervisor/conf.d/supervisord.conf'
).format(**env),
subprocess.check_call(cmd, shell=True)
# supervisorctrl reload # supervisorctrl reload
subprocess.check_call(r"supervisorctl reload", shell=True) subprocess.check_call(['supervisorctl', 'reload'])
# check all running # check all running
for i in xrange(20): for i in range(40):
output = subprocess.check_output(r"supervisorctl status | grep RUNNING | wc -l", shell=True) output = subprocess.check_output(['supervisorctl', 'status'])
if output.strip() == "6": for line in output.strip().split('\n'):
if line.find('RUNNING') < 0:
break
else:
FIRST = False FIRST = False
return HTML_REDIRECT return HTML_REDIRECT
time.sleep(2) time.sleep(1)
logging.info('wait services is ready...')
abort(500, 'service is not ready, please restart container') abort(500, 'service is not ready, please restart container')