22# -*- coding: utf-8 -*-
33
44import os
5+ import sys
56import argparse
67import time as t
78import numpy as np
9+ from os .path import join as pjoin
810from subprocess import check_output
911from textwrap import dedent
1012
@@ -53,7 +55,11 @@ def main():
5355 else :
5456 raise ValueError ("Unknown subcommand!" )
5557
56- command_manager = CommandManager (os .path .join (path_job_commands , "commands.txt" ))
58+ # Keep a log of the command line in the job folder.
59+ command_line = " " .join (sys .argv )
60+ smartdispatch .log_command_line (path_job , command_line )
61+
62+ command_manager = CommandManager (pjoin (path_job_commands , "commands.txt" ))
5763
5864 # If resume mode, reset running jobs
5965 if args .mode == "launch" :
@@ -82,7 +88,7 @@ def main():
8288
8389 # If no pool size is specified the number of commands is taken
8490 if args .pool is None :
85- args .pool = command_manager .get_nb_commands_to_run ()
91+ args .pool = command_manager .get_nb_commands_to_run (command_line )
8692
8793 # Generating all the worker commands
8894 COMMAND_STRING = 'cd "{cwd}"; smart_worker.py "{commands_file}" "{log_folder}" ' \
@@ -111,7 +117,7 @@ def main():
111117 qsub_output = check_output ('{launcher} {pbs_filename}' .format (launcher = LAUNCHER if args .launcher is None else args .launcher , pbs_filename = pbs_filename ), shell = True )
112118 jobs_id += [qsub_output .strip ()]
113119
114- with utils .open_with_lock (os . path . join (path_job , "jobs_id.txt" ), 'a' ) as jobs_id_file :
120+ with utils .open_with_lock (pjoin (path_job , "jobs_id.txt" ), 'a' ) as jobs_id_file :
115121 jobs_id_file .writelines (t .strftime ("## %Y-%m-%d %H:%M:%S ##\n " ))
116122 jobs_id_file .writelines ("\n " .join (jobs_id ) + "\n " )
117123 print "\n Jobs id:\n {jobs_id}" .format (jobs_id = " " .join (jobs_id ))
@@ -157,10 +163,10 @@ def parse_arguments():
157163
158164
159165def _gen_job_paths (jobname ):
160- path_smartdispatch_logs = os . path . join (os .getcwd (), LOGS_FOLDERNAME )
161- path_job = os . path . join (path_smartdispatch_logs , jobname )
162- path_job_logs = os . path . join (path_job , 'logs' )
163- path_job_commands = os . path . join (path_job , 'commands' )
166+ path_smartdispatch_logs = pjoin (os .getcwd (), LOGS_FOLDERNAME )
167+ path_job = pjoin (path_smartdispatch_logs , jobname )
168+ path_job_logs = pjoin (path_job , 'logs' )
169+ path_job_commands = pjoin (path_job , 'commands' )
164170
165171 return path_job , path_job_logs , path_job_commands
166172
@@ -173,10 +179,10 @@ def get_job_folders(jobname):
173179
174180 if not os .path .exists (path_job_logs ):
175181 os .makedirs (path_job_logs )
176- if not os .path .exists (os . path . join (path_job_logs , "worker" )):
177- os .makedirs (os . path . join (path_job_logs , "worker" ))
178- if not os .path .exists (os . path . join (path_job_logs , "job" )):
179- os .makedirs (os . path . join (path_job_logs , "job" ))
182+ if not os .path .exists (pjoin (path_job_logs , "worker" )):
183+ os .makedirs (pjoin (path_job_logs , "worker" ))
184+ if not os .path .exists (pjoin (path_job_logs , "job" )):
185+ os .makedirs (pjoin (path_job_logs , "job" ))
180186
181187 return path_job , path_job_logs , path_job_commands
182188
@@ -190,8 +196,8 @@ def create_job_folders(jobname):
190196
191197 if not os .path .exists (path_job_logs ):
192198 os .makedirs (path_job_logs )
193- os .makedirs (os . path . join (path_job_logs , "worker" ))
194- os .makedirs (os . path . join (path_job_logs , "job" ))
199+ os .makedirs (pjoin (path_job_logs , "worker" ))
200+ os .makedirs (pjoin (path_job_logs , "job" ))
195201
196202 return path_job , path_job_logs , path_job_commands
197203
0 commit comments