Skip to content
Snippets Groups Projects
Commit b44989bc authored by Jeremy Auguste's avatar Jeremy Auguste
Browse files

Added anterior argument and made code more modular

parent a54cee34
No related branches found
No related tags found
No related merge requests found
...@@ -5,16 +5,15 @@ from __future__ import print_function ...@@ -5,16 +5,15 @@ from __future__ import print_function
from __future__ import unicode_literals from __future__ import unicode_literals
import argparse import argparse
# import logging
import subprocess import subprocess
def argparser(): def argparser():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('command', nargs='?', # parser.add_argument('command', nargs='?',
# help="Command to use for the job (in passive mode)")
parser.add_argument('command', nargs=argparse.REMAINDER,
help="Command to use for the job (in passive mode)") help="Command to use for the job (in passive mode)")
parser.add_argument('argument', nargs=argparse.REMAINDER,
help="Arguments of the command (in passive mode)")
parser.add_argument('-n', '--name', parser.add_argument('-n', '--name',
help="Name to give to the job") help="Name to give to the job")
parser.add_argument('-b', '--besteffort', action="store_true", parser.add_argument('-b', '--besteffort', action="store_true",
...@@ -33,65 +32,83 @@ def argparser(): ...@@ -33,65 +32,83 @@ def argparser():
help="Enable checkpoint signals with the given delay (in seconds)") help="Enable checkpoint signals with the given delay (in seconds)")
parser.add_argument('-r', '--run', action="store_true", parser.add_argument('-r', '--run', action="store_true",
help="Run the command") help="Run the command")
# parser.add_argument('-l', '--logger', default='INFO', parser.add_argument('-a', '--anterior',
# choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help="Anterior job id that must be terminated to start this new one")
# help="Logging level: DEBUG, INFO (default), WARNING, ERROR")
args = parser.parse_args() args = parser.parse_args()
# numeric_level = getattr(logging, args.logger.upper(), None)
# if not isinstance(numeric_level, int):
# raise ValueError("Invalid log level: {}".format(args.logger))
# logging.basicConfig(level=numeric_level)
return args return args
def main(): def prepare_oarsub(gpu, host, core, time,
args = argparser() command=None, argument=None,
interactive=False,
command = ["oarsub"] name=None, besteffort=False,
command.append("-p") checkpoint=None, anterior=None,
command_is_string=False):
oar_cmd = ["oarsub"]
oar_cmd.append("-p")
properties = "" properties = ""
if args.gpu: if gpu:
properties += "(gpu IS NOT NULL)" properties += "(gpu IS NOT NULL)"
else: else:
properties += "(gpu IS NULL)" properties += "(gpu IS NULL)"
if args.host is not None: if host is not None:
properties += " AND host LIKE '{}'".format(args.host) properties += " AND host LIKE '{}'".format(host)
properties += "" properties += ""
command.append(properties) oar_cmd.append(properties)
command.append("-l") oar_cmd.append("-l")
time = args.time.split(':') time = time.split(':')
hour = time[0] hour = time[0]
minutes = time[1] if len(time) >= 2 else "00" minutes = time[1] if len(time) >= 2 else "00"
seconds = time[2] if len(time) >= 3 else "00" seconds = time[2] if len(time) >= 3 else "00"
ressources = "core={},walltime={}:{}:{}".format(args.core, hour, minutes, seconds) ressources = "core={},walltime={}:{}:{}".format(core, hour, minutes, seconds)
command.append(ressources) oar_cmd.append(ressources)
if name is not None:
oar_cmd.append("-n")
oar_cmd.append(name)
oar_cmd.append("-O")
oar_cmd.append("{}.%jobid%.stdout".format(name))
oar_cmd.append("-E")
oar_cmd.append("{}.%jobid%.stderr".format(name))
if args.name is not None: if besteffort:
command.append("-n") oar_cmd.extend(["-t", "besteffort", "-t", "idempotent"])
command.append(args.name)
command.append("-O")
command.append("{}.%jobid%.stdout".format(args.name))
command.append("-E")
command.append("{}.%jobid%.stderr".format(args.name))
if args.besteffort: if checkpoint is not None:
command.extend(["-t", "besteffort", "-t", "idempotent"]) oar_cmd.extend(["--checkpoint", checkpoint])
if args.checkpoint is not None: if anterior is not None:
command.extend(["--checkpoint", args.checkpoint]) oar_cmd.extend(["-a", anterior])
if args.interactive: if interactive:
command.append('-I') oar_cmd.append('-I')
else: else:
job_command = [args.command] + args.argument job_command = command if command_is_string else " ".join(command)
command.append(" ".join(job_command)) oar_cmd.append(" ".join(job_command))
def run_oarsub(command, print_cmd=False, fake_run=False, return_output=False):
print(subprocess.list2cmdline(command)) print(subprocess.list2cmdline(command))
if args.run: if fake_run:
return None
if not return_output:
subprocess.call(command) subprocess.call(command)
return None
return subprocess.check_output(command)
def main():
args = argparser()
oar_command = prepare_oarsub(args.gpu, args.host, args.core, args.time,
command=args.command, argument=args.argument,
interactive=args.interactive, name=args.name,
besteffort=args.besteffort, checkpoint=args.checkpoint,
anterior=args.anterior)
run_oarsub(oar_command, print_cmd=True, fake_run=not args.run)
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment