示例#1
0
def main(sysargs=None):
    parser = argparse.ArgumentParser(
        description="xylem is a package manager abstraction tool.",
        add_help=False,
        formatter_class=ConfigHelpFormatter
    )
    add_config_arguments(parser)
    add_global_arguments(parser)

    cmds = list_commands()
    create_subparsers(parser, cmds)

    args = parser.parse_args(sysargs)
    handle_global_arguments(args)
    handle_config_arguments(args)

    # FIXME: the following logic and error handling
    try:
        args.func
        result = args.func(args)
    except XylemError as e:
        if is_debug() or isinstance(e, XylemInternalError):
            print_exc(exc_to_str(e, tb=True, chain=True))
        else:
            error(exc_to_str(e, tb=False, chain=True))
        sys.exit(1)
    except (KeyboardInterrupt, EOFError):
        info('')
        sys.exit(1)
    sys.stdout.write(ansi('reset'))
    sys.exit(result or 0)
示例#2
0
def main(args=None):
    args = command_handle_args(args, definition)
    config = get_config()
    try:
        resolve_errors, install_errors = install(
            args.xylem_key,
            all_keys=args.all,
            config=config,
            reinstall=args.reinstall,
            simulate=args.dry_run,
            continue_on_error=args.continue_on_error,
            fix_prerequisites=args.fix_prerequisites)
        if resolve_errors:
            # error("The following errors occurred during resolution:")
            error("\n".join(
                indent(exc_to_str(e), 2, exclude_first=True)
                for _, e in resolve_errors))
        if install_errors:
            # error("The following errors occurred during installation:")
            error("\n".join(
                indent(exc_to_str(e), 2, exclude_first=True)
                for e in install_errors))
        if resolve_errors or install_errors:
            sys.exit(1)
    except (KeyboardInterrupt, EOFError):
        info('')
        sys.exit(1)
示例#3
0
文件: install.py 项目: catkin/xylem
def main(args=None):
    args = command_handle_args(args, definition)
    config = get_config()
    try:
        resolve_errors, install_errors = install(
            args.xylem_key,
            all_keys=args.all,
            config=config,
            reinstall=args.reinstall,
            simulate=args.dry_run,
            continue_on_error=args.continue_on_error,
            fix_prerequisites=args.fix_prerequisites)
        if resolve_errors:
            # error("The following errors occurred during resolution:")
            error("\n".join(indent(exc_to_str(e), 2, exclude_first=True)
                            for _, e in resolve_errors))
        if install_errors:
            # error("The following errors occurred during installation:")
            error("\n".join(indent(exc_to_str(e), 2, exclude_first=True)
                            for e in install_errors))
        if resolve_errors or install_errors:
            sys.exit(1)
    except (KeyboardInterrupt, EOFError):
        info('')
        sys.exit(1)
示例#4
0
def main(args=None):
    args = command_handle_args(args, definition)
    config = get_config()
    try:
        ic = InstallerContext(config=config)
        default_installer_name = ic.get_default_installer_name()
        results, errors = resolve(args.xylem_key, all_keys=args.all,
                                  config=config, installer_context=ic)
        if errors:
            error("\n".join(indent(exc_to_str(e), 2, exclude_first=True)
                            for _, e in errors))
        for key, (installer_name, resolutions) in results:
            if installer_name != default_installer_name or \
                    args.show_default_installer:
                installer_string = "{0}: ".format(installer_name)
            else:
                installer_string = ""
            resolution_string = ', '.join(map(to_str, resolutions))
            info("{0} --> {1}{2}".
                 format(ansi("cyanf") + key + ansi("reset"),
                        ansi("bluef") + installer_string,
                        ansi("yellowf") + resolution_string))
        if errors:
            sys.exit(1)
    except (KeyboardInterrupt, EOFError):
        info('')
        sys.exit(1)
示例#5
0
def install(xylem_keys,
            all_keys=False,
            interactive=True,
            reinstall=False,
            simulate=False,
            continue_on_error=False,
            fix_prerequisites=False,
            config=None,
            database=None,
            sources_context=None,
            installer_context=None):
    #  1. Prepare config and contexts and load database
    config = ensure_config(config)
    installer_context = ensure_installer_context(installer_context, config)

    #  2. Resolve keys
    results, resolve_errors = resolve(xylem_keys,
                                      all_keys=all_keys,
                                      config=config,
                                      database=database,
                                      sources_context=sources_context,
                                      installer_context=installer_context)
    if resolve_errors and not continue_on_error:
        return resolve_errors, []

    resolved = _squash_resolutions(res_tuple for _, res_tuple in results)

    #  3. check general prerequisites for all installers
    check_general_prerequisites(_installer_names(resolved),
                                installer_context,
                                fix_unsatisfied=fix_prerequisites,
                                interactive=interactive)

    #  4. Determine uninstalled resolutions
    if not reinstall:
        resolved, uninstalled_errors = filter_uninstalled(
            resolved, installer_context)
        # TODO: figure out what exactly to do with these errors... For
        #       now print them here
        for err in uninstalled_errors:
            error(exc_to_str(uninstalled_errors))

    if uninstalled_errors and not continue_on_error:
        return resolve_errors, []

    #  5. check prerequisites all resolutions to be installed
    check_install_prerequisites(_map_resolutions(resolved),
                                installer_context,
                                fix_unsatisfied=fix_prerequisites,
                                interactive=interactive)

    #  6. Install resolved items
    install_errors = install_resolved(resolved,
                                      installer_context,
                                      interactive=interactive,
                                      reinstall=reinstall,
                                      simulate=simulate,
                                      continue_on_error=continue_on_error)

    return resolve_errors, install_errors
示例#6
0
def load_plugins(kind, base_class, group, disabled=[]):
    """Load plugins form entry points.

    Load the plugins of given ``kind`` from entry points ``group``,
    instantiating objects and ignoring duplicates. The entry points must
    be valid plugin definitions (see :func:`verify_plugin_definition`).
    The list of plugins is free of duplicates by plugin class name (not
    plugin name), whereas the list of ``disabled`` plugins refer to the
    plugin names instead.

    :param str kind: kind of plugin (e.g. "installer")
    :param base_class: (abstract) base class plugins (must implement
        PluginBase)
    :param group: entry point group to load plugins from
    :param disabled: list of plugins to ignore; these are plugin names,
        not plugin object names
    :type disabled: `list` of `str`
    :return: list of the loaded and instantiated plugin classes
    :rtype: `list`
    """
    plugin_list = []
    name_set = set()
    for entry_point in pkg_resources.iter_entry_points(group=group):
        definition = entry_point.load()
        try:
            verify_plugin_definition(definition, kind, base_class)
        except InvalidPluginError as e:
            # TODO: somehow decide when to reraise and when to display error
            error("Skipping {} plugin. Failed to load from '{}' entry point "
                  "with name '{}':\n{}".format(kind, group, entry_point.name,
                                               e))
            continue
        plugin_name = definition["plugin_name"]
        if plugin_name in disabled:
            info_v("Skipping disabled {} plugin '{}'.".format(
                kind, plugin_name))
            continue
        plugin_class = definition[kind]
        plugin_obj = plugin_class()
        obj_name = plugin_obj.name
        try:
            plugin_class.verify_plugin(plugin_obj)
        except InvalidPluginError as e:
            # TODO: somehow decide when to reraise and when to display error
            error("Skipping {} plugin '{}'. Plugin is invalid:\n{}".format(
                kind, plugin_name, exc_to_str(e)))
            continue
        if obj_name in name_set:
            # TODO: somehow decide when to reraise and when to display error
            warning(
                "Ignoring {0} plugin '{1}' with duplicate name '{1}'".format(
                    kind, definition['plugin_name'], obj_name))
            continue
        info_v("Loaded {0} plugin '{1}' with {0} name '{2}'.".format(
            kind, plugin_name, obj_name))
        name_set.add(obj_name)
        plugin_list.append(plugin_obj)
    return plugin_list
示例#7
0
def load_plugins(kind, base_class, group, disabled=[]):
    """Load plugins form entry points.

    Load the plugins of given ``kind`` from entry points ``group``,
    instantiating objects and ignoring duplicates. The entry points must
    be valid plugin definitions (see :func:`verify_plugin_definition`).
    The list of plugins is free of duplicates by plugin class name (not
    plugin name), whereas the list of ``disabled`` plugins refer to the
    plugin names instead.

    :param str kind: kind of plugin (e.g. "installer")
    :param base_class: (abstract) base class plugins (must implement
        PluginBase)
    :param group: entry point group to load plugins from
    :param disabled: list of plugins to ignore; these are plugin names,
        not plugin object names
    :type disabled: `list` of `str`
    :return: list of the loaded and instantiated plugin classes
    :rtype: `list`
    """
    plugin_list = []
    name_set = set()
    for entry_point in pkg_resources.iter_entry_points(group=group):
        definition = entry_point.load()
        try:
            verify_plugin_definition(definition, kind, base_class)
        except InvalidPluginError as e:
            # TODO: somehow decide when to reraise and when to display error
            error("Skipping {} plugin. Failed to load from '{}' entry point "
                  "with name '{}':\n{}".format(
                      kind, group, entry_point.name, e))
            continue
        plugin_name = definition["plugin_name"]
        if plugin_name in disabled:
            info_v("Skipping disabled {} plugin '{}'.".
                   format(kind, plugin_name))
            continue
        plugin_class = definition[kind]
        plugin_obj = plugin_class()
        obj_name = plugin_obj.name
        try:
            plugin_class.verify_plugin(plugin_obj)
        except InvalidPluginError as e:
            # TODO: somehow decide when to reraise and when to display error
            error("Skipping {} plugin '{}'. Plugin is invalid:\n{}".format(
                  kind, plugin_name, exc_to_str(e)))
            continue
        if obj_name in name_set:
            # TODO: somehow decide when to reraise and when to display error
            warning("Ignoring {0} plugin '{1}' with duplicate name '{1}'".
                    format(kind, definition['plugin_name'], obj_name))
            continue
        info_v("Loaded {0} plugin '{1}' with {0} name '{2}'.".
               format(kind, plugin_name, obj_name))
        name_set.add(obj_name)
        plugin_list.append(plugin_obj)
    return plugin_list
示例#8
0
文件: util.py 项目: catkin/xylem
def custom_exception_handler(type, value, tb):
    # Print traceback, ...
    print_exc(exc_to_str(value, tb))
    if not pdb_enabled() or hasattr(sys, 'ps1') or not sys.stderr.isatty():
        pass
    else:
        # ...then start the debugger in post-mortem mode.
        import pdb
        pdb.set_trace()
示例#9
0
文件: util.py 项目: pombredanne/xylem
def custom_exception_handler(type, value, tb):
    # Print traceback, ...
    print_exc(exc_to_str(value, tb))
    if not pdb_enabled() or hasattr(sys, 'ps1') or not sys.stderr.isatty():
        pass
    else:
        # ...then start the debugger in post-mortem mode.
        import pdb
        pdb.set_trace()