Skip to content

Commit 338b97b

Browse files
committed
refactor: pep8
1 parent 0de27e4 commit 338b97b

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

image/usr/lib/web/lightop/__init__.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
abort,
44
)
55
import os
6+
import json
7+
from functools import wraps
8+
import subprocess
9+
import time
610

711

812
# Flask app
9-
app = Flask(__name__,
10-
static_folder='static', static_url_path='',
11-
instance_relative_config=True)
13+
app = Flask(
14+
__name__,
15+
static_folder='static', static_url_path='',
16+
instance_relative_config=True
17+
)
1218
CONFIG = os.environ.get('CONFIG') or 'config.Development'
1319
app.config.from_object('config.Default')
1420
app.config.from_object(CONFIG)
@@ -18,16 +24,8 @@
1824
from log.config import LoggingConfiguration
1925
LoggingConfiguration.set(
2026
logging.DEBUG if os.getenv('DEBUG') else logging.INFO,
21-
'lightop.log', name='Web')
22-
23-
24-
import json
25-
from functools import wraps
26-
import subprocess
27-
import time
28-
29-
30-
FIRST = True
27+
'/var/log/web.log'
28+
)
3129

3230

3331
def exception_to_json(func):
@@ -68,7 +66,8 @@ class BadRequest(Exception):
6866
g = d.getElementsByTagName('body')[0],
6967
x = w.innerWidth || e.clientWidth || g.clientWidth,
7068
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
71-
window.location.href = "redirect.html?width=" + x + "&height=" + (parseInt(y));
69+
var url = "redirect.html?width=" + x + "&height=" + (parseInt(y));
70+
window.location.href = url;
7271
</script>
7372
<title>Page Redirection</title>
7473
</head><body></body></html>'''
@@ -104,18 +103,28 @@ def redirectme():
104103
env['height'] = request.args['height']
105104

106105
# sed
107-
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),
108-
shell=True)
106+
cmd = (
107+
'sed -i \'s#'
108+
'^command=/usr/bin/Xvfb.*$'
109+
'#'
110+
'command=/usr/bin/Xvfb :1 -screen 0 {width}x{height}x16'
111+
'#\' /etc/supervisor/conf.d/supervisord.conf'
112+
).format(**env),
113+
subprocess.check_call(cmd, shell=True)
109114
# supervisorctrl reload
110-
subprocess.check_call(r"supervisorctl reload", shell=True)
115+
subprocess.check_call(['supervisorctl', 'reload'])
111116

112117
# check all running
113-
for i in xrange(20):
114-
output = subprocess.check_output(r"supervisorctl status | grep RUNNING | wc -l", shell=True)
115-
if output.strip() == "6":
118+
for i in range(40):
119+
output = subprocess.check_output(['supervisorctl', 'status'])
120+
for line in output.strip().split('\n'):
121+
if line.find('RUNNING') < 0:
122+
break
123+
else:
116124
FIRST = False
117125
return HTML_REDIRECT
118-
time.sleep(2)
126+
time.sleep(1)
127+
logging.info('wait services is ready...')
119128
abort(500, 'service is not ready, please restart container')
120129

121130

0 commit comments

Comments
 (0)