def run_toolbox(action_classes, script_name='', show_make_flags=True):
    """
    Provide a command line interface for a list of Actions.
    
    Note:    
    strings included in the action_classes list will be printed 
    as help text, for example to display section headings.
    """
    args = configure_making(sys.argv[1:])
    
    commands = { }

    for item in action_classes:
        if isinstance(item, str):
            continue
        name = item.shell_name()
        commands[ name ] = item

    if args == [ '--help-make' ]:
        help = [ '\n' ]
        help.append('\nMake options:\n'+Make().describe('', show_help=True, escape_newlines=False)+'\n')

        config.write_colored_text(sys.stdout, ''.join(help)+'\n\n')
        sys.exit(1)

    if not args or args == ['-h'] or args == ['--help']:
        help = [ '\n' ]
        
        for item in action_classes:
            if isinstance(item, str):
                help.append(config.wrap(item, 70) + '\n\n')
                continue
            name = item.shell_name()
            help.append('    %s\n' % config.colored(1,name+':'))
            help.append(config.color_as_comment(config.wrap(item.help_short, 70, '        ')) + '\n\n')

        if show_make_flags:
            #help.append('\nMake options:\n'+Make().describe('', show_help=True, escape_newlines=False)+'\n')
            help.append('\nFor workflow make options type "%s --help-make".\n' % script_name)

        config.write_colored_text(sys.stdout, ''.join(help))
        sys.exit(1)
        
    try:        
        command, args = args[0], args[1:]
        
        mangled_command = command.lower().rstrip(':')
        if mangled_command not in commands:
            raise grace.Error("Don't know how to "+command)        
    except:
        config.report_exception()
        sys.exit(1)

    config.shell_run(commands[mangled_command](), args, (script_name+' ' if script_name else '') + mangled_command+':')
예제 #2
0
def _run_future(time,abort_make,do_nothing, func, args, kwargs, sender):
    set_locals()
    LOCAL.time = time
    LOCAL.abort_make = abort_make
    LOCAL.do_nothing = do_nothing
    result = None
    exception = None
    try:
        result = func(*args, **kwargs)
        barrier()
    except object, e:
        config.report_exception()
        exception = e
def configure_making(args):
    """ Configure make options, return remaining arguments.
    
        Exits program if options are invalid.
    """
    
    try:
        maker = Make()
        leftovers = maker.parse_partial(args)
        if leftovers != args:
            config.write_colored_text(sys.stderr, '\n'+maker.describe('Make options')+'\n')        
        maker.run()    
        return leftovers
    except:
        config.report_exception()
        sys.exit(1)
    def run_future(time,abort_make,do_selection,done_selection):
        set_locals()
        LOCAL.time = time
        LOCAL.abort_make = abort_make
        LOCAL.do_selection = do_selection
        LOCAL.done_selection = done_selection
        result = None
        exception = None
        try:
            result = func(*args, **kwargs)
            LOCAL.stage.barrier()
            assert not LOCAL.stages, 'Process completed without calling .barrier() on all Stages.'
        except:
            config.report_exception()
            exception = sys.exc_info()[1]

        storage.extend([ LOCAL.time, exception, result ])
예제 #5
0
파일: legion.py 프로젝트: mscook/nesoni
    def run_future(time, abort_make, do_selection, done_selection):
        set_locals()
        LOCAL.time = time
        LOCAL.abort_make = abort_make
        LOCAL.do_selection = do_selection
        LOCAL.done_selection = done_selection
        result = None
        exception = None
        try:
            result = func(*args, **kwargs)
            LOCAL.stage.barrier()
            assert not LOCAL.stages, 'Process completed without calling .barrier() on all Stages.'
        except:
            config.report_exception()
            exception = sys.exc_info()[1]

        storage.extend([LOCAL.time, exception, result])
예제 #6
0
파일: legion.py 프로젝트: mscook/nesoni
def configure_making(args):
    """ Configure make options, return remaining arguments.
    
        Exits program if options are invalid.
    """

    try:
        maker = Make()
        leftovers = maker.parse_partial(args)
        if leftovers != args:
            config.write_colored_text(
                sys.stderr, '\n' + maker.describe('Make options') + '\n')
        maker.run()
        return leftovers
    except:
        config.report_exception()
        sys.exit(1)
def _run_future(time,abort_make,do_selection,done_selection, func, args, kwargs, future_number):
    set_locals()
    LOCAL.time = time
    LOCAL.abort_make = abort_make
    LOCAL.do_selection = do_selection
    LOCAL.done_selection = done_selection
    result = None
    exception = None
    try:
        result = func(*args, **kwargs)
        assert not LOCAL.stages, 'Process completed without calling .barrier() on all Stages.'
    except:
        config.report_exception()
        exception = sys.exc_info()[1]
    
    coordinator().deliver_future(future_number, (LOCAL.time, exception, result))

    #Give core back to parent
    coordinator().release_core()
예제 #8
0
파일: legion.py 프로젝트: mscook/nesoni
def _run_future(time, abort_make, do_selection, done_selection, func, args,
                kwargs, future_number):
    set_locals()
    LOCAL.time = time
    LOCAL.abort_make = abort_make
    LOCAL.do_selection = do_selection
    LOCAL.done_selection = done_selection
    result = None
    exception = None
    try:
        result = func(*args, **kwargs)
        assert not LOCAL.stages, 'Process completed without calling .barrier() on all Stages.'
    except:
        config.report_exception()
        exception = sys.exc_info()[1]

    coordinator().deliver_future(future_number,
                                 (LOCAL.time, exception, result))

    #Give core back to parent
    coordinator().release_core()
예제 #9
0
def run_toolbox(action_classes, script_name=''):
    """
    Provide a command line interface for a list of Actions.
    
    Note:    
    strings included in the action_classes list will be printed 
    as help text, for example to display section headings.
    """
    commands = { }
    help = [ '\n' ]
    for item in action_classes:
        if isinstance(item, str):
            help.append(config.wrap(item, 70) + '\n\n')
            continue
        name = item.shell_name()
        commands[ name ] = item
        help.append('    %s\n' % config.colored(1,name+':'))
        help.append(config.wrap(item.help_short, 70, '        ') + '\n\n')

    args = sys.argv[1:]
    
    if not args:
        config.write_colored_text(sys.stdout, ''.join(help)+'\n\n')
        sys.exit(1)
        
    try:        
        command, args = args[0], args[1:]
        
        mangled_command = command.lower().rstrip(':')
        if mangled_command not in commands:
            raise grace.Error("Don't know how to "+command)        
    except:
        config.report_exception()
        sys.exit(1)

    config.shell_run(commands[mangled_command](), args, (script_name+' ' if script_name else '') + mangled_command+':')
예제 #10
0
파일: legion.py 프로젝트: mscook/nesoni
def run_toolbox(action_classes, script_name='', show_make_flags=True):
    """
    Provide a command line interface for a list of Actions.
    
    Note:    
    strings included in the action_classes list will be printed 
    as help text, for example to display section headings.
    """
    args = configure_making(sys.argv[1:])

    commands = {}

    for item in action_classes:
        if isinstance(item, str):
            continue
        name = item.shell_name()
        commands[name] = item

    if args == ['--help-make']:
        help = ['\n']
        help.append(
            '\nMake options:\n' +
            Make().describe('', show_help=True, escape_newlines=False) + '\n')

        config.write_colored_text(sys.stdout, ''.join(help) + '\n\n')
        sys.exit(1)

    if not args or args == ['-h'] or args == ['--help']:
        help = ['\n']

        for item in action_classes:
            if isinstance(item, str):
                help.append(config.wrap(item, 70) + '\n\n')
                continue
            name = item.shell_name()
            help.append('    %s\n' % config.colored(1, name + ':'))
            help.append(
                config.color_as_comment(
                    config.wrap(item.help_short, 70, '        ')) + '\n\n')

        if show_make_flags:
            #help.append('\nMake options:\n'+Make().describe('', show_help=True, escape_newlines=False)+'\n')
            help.append(
                '\nFor workflow make options type "%s --help-make".\n' %
                script_name)

        config.write_colored_text(sys.stdout, ''.join(help))
        sys.exit(1)

    try:
        command, args = args[0], args[1:]

        mangled_command = command.lower().rstrip(':')
        if mangled_command not in commands:
            raise grace.Error("Don't know how to " + command)
    except:
        config.report_exception()
        sys.exit(1)

    config.shell_run(commands[mangled_command](), args,
                     (script_name + ' ' if script_name else '') +
                     mangled_command + ':')
예제 #11
0
import sys

import nesoni
from nesoni import grace, config

try:
    sys.exit(nesoni.main(sys.argv[1:]))

except grace.Help_shown:
    sys.exit(1)

except Exception:
    config.report_exception()
    sys.exit(1)