Skip to content

Commit a72297e

Browse files
committed
Merge pull request #66 from mgermain/nicer_output
Nicer output
2 parents 053ac62 + 85090bd commit a72297e

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

scripts/smart_dispatch.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ def main():
4242
commands = smartdispatch.unfold_command(command)
4343

4444
commands = smartdispatch.replace_uid_tag(commands)
45+
nb_commands = len(commands) # For print at the end
4546

46-
path_job_logs, path_job_commands = create_job_folders(jobname)
47+
path_job, path_job_logs, path_job_commands = create_job_folders(jobname)
4748
elif args.mode == "resume":
48-
path_job_logs, path_job_commands = get_job_folders(args.batch_uid)
49+
jobname = args.batch_uid
50+
path_job, path_job_logs, path_job_commands = get_job_folders(args.batch_uid)
4951
else:
5052
raise ValueError("Unknown subcommand!")
5153

@@ -58,6 +60,7 @@ def main():
5860
command_manager.set_commands_to_run(commands)
5961
else:
6062
command_manager.reset_running_commands()
63+
nb_commands = command_manager.get_nb_commands_to_run()
6164

6265
worker_command = 'smart_worker.py "{0}" "{1}"'.format(command_manager._commands_filename, path_job_logs)
6366
# Replace commands with `args.pool` workers
@@ -83,11 +86,19 @@ def main():
8386
job_generator = job_generator_factory(queue, commands, command_params, CLUSTER_NAME)
8487
pbs_filenames = job_generator.write_pbs_files(path_job_commands)
8588

86-
# Launch the jobs with QSUB
89+
# Launch the jobs
90+
print "## {nb_commands} command(s) will be executed in {nb_jobs} job(s) ##".format(nb_commands=nb_commands, nb_jobs=len(pbs_filenames))
91+
print "Batch UID:\n {batch_uid}".format(batch_uid=jobname)
8792
if not args.doNotLaunch:
93+
jobs_id = []
8894
for pbs_filename in pbs_filenames:
8995
qsub_output = check_output('{launcher} {pbs_filename}'.format(launcher=LAUNCHER if args.launcher is None else args.launcher, pbs_filename=pbs_filename), shell=True)
90-
print qsub_output,
96+
jobs_id += [qsub_output.rstrip()]
97+
98+
with utils.open_with_lock(os.path.join(path_job, "jobs_id.txt"), 'a') as jobs_id_file:
99+
jobs_id_file.writelines("\n".join(jobs_id))
100+
print "\nJobs id:\n {jobs_id}".format(jobs_id=" ".join(jobs_id))
101+
print "\nLogs, command, and jobs id related to this batch will be in:\n {smartdispatch_folder}".format(smartdispatch_folder=path_job)
91102

92103

93104
def parse_arguments():
@@ -137,32 +148,32 @@ def _gen_job_paths(jobname):
137148
path_job_logs = os.path.join(path_job, 'logs')
138149
path_job_commands = os.path.join(path_job, 'commands')
139150

140-
return path_job_logs, path_job_commands
151+
return path_job, path_job_logs, path_job_commands
141152

142153

143154
def get_job_folders(jobname):
144-
path_job_logs, path_job_commands = _gen_job_paths(jobname)
155+
path_job, path_job_logs, path_job_commands = _gen_job_paths(jobname)
145156

146157
if not os.path.exists(path_job_commands):
147158
raise LookupError("Batch UID ({0}) does not exist! Cannot resume.".format(jobname))
148159

149160
if not os.path.exists(path_job_logs):
150161
os.makedirs(path_job_logs)
151162

152-
return path_job_logs, path_job_commands
163+
return path_job, path_job_logs, path_job_commands
153164

154165

155166
def create_job_folders(jobname):
156167
"""Creates the folders where the logs, commands and QSUB files will be saved."""
157-
path_job_logs, path_job_commands = _gen_job_paths(jobname)
168+
path_job, path_job_logs, path_job_commands = _gen_job_paths(jobname)
158169

159170
if not os.path.exists(path_job_commands):
160171
os.makedirs(path_job_commands)
161172

162173
if not os.path.exists(path_job_logs):
163174
os.makedirs(path_job_logs)
164175

165-
return path_job_logs, path_job_commands
176+
return path_job, path_job_logs, path_job_commands
166177

167178

168179
if __name__ == "__main__":

smartdispatch/command_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def get_command_to_run(self):
3636
self._move_line_between_files(commands_file, running_commands_file, command)
3737
return command[:-1]
3838

39+
def get_nb_commands_to_run(self):
40+
with utils.open_with_lock(self._commands_filename, 'r') as commands_file:
41+
return len(commands_file.readlines())
42+
3943
def set_running_command_as_finished(self, command):
4044
with utils.open_with_lock(self._running_commands_filename, 'r+') as running_commands_file:
4145
with utils.open_with_lock(self._finished_commands_filename, 'a') as finished_commands_file:

smartdispatch/tests/test_command_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ def test_get_command_to_run(self):
5555

5656
assert_true(not os.path.isfile(self.command_manager._finished_commands_filename))
5757

58+
def test_get_nb_commands_to_run(self):
59+
assert_equal(self.command_manager.get_nb_commands_to_run(), 3)
60+
5861
def test_set_running_command_as_finished(self):
5962
# SetUp
6063
command = self.command_manager.get_command_to_run()

0 commit comments

Comments
 (0)