Commit ab224625 authored by Marco Mariani's avatar Marco Mariani

runner: use context manager for open(.., 'w')

parent ccd8605a
...@@ -89,9 +89,8 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -89,9 +89,8 @@ class SlaprunnerTestCase(unittest.TestCase):
self.app = views.app.test_client() self.app = views.app.test_client()
self.app.config = views.app.config self.app.config = views.app.config
#Create password recover code #Create password recover code
rpwd = open(os.path.join(views.app.config['etc_dir'], '.rcode'), 'w') with open(os.path.join(views.app.config['etc_dir'], '.rcode'), 'w') as rpwd:
rpwd.write(self.rcode) rpwd.write(self.rcode)
rpwd.close()
def tearDown(self): def tearDown(self):
"""Remove all test data""" """Remove all test data"""
......
...@@ -296,9 +296,8 @@ def config_SR_folder(config): ...@@ -296,9 +296,8 @@ def config_SR_folder(config):
#create symlink #create symlink
os.symlink(source, destination) os.symlink(source, destination)
#write config file #write config file
cf = open(cfg, 'w') with open(cfg, 'w') as cf:
cf.write(current_project + "#" + folder) cf.write(current_project + '#' + folder)
cf.close()
def loadSoftwareRList(config): def loadSoftwareRList(config):
......
...@@ -536,12 +536,11 @@ def saveParameterXml(): ...@@ -536,12 +536,11 @@ def saveParameterXml():
content = request.form['parameter'].encode("utf-8") content = request.form['parameter'].encode("utf-8")
param_path = os.path.join(app.config['etc_dir'], ".parameter.xml") param_path = os.path.join(app.config['etc_dir'], ".parameter.xml")
try: try:
f = open(param_path, 'w') with open(param_path, 'w') as f:
f.write(content) f.write(content)
f.close()
result = readParameters(param_path) result = readParameters(param_path)
except Exception as 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']:
software_type = request.form['software_type'] software_type = request.form['software_type']
......
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