Source code for flash.flmake.main

import os
import sys

if sys.version_info[0] == 3 or sys.version_info[:2] == (2, 7):
    import argparse
else:
    from .. import _argparse as argparse


# Command registration
#    key is command name, 
#    value is (command module - relative import, main function)
commands = {
    'setup': ('setup', 'main'),
    'build': ('build', 'main'),
    'run': ('run', 'main'),
    'restart': ('restart', 'main'),
    'merge': ('merge', 'main'),
    'clean': ('clean', 'main'),
    'metadata': ('metadata', 'main'),
    'diffpar': ('diffpar', 'main'),
    'ls-runs': ('lsruns', 'main'),
    'help': ('help_cmd', 'main'),
    'mv': ('mv', 'main'),
    'rm': ('rm', 'main'),
    'log': ('log', 'main'),
    'qsub': ('qsub', 'main'),
    'reproduce': ('reproduce', 'main'),
    }


[docs]def main(rcfile='flashrc.py', args=None): """Entry point for flash make utility.""" # open run-control file, if present rc = {} if os.path.isfile(rcfile): execfile(rcfile, {}, rc) # Parse the command line arguments parser = argparse.ArgumentParser(description='FLASH make utility.', ) parser.add_argument('-m', metavar="MESSAGE", default=None, type=str, help='message to log', required=False, dest="message") subparsers = parser.add_subparsers(title='subcommands', description='valid subcommands', dest="cmd", help='sub-command help') for key in commands: subparser = subparsers.add_parser(key, prog=key, prefix_chars="\0", add_help=False) subparser.add_argument('options', type=str, nargs=argparse.REMAINDER, help='build command to execute') ns = parser.parse_args(args) # Run the flmake command, use dynamic import if '.' not in sys.path: sys.path.insert(0, '.') cmdmod, mainfunc = commands[ns.cmd] cmdmod = __import__(cmdmod, globals(), locals(), fromlist=[None]) mainfunc = getattr(cmdmod, mainfunc) rtn = mainfunc(ns.options, rc, ns.message) # Handle some edge cases if rtn is NotImplemented: print "Command '{0}' has not yet been implemented.".format(cmd) raise SystemExit(1) elif 0 < rtn: print "flmake encountered an error." raise SystemExit(rtn) # remove empty flash.log if os.path.exists('flash.log') and 0 == os.path.getsize('flash.log'): os.remove('flash.log')