Skip to content

Commit

Permalink
small fixes in slurm switches
Browse files Browse the repository at this point in the history
opening and closing files still compatible with python 2.6
  • Loading branch information
grzanka authored and Michal Szczerba committed Aug 26, 2017
1 parent b8c0b28 commit f480569
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions mcpartools/scheduler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ def __init__(self, scheduler_options):
self.options_args = ""
logger.debug("No scheduler options")
elif os.path.exists(scheduler_options):
with open(scheduler_options, 'r') as f:
options_file_content = f.read()
self.options_header = options_file_content
logger.debug("Scheduler options file:" + options_file_content)
opt_fd = open(scheduler_options, 'r')
options_file_content = opt_fd.read()
opt_fd.close()
self.options_header = options_file_content
self.options_args = ""
logger.debug("Scheduler options file:" + options_file_content)
else:
self.options_header = "# no user options provided"
self.options_args = scheduler_options[1:-1]
Expand Down Expand Up @@ -50,9 +51,10 @@ def main_run_script_body(self, jobs_no, workspace_dir):
return self.main_run_script

def write_submit_script(self, script_path, jobs_no, workspace_dir):
fd = open(script_path, 'w')
abs_path_workspace = os.path.abspath(workspace_dir)
with open(script_path, 'w') as f:
f.write(self.submit_script_body(jobs_no, abs_path_workspace))
fd.write(self.submit_script_body(jobs_no, abs_path_workspace))
fd.close()
os.chmod(script_path, 0o750)
logger.debug("Saved submit script: " + script_path)
logger.debug("Jobs no " + str(jobs_no))
Expand All @@ -61,8 +63,9 @@ def write_submit_script(self, script_path, jobs_no, workspace_dir):
def write_main_run_script(self, jobs_no, output_dir):
output_dir_abspath = os.path.abspath(output_dir)
out_file_path = os.path.join(output_dir_abspath, self.main_run_script)
with open(out_file_path, 'w') as f:
f.write(self.main_run_script_body(jobs_no=jobs_no, workspace_dir=output_dir_abspath))
fd = open(out_file_path, 'w')
fd.write(self.main_run_script_body(jobs_no=jobs_no, workspace_dir=output_dir_abspath))
fd.close()
os.chmod(out_file_path, 0o750)
logger.debug("Saved main run script: " + out_file_path)
logger.debug("Output dir " + output_dir)

0 comments on commit f480569

Please sign in to comment.