Commit 33e68311 authored by Marco Mariani's avatar Marco Mariani

"except ... as .." syntax

parent 956dea7a
...@@ -109,7 +109,7 @@ def run(): ...@@ -109,7 +109,7 @@ def run():
serve(config) serve(config)
return_code = 0 return_code = 0
except SystemExit, err: except SystemExit as err:
# Catch exception raise by optparse # Catch exception raise by optparse
return_code = err return_code = err
......
...@@ -98,7 +98,7 @@ class fileBrowser(object): ...@@ -98,7 +98,7 @@ class fileBrowser(object):
shutil.rmtree(file) shutil.rmtree(file)
else: else:
os.unlink(file) os.unlink(file)
except Exception, e: except Exception as e:
return str(e) return str(e)
return '{result: \'1\'}' return '{result: \'1\'}'
...@@ -126,7 +126,7 @@ class fileBrowser(object): ...@@ -126,7 +126,7 @@ class fileBrowser(object):
shutil.copy(realfile, dest) shutil.copy(realfile, dest)
if del_source: if del_source:
os.unlink(realfile) os.unlink(realfile)
except Exception, e: except Exception as e:
return str(e) return str(e)
return '{result: \'1\'}' return '{result: \'1\'}'
......
...@@ -48,7 +48,7 @@ def cloneRepo(data): ...@@ -48,7 +48,7 @@ def cloneRepo(data):
if data["email"] != "": if data["email"] != "":
config_writer.set_value("user", "email", data["email"]) config_writer.set_value("user", "email", data["email"])
code = 1 code = 1
except Exception, e: except Exception as e:
json = safeResult(str(e)) json = safeResult(str(e))
if os.path.exists(workDir): if os.path.exists(workDir):
shutil.rmtree(workDir) shutil.rmtree(workDir)
...@@ -69,7 +69,7 @@ def gitStatus(project): ...@@ -69,7 +69,7 @@ def gitStatus(project):
branch = git.branch().replace(' ', '').split('\n') branch = git.branch().replace(' ', '').split('\n')
isdirty = repo.is_dirty(untracked_files=True) isdirty = repo.is_dirty(untracked_files=True)
code = 1 code = 1
except Exception, e: except Exception as e:
json = safeResult(str(e)) json = safeResult(str(e))
return jsonify(code=code, result=json, branch=branch, dirty=isdirty) return jsonify(code=code, result=json, branch=branch, dirty=isdirty)
...@@ -91,7 +91,7 @@ def switchBranch(project, name): ...@@ -91,7 +91,7 @@ def switchBranch(project, name):
git = repo.git git = repo.git
git.checkout(name) git.checkout(name)
code = 1 code = 1
except Exception, e: except Exception as e:
json = safeResult(str(e)) json = safeResult(str(e))
return jsonify(code=code, result=json) return jsonify(code=code, result=json)
...@@ -113,7 +113,7 @@ def addBranch(project, name, onlyCheckout=False): ...@@ -113,7 +113,7 @@ def addBranch(project, name, onlyCheckout=False):
else: else:
git.checkout(name) git.checkout(name)
code = 1 code = 1
except Exception, e: except Exception as e:
json = safeResult(str(e)) json = safeResult(str(e))
return jsonify(code=code, result=json) return jsonify(code=code, result=json)
...@@ -125,7 +125,7 @@ def getDiff(project): ...@@ -125,7 +125,7 @@ def getDiff(project):
git = repo.git git = repo.git
current_branch = repo.active_branch.name current_branch = repo.active_branch.name
result = git.diff(current_branch) result = git.diff(current_branch)
except Exception, e: except Exception as e:
result = safeResult(str(e)) result = safeResult(str(e))
return result return result
...@@ -155,7 +155,7 @@ def gitPush(project, msg): ...@@ -155,7 +155,7 @@ def gitPush(project, msg):
else: else:
json = "Nothing to be commited" json = "Nothing to be commited"
code = 1 code = 1
except Exception, e: except Exception as e:
if undo_commit: if undo_commit:
git.reset("HEAD~") #undo previous commit git.reset("HEAD~") #undo previous commit
json = safeResult(str(e)) json = safeResult(str(e))
...@@ -169,7 +169,7 @@ def gitPull(project): ...@@ -169,7 +169,7 @@ def gitPull(project):
git = repo.git git = repo.git
git.pull() git.pull()
code = 1 code = 1
except Exception, e: except Exception as e:
result = safeResult(str(e)) result = safeResult(str(e))
return jsonify(code=code, result=result) return jsonify(code=code, result=result)
......
...@@ -90,7 +90,7 @@ def saveSession(config, account): ...@@ -90,7 +90,7 @@ def saveSession(config, account):
#save new account data #save new account data
open(user, 'w').write((';'.join(account)).encode("utf-8")) open(user, 'w').write((';'.join(account)).encode("utf-8"))
return True return True
except Exception, e: except Exception as e:
try: try:
if backup: if backup:
os.remove(user) os.remove(user)
...@@ -212,7 +212,7 @@ def recursifKill(pids): ...@@ -212,7 +212,7 @@ def recursifKill(pids):
try: try:
os.kill(pid, signal.SIGKILL) #kill current process os.kill(pid, signal.SIGKILL) #kill current process
except Exception: except Exception:
pass pass
recursifKill(ppids) #kill all children of this process recursifKill(ppids) #kill all children of this process
def pidppid(pid): def pidppid(pid):
......
...@@ -299,7 +299,7 @@ def createFile(): ...@@ -299,7 +299,7 @@ def createFile():
else: else:
os.mkdir(path) os.mkdir(path)
return jsonify(code=1, result="") return jsonify(code=1, result="")
except Exception, e: except Exception as e:
return jsonify(code=0, result=str(e)) return jsonify(code=0, result=str(e))
#remove file or directory #remove file or directory
...@@ -311,7 +311,7 @@ def removeFile(): ...@@ -311,7 +311,7 @@ def removeFile():
else: else:
os.remove(request.form['path']) os.remove(request.form['path'])
return jsonify(code=1, result="") return jsonify(code=1, result="")
except Exception, e: except Exception as e:
return jsonify(code=0, result=str(e)) return jsonify(code=0, result=str(e))
@login_required() @login_required()
...@@ -320,7 +320,7 @@ def removeSoftwareDir(): ...@@ -320,7 +320,7 @@ def removeSoftwareDir():
data = removeSoftwareByName(app.config, request.form['md5'], data = removeSoftwareByName(app.config, request.form['md5'],
request.form['title']) request.form['title'])
return jsonify(code=1, result=data) return jsonify(code=1, result=data)
except Exception, e: except Exception as e:
return jsonify(code=0, result=str(e)) return jsonify(code=0, result=str(e))
#read file and return content to ajax #read file and return content to ajax
...@@ -459,7 +459,7 @@ def saveParameterXml(): ...@@ -459,7 +459,7 @@ def saveParameterXml():
f.write(content) f.write(content)
f.close() f.close()
result = readParameters(param_path) result = readParameters(param_path)
except Exception, e: except Exception as e:
result = str(e) result = str(e)
software_type = None software_type = None
if request.form['software_type']: if request.form['software_type']:
...@@ -469,7 +469,7 @@ def saveParameterXml(): ...@@ -469,7 +469,7 @@ def saveParameterXml():
else: else:
try: try:
updateInstanceParameter(app.config, software_type) updateInstanceParameter(app.config, software_type)
except Exception, e: except Exception as e:
return jsonify(code=0, result="An error occurred while applying your settings!<br/>" + str(e)) return jsonify(code=0, result="An error occurred while applying your settings!<br/>" + str(e))
return jsonify(code=1, result="") return jsonify(code=1, result="")
...@@ -591,7 +591,7 @@ def fileBrowser(): ...@@ -591,7 +591,7 @@ def fileBrowser():
result = file_request.unzipFile(dir, filename, newfilename) result = file_request.unzipFile(dir, filename, newfilename)
else: else:
result = "ARGS PARSE ERROR: Bad option..." result = "ARGS PARSE ERROR: Bad option..."
except Exception, e: except Exception as e:
return str(e) return str(e)
return result return result
......
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