Skip to content
Snippets Groups Projects
Select Git revision
  • 817f3d65f49231e6a85e069bb4ea2d7d21dc26b5
  • master default protected
2 results

oargen.py

Blame
  • Forked from Jeremy Auguste / oar
    60 commits behind the upstream repository.
    oargen.py 2.64 KiB
    #!/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()