def _write_submit_script(self, template_string, script_filename, job_name, configs): ''' Load the template string with config values and write the generated submit script to a submit script file. Args: - template_string (string) : The template string to be used for the writing submit script - script_filename (string) : Name of the submit script - job_name (string) : job name - configs (dict) : configs that get pushed into the template Returns: - True: on success Raises: SchedulerMissingArgs : If template is missing args ScriptPathError : Unable to write submit script out ''' try: submit_script = Template(template_string).substitute(jobname=job_name, **configs) with open(script_filename, 'w') as f: f.write(submit_script) except KeyError as e: logger.error("Missing keys for submit script : %s", e) raise (ep_error.SchedulerMissingArgs(e.args, self.label)) except IOError as e: logger.error("Failed writing to submit script: %s", script_filename) raise (ep_error.ScriptPathError(script_filename, e)) return True
def _write_submit_script(self, script_string, script_filename): ''' Load the template string with config values and write the generated submit script to a submit script file. Args: - template_string (string) : The template string to be used for the writing submit script - script_filename (string) : Name of the submit script Returns: - True: on success Raises: SchedulerMissingArgs : If template is missing args ScriptPathError : Unable to write submit script out ''' try: with open(script_filename, 'w') as f: f.write(script_string) except KeyError as e: logger.error("Missing keys for submit script : %s", e) raise (ep_error.SchedulerMissingArgs(e.args, self.sitename)) except IOError as e: logger.error("Failed writing to submit script: %s", script_filename) raise (ep_error.ScriptPathError(script_filename, e)) return True
def _write_submit_script(self, template_string, script_filename, job_name, configs): """ Load the template string with config values and write the generated submit script to a submit script file. Args: - template_string (string) : The template string to be used for the writing submit script - script_filename (string) : Name of the submit script - job_name (string) : job name - configs (dict) : configs that get pushed into the template Returns: - True: on success Raises: SchedulerMissingArgs : If template is missing args ScriptPathError : Unable to write submit script out """ try: script_dir = os.path.dirname(script_filename) if script_dir: os.makedirs(script_dir) except Exception as e: if e.errno == 17: pass else: logger.error( "Unable to create script_dir:{0} due to:{1}".format( script_dir, e)) raise (ep_error.ScriptPathError(script_filename, e)) try: submit_script = Template(template_string).substitute(**configs) with open(script_filename, 'w') as f: f.write(submit_script) os.chmod(script_filename, 0o777) except KeyError as e: logger.error("Missing keys for submit script : %s", e) raise (ep_error.SchedulerMissingArgs(e.args, self.label)) except IOError as e: logger.error("Failed writing to submit script: %s", script_filename) raise (ep_error.ScriptPathError(script_filename, e)) return True
def _write_submit_script(self, template, script_filename, job_name, configs): """Generate submit script and write it to a file. Args: - template (string) : The template string to be used for the writing submit script - script_filename (string) : Name of the submit script - job_name (string) : job name - configs (dict) : configs that get pushed into the template Returns: - True: on success Raises: SchedulerMissingArgs : If template is missing args ScriptPathError : Unable to write submit script out """ try: submit_script = Template(template).substitute(jobname=job_name, **configs) # submit_script = Template(template).safe_substitute(jobname=job_name, **configs) with open(script_filename, 'w') as f: f.write(submit_script) except KeyError as e: logger.error("Missing keys for submit script : %s", e) raise (ep_error.SchedulerMissingArgs(e.args, self.sitename)) except IOError as e: logger.error("Failed writing to submit script: %s", script_filename) raise (ep_error.ScriptPathError(script_filename, e)) except Exception as e: print("Template : ", template) print("Args : ", job_name) print("Kwargs : ", configs) logger.error("Uncategorized error: %s", e) raise (e) return True