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