Skip to content

Commit f8106dc

Browse files
committed
Changed print to be Python 3 compliant, convert Popen's output from bytes to str and removed function file in argparse
1 parent 99859d2 commit f8106dc

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

scripts/smart_dispatch.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
from __future__ import print_function
34

45
import os
56
import sys
@@ -119,8 +120,8 @@ def main():
119120
pbs_filenames = job_generator.write_pbs_files(path_job_commands)
120121

121122
# Launch the jobs
122-
print "## {nb_commands} command(s) will be executed in {nb_jobs} job(s) ##".format(nb_commands=nb_commands, nb_jobs=len(pbs_filenames))
123-
print "Batch UID:\n{batch_uid}".format(batch_uid=jobname)
123+
print("## {nb_commands} command(s) will be executed in {nb_jobs} job(s) ##".format(nb_commands=nb_commands, nb_jobs=len(pbs_filenames)))
124+
print("Batch UID:\n{batch_uid}".format(batch_uid=jobname))
124125
if not args.doNotLaunch:
125126
jobs_id = []
126127
for pbs_filename in pbs_filenames:
@@ -130,8 +131,8 @@ def main():
130131
with open_with_lock(pjoin(path_job, "jobs_id.txt"), 'a') as jobs_id_file:
131132
jobs_id_file.writelines(t.strftime("## %Y-%m-%d %H:%M:%S ##\n"))
132133
jobs_id_file.writelines("\n".join(jobs_id) + "\n")
133-
print "\nJobs id:\n{jobs_id}".format(jobs_id=" ".join(jobs_id))
134-
print "\nLogs, command, and jobs id related to this batch will be in:\n {smartdispatch_folder}".format(smartdispatch_folder=path_job)
134+
print("\nJobs id:\n{jobs_id}".format(jobs_id=" ".join(jobs_id)))
135+
print("\nLogs, command, and jobs id related to this batch will be in:\n {smartdispatch_folder}".format(smartdispatch_folder=path_job))
135136

136137

137138
def parse_arguments():
@@ -146,7 +147,7 @@ def parse_arguments():
146147
parser.add_argument('-c', '--coresPerCommand', type=int, required=False, help='How many cores a command needs.', default=1)
147148
parser.add_argument('-g', '--gpusPerCommand', type=int, required=False, help='How many gpus a command needs.', default=1)
148149
# parser.add_argument('-m', '--memPerCommand', type=float, required=False, help='How much memory a command needs (in Gb).')
149-
parser.add_argument('-f', '--commandsFile', type=file, required=False, help='File containing commands to launch. Each command must be on a seperate line. (Replaces commandAndOptions)')
150+
parser.add_argument('-f', '--commandsFile', type=str, required=False, help='File containing commands to launch. Each command must be on a seperate line. (Replaces commandAndOptions)')
150151

151152
parser.add_argument('-l', '--modules', type=str, required=False, help='List of additional modules to load.', nargs='+')
152153
parser.add_argument('-x', '--doNotLaunch', action='store_true', help='Creates the QSUB files without launching them.')
@@ -170,6 +171,9 @@ def parse_arguments():
170171
if args.queueName not in AVAILABLE_QUEUES and ((args.coresPerNode is None and args.gpusPerNode is None) or args.walltime is None):
171172
parser.error("Unknown queue, --coresPerNode/--gpusPerNode and --walltime must be set.")
172173

174+
if args.commandsFile is not None and not os.path.isfile(args.commandsFile):
175+
parser.error("Command file does not exist: '{0}'.".format(args.commandsFile))
176+
173177
return args
174178

175179

smartdispatch/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import print_function
2+
13
import re
24
import hashlib
35
import unicodedata
@@ -15,7 +17,7 @@ def print_boxed(string):
1517
out = u"\u250c" + box_line + u"\u2510\n"
1618
out += '\n'.join([u"\u2502 {} \u2502".format(line.ljust(max_len)) for line in splitted_string])
1719
out += u"\n\u2514" + box_line + u"\u2518"
18-
print out
20+
print(out)
1921

2022

2123
def yes_no_prompt(query, default=None):
@@ -92,6 +94,8 @@ def detect_cluster():
9294
# Get server status
9395
try:
9496
output = Popen(["qstat", "-B"], stdout=PIPE).communicate()[0]
97+
if isinstance(output, bytes):
98+
output = output.decode("utf-8")
9599
except OSError:
96100
# If qstat is not available we assume that the cluster is unknown.
97101
return None

0 commit comments

Comments
 (0)