コード例 #1
0
def test_get_relevant_extensions(mock_plugin_mgr):
    plugin_manager = plugin.get_pluginmanager()
    exts = list(plugin.get_relevant_extensions(
        plugin_manager, [plugin.ProcessHookMixin]))
    assert len(exts) == 2
    assert exts[0].name == "test_process"
    assert exts[1].name == "test_process2"
コード例 #2
0
ファイル: cli.py プロジェクト: matti-kariluoma/spreads
 def _add_plugin_arguments(hooks, parser):
     extensions = plugin.get_relevant_extensions(pluginmanager, hooks)
     for ext in extensions:
         tmpl = ext.plugin.configuration_template()
         if not tmpl:
             continue
         for key, option in tmpl.iteritems():
             try:
                 add_argument_from_option(ext.name, key, option, parser)
             except:
                 continue
コード例 #3
0
ファイル: cli.py プロジェクト: Gunirus/spreads
def _setup_processing_pipeline(config):
    pm = get_pluginmanager(config)
    extensions = [ext.name for ext in get_relevant_extensions(pm, ['process'])]
    print("The following postprocessing plugins were detected:")
    print("\n".join(" - {0}".format(ext) for ext in extensions))
    while True:
        answer = raw_input("Please enter the extensions in the order that they"
                           " should be invoked, separated by commas:\n")
        plugins = [x.strip() for x in answer.split(',')]
        if any(x not in extensions for x in plugins):
            print(colorize("At least one of the entered extensions was not"
                           "found, please try again!", colorama.Fore.RED))
        else:
            break
    config["plugins"] = plugins + [x for x in config["plugins"].get()
                                   if x not in plugins]
コード例 #4
0
ファイル: cli.py プロジェクト: matti-kariluoma/spreads
def setup_parser(config):
    def _add_device_arguments(name, parser):
        tmpl = plugin.get_driver(config["driver"]
                                 .get()).driver.configuration_template()
        if not tmpl:
            return
        for key, option in tmpl.iteritems():
            try:
                add_argument_from_option('device', key, option, parser)
            except:
                return

    def _add_plugin_arguments(hooks, parser):
        extensions = plugin.get_relevant_extensions(pluginmanager, hooks)
        for ext in extensions:
            tmpl = ext.plugin.configuration_template()
            if not tmpl:
                continue
            for key, option in tmpl.iteritems():
                try:
                    add_argument_from_option(ext.name, key, option, parser)
                except:
                    continue

    root_options = {
        'verbose': plugin.PluginOption(value=False,
                                       docstring="Enable verbose output"),
        'logfile': plugin.PluginOption(value="~/.config/spreads/spreads.log",
                                       docstring="Path to logfile"),
        'loglevel': plugin.PluginOption(value=['info', 'critical', 'error',
                                               'warning', 'debug'],
                                        docstring="Logging level for logfile",
                                        selectable=True)
    }

    pluginmanager = plugin.get_pluginmanager(config)
    rootparser = argparse.ArgumentParser(
        description="Scanning Tool for  DIY Book Scanner")
    subparsers = rootparser.add_subparsers()
    for key, option in root_options.iteritems():
        add_argument_from_option('', key, option, rootparser)

    wizard_parser = subparsers.add_parser(
        'wizard', help="Interactive mode")
    wizard_parser.add_argument(
        "path", type=unicode, help="Project path")
    wizard_parser.set_defaults(subcommand=wizard)

    config_parser = subparsers.add_parser(
        'configure', help="Perform initial configuration")
    config_parser.set_defaults(subcommand=configure)

    capture_parser = subparsers.add_parser(
        'capture', help="Start the capturing workflow")
    capture_parser.add_argument(
        "path", type=unicode, help="Project path")
    capture_parser.set_defaults(subcommand=capture)
    # Add arguments from plugins
    for parser in (capture_parser, wizard_parser):
        _add_plugin_arguments(
            [plugin.CaptureHooksMixin, plugin.TriggerHooksMixin], parser)
        if 'driver' in config.keys():
            _add_device_arguments('capture', parser)

    postprocess_parser = subparsers.add_parser(
        'postprocess',
        help="Postprocess scanned images.")
    postprocess_parser.add_argument(
        "path", type=unicode, help="Project path")
    postprocess_parser.add_argument(
        "--jobs", "-j", dest="jobs", type=int, default=None,
        metavar="<int>", help="Number of concurrent processes")
    postprocess_parser.set_defaults(subcommand=postprocess)
    # Add arguments from plugins
    for parser in (postprocess_parser, wizard_parser):
        _add_plugin_arguments([plugin.ProcessHookMixin], parser)

    output_parser = subparsers.add_parser(
        'output',
        help="Generate output files.")
    output_parser.add_argument(
        "path", type=unicode, help="Project path")
    output_parser.set_defaults(subcommand=output)
    # Add arguments from plugins
    for parser in (output_parser, wizard_parser):
        _add_plugin_arguments([plugin.OutputHookMixin], parser)

    # Add custom subcommands from plugins
    if config["plugins"].get():
        exts = plugin.get_relevant_extensions(pluginmanager,
                                              [plugin.SubcommandHookMixin])

        for ext in exts:
            ext.plugin.add_command_parser(subparsers)
    return rootparser