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

Added a new oargen script

parent 6d46dc05
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
# coding: utf-8
from __future__ import print_function
from __future__ import unicode_literals
import argparse
# import logging
import subprocess
def argparser():
parser = argparse.ArgumentParser()
parser.add_argument('command', nargs='?',
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('-b', '--besteffort', action="store_true",
help="Launch job in besteffort mode")
parser.add_argument('-t', '--time', default=12, type=int,
help="Estimated maximum duration of the job (in hours)")
parser.add_argument('-g', '--gpu', action="store_true",
help="If True, reserves only cores with GPUs")
parser.add_argument('-c', '--core', default=1, type=int,
help="Number of cores to reserve")
parser.add_argument('-H', '--host',
help="Name of the host (SQL LIKE syntax accepted)")
parser.add_argument('-i', '--interactive', action="store_true",
help="Launch job in interactive mode")
parser.add_argument('-r', '--run', action="store_true",
help="Run the command")
# parser.add_argument('-l', '--logger', default='INFO',
# choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
# help="Logging level: DEBUG, INFO (default), WARNING, ERROR")
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
def main():
args = argparser()
command = ["oarsub"]
properties = "-p \""
if args.gpu:
properties += "gpu IS NOT NULL"
else:
properties += "gpu IS NULL"
if args.host is not None:
properties += " AND host LIKE '{}'".format(args.host)
properties += "\""
command.append(properties)
ressources = "-l core={},walltime={}:00:00".format(args.core, args.time)
command.append(ressources)
if args.besteffort:
command.append("-t besteffort -t idempotent")
if args.interactive:
command.append('-I')
else:
job_command = [args.command] + args.argument
command.append('"{}"'.format(" ".join(job_command)))
print(" ".join(command))
if args.run:
subprocess.call(command)
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment