yaclifw/framework.py
def main(fw_name, args=None, items=None):
    """
    Reusable entry point. Arguments are parsed
    via the argparse-subcommands configured via
    each Command class found in globals(). Stop
    exceptions are propagated to callers.

    The name of the framework will be used in logging
    and similar.
    """

    global DEBUG_LEVEL
    global FRAMEWORK_NAME

    debug_name = "%s_DEBUG_LEVEL" % fw_name.upper()
    if debug_name in os.environ:
        try:
            DEBUG_LEVEL = int(os.environ.get(debug_name))
        except ValueError:
            DEBUG_LEVEL = 10  # Assume poorly formatted means "debug"
    FRAMEWORK_NAME = fw_name

    if args is None:
        args = sys.argv[1:]

    if items is None:
        items = list(globals().items())

    yaclifw_parser, sub_parsers = parsers()

    for name, MyCommand in sorted(items):
        if not isinstance(MyCommand, type):
            continue
        if not issubclass(MyCommand, Command):
            continue
        if MyCommand.NAME == "abstract":
            continue
        MyCommand(sub_parsers)

    ns = yaclifw_parser.parse_args(args)
    ns.func(ns)
    if hasattr(ns, 'callback'):
        if callable(ns.callback):
            ns.callback()
        else:
            raise Stop(3, "Callback not callable")
def main(fw_name, args=None, items=None):
    """
    Reusable entry point. Arguments are parsed
    via the argparse-subcommands configured via
    each Command class found in globals(). Stop
    exceptions are propagated to callers.

    The name of the framework will be used in logging
    and similar.
    """

    global DEBUG_LEVEL
    global FRAMEWORK_NAME

    debug_name = "%s_DEBUG_LEVEL" % fw_name.upper()
    if debug_name in os.environ:
        try:
            DEBUG_LEVEL = int(os.environ.get(debug_name))
        except ValueError:
            DEBUG_LEVEL = 10  # Assume poorly formatted means "debug"
    FRAMEWORK_NAME = fw_name

    if args is None:
        args = sys.argv[1:]

    if items is None:
        items = list(globals().items())

    yaclifw_parser, sub_parsers = parsers()

    for name, MyCommand in sorted(items):
        if not isinstance(MyCommand, type):
            continue
        if not issubclass(MyCommand, Command):
            continue
        if MyCommand.NAME == "abstract":
            continue
        MyCommand(sub_parsers)

    ns = yaclifw_parser.parse_args(args)
    ns.func(ns)
    if hasattr(ns, 'callback'):
        if callable(ns.callback):
            ns.callback()
        else:
            raise Stop(3, "Callback not callable")
Reusable entry point. Arguments are parsed
    via the argparse-subcommands configured via
    each Command class found in globals(). Stop
    exceptions are propagated to callers.

    The name of the framework will be used in logging
    and similar.