def setUp(self): temp_output_filename = self.temp_output_filename = os.path.realpath('.') + '/temp.out' self.pbs_script_filename = os.path.realpath('.') + '/test.pbs' dump_to_file(self.pbs_script_filename, pbs.generic_script(""" echo "Hello, World!" > %(temp_output_filename)s sleep 1 """ % locals()))
def run_command_here(script_file_name, command, input_file_name=None, output_file_name=None, err_output_file_name=None, job_name='submit_command', verbose=True, numcpu=None, mem=None, pmem=None, time=False, numnodes=None, queue=None, walltime=None, disable_mpi=False): """Create a pbs script executing the given in the cwd command with given stdin and stderr/out files.""" pwd = os.getcwd() if input_file_name: redirect_input = '< %s ' % input_file_name else: redirect_input = '' if time: command = 'time ' + command output_file_name = output_file_name or '/dev/null' if err_output_file_name is None: if output_file_name is not None: err_output_file_name = output_file_name + '.err' else: err_output_file_name = '/dev/null' if verbose: processor_verbose = """echo -------------------------------------- echo + Running on host `hostname` echo + Time is `date` [ ${PBS_NODEFILE:-nonode} != "nonode" ] && echo + This job runs on the following processors: `cat ${PBS_NODEFILE}` echo -------------------------------------- """ % locals() else: processor_verbose = "" additional_configuration_lines = [] additional_configuration = '\n'.join(additional_configuration_lines) if disable_mpi: module_file = disable_mpi_module.__file__ if module_file[-1] == 'c': module_file = module_file[:-1] disable_mpi = 'python ' + module_file else: disable_mpi = '' with open(script_file_name, 'w') as script_file: script = pbs.generic_script(""" working_directory=%(pwd)s if [ ! -d ${working_directory} ]; then echo "Can not execute, working directory does not exist: ${working_directory}" exit 1 fi cd ${working_directory} %(processor_verbose)s %(disable_mpi)s %(command)s %(redirect_input)s """ % locals(), numnodes=numnodes, numcpu=numcpu, queue=queue, walltime=walltime, mem=mem, pmem=pmem, job_name=job_name) script_file.write(script)