Commit 17a77af3 authored by Marco Mariani's avatar Marco Mariani

runner: reversed 'if not' logic, function guards, typos

parent 0ad53e01
......@@ -182,6 +182,7 @@ def updateProxy(config):
computer.updateConfiguration(xml_marshaller.xml_marshaller.dumps(slap_config))
return True
def updateInstanceParameter(config, software_type=None):
"""
Reconfigure Slapproxy to re-deploy current Software Instance with parameters.
......@@ -193,9 +194,12 @@ def updateInstanceParameter(config, software_type=None):
if not (updateProxy(config) and requestInstance(config, software_type)):
return False
def startProxy(config):
"""Start Slapproxy server"""
if not isRunning('slapproxy'):
if isRunning('slapproxy'):
return
log = os.path.join(config['log_dir'], 'slapproxy.log')
Popen([config['slapproxy'], '--log_file', log,
config['configuration_file_path']],
......@@ -219,6 +223,7 @@ def isSoftwareRunning(config=None):
"""
Return True if slapgrid-sr is still running and false if slapgrid if not
"""
# XXX-Marco what is 'config' for?
return isRunning('slapgrid-sr')
......@@ -227,8 +232,10 @@ def runSoftwareWithLock(config):
Use Slapgrid to compile current Software Release and wait until
compilation is done
"""
if isSoftwareRunning():
return False
slapgrid_pid = os.path.join(config['run_dir'], 'slapgrid-sr.pid')
if not isSoftwareRunning():
if not os.path.exists(config['software_root']):
os.mkdir(config['software_root'])
stopProxy(config)
......@@ -238,6 +245,7 @@ def runSoftwareWithLock(config):
if not updateProxy(config):
return False
# Accelerate compilation by setting make -jX
# XXX-Marco can have issues with implicit dependencies or recursive makefiles. should be configurable.
environment = os.environ.copy()
environment['MAKEFLAGS'] = '-j%r' % multiprocessing.cpu_count()
slapgrid = Popen([config['slapgrid_sr'], '-vc',
......@@ -249,7 +257,7 @@ def runSoftwareWithLock(config):
#Saves the current compile software for re-use
config_SR_folder(config)
return True
return False
def config_SR_folder(config):
"""Create a symbolik link for each folder in software folder. That allow
......@@ -302,8 +310,9 @@ def loadSoftwareRList(config):
def isInstanceRunning(config=None):
"""
Return True if slapgrid-cp is still running and false if slapgrid if not
Return True if slapgrid-cp is still running and False otherwise
"""
# XXX-Marco what is 'config' for?
return isRunning('slapgrid-cp')
......@@ -312,8 +321,10 @@ def runInstanceWithLock(config):
Use Slapgrid to deploy current Software Release and wait until
deployment is done.
"""
if isInstanceRunning():
return False
slapgrid_pid = os.path.join(config['run_dir'], 'slapgrid-cp.pid')
if not isInstanceRunning():
startProxy(config)
logfile = open(config['instance_log'], 'w')
if not (updateProxy(config) and requestInstance(config)):
......@@ -324,7 +335,7 @@ def runInstanceWithLock(config):
stdout=logfile, name='slapgrid-cp')
slapgrid.wait()
return True
return False
def getProfilePath(projectDir, profile):
"""
......@@ -431,11 +442,12 @@ def getFolderContent(config, folder):
r = ['<ul class="jqueryFileTree" style="display: none;">']
d = urllib.unquote(folder)
realdir = realpath(config, d)
if not realdir:
if realdir:
ldir = sorted(os.listdir(realdir), key=str.lower)
else:
r.append('Could not load directory: Permission denied')
ldir = []
else:
ldir = sorted(os.listdir(realdir), key=str.lower)
for f in ldir:
if f.startswith('.'): #do not displays this file/folder
continue
......
......@@ -47,7 +47,9 @@ def login_redirect(*args, **kwargs):
#Access Control: Only static files and login pages are allowed to guest
@app.before_request
def before_request():
if not request.path.startswith('/static'):
if request.path.startswith('/static'):
return
account = getSession(app.config)
if account:
user = AuthUser(username=account[0])
......@@ -59,6 +61,7 @@ def before_request():
if request.path != "/setAccount" and request.path != "/configAccount":
return redirect(url_for('setAccount'))
# general views
@login_required()
def home():
......@@ -179,7 +182,7 @@ def inspectInstance():
@login_required()
def supervisordStatus():
result = getSvcStatus(app.config)
if not (result):
if not result:
return jsonify(code=0, result="")
html = "<tr><th>Partition and Process name</th><th>Status</th><th>Process PID </th><th> UpTime</th><th></th></tr>"
for item in result:
......@@ -521,29 +524,36 @@ def getParameterXml(request):
else:
return jsonify(code=1, result=parameters)
#update user account data
@login_required()
def updateAccount():
account = []
account.append(request.form['username'].strip())
account.append(request.form['password'].strip())
account.append(request.form['email'].strip())
account.append(request.form['name'].strip())
code = request.form['rcode'].strip()
recovery_code = open(os.path.join(app.config['etc_dir'], ".rcode"), "r").read()
if code != recovery_code:
return jsonify(code=0, result="Your password recovery code is not valid!")
account = [
request.form['username'].strip(),
request.form['password'].strip(),
request.form['email'].strip(),
request.form['name'].strip()
]
result = saveSession(app.config, account)
if type(result) == type(""):
return jsonify(code=0, result=result)
else:
return jsonify(code=1, result="")
#update user account data
@app.route("/configAccount", methods=['POST'])
def configAccount():
last_account = getSession(app.config)
if not last_account:
if last_account:
return jsonify(code=0,
result="Unable to respond to your request, permission denied.")
account = []
account.append(request.form['username'].strip())
account.append(request.form['password'].strip())
......@@ -559,8 +569,7 @@ def configAccount():
return jsonify(code=0, result=result)
else:
return jsonify(code=1, result="")
return jsonify(code=0,
result="Unable to respond to your request, permission denied.")
#Global File Manager
@login_required()
......@@ -576,6 +585,7 @@ def fileBrowser():
opt = int(request.form['opt'])
else:
opt = int(request.args.get('opt'))
try:
if opt == 1:
#list files and directories
......
Markdown is supported
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