示例#1
0
def index():
    """ Deliver static landing page that launches the client-side app. """
    default_config = cache.get('default-config')
    if default_config is None:
        default_config = app.config['default_config'].flatten()
        cache.set('default-config', default_config)
    templates = cache.get('plugin-templates')
    if templates is None:
        templates = _get_templates()
        cache.set('plugin-templates', templates)
    return render_template(
        "index.html",
        version=get_version(),
        debug=app.config['debug'],
        default_config=default_config,
        plugins=_list_plugins(),
        config_templates=templates,
        metaschema=spreads.metadata.Metadata.SCHEMA,
    )
示例#2
0
文件: web.py 项目: duerig/spreads
def index():
    """ Deliver static landing page that launches the client-side app. """
    default_config = cache.get('default-config')
    if default_config is None:
        default_config = app.config['default_config'].flatten()
        cache.set('default-config', default_config)
    templates = cache.get('plugin-templates')
    if templates is None:
        templates = get_plugin_templates()
        cache.set('plugin-templates', templates)
    return render_template(
        "index.html",
        version=get_version(),
        debug=app.config['debug'],
        default_config=default_config,
        plugins=list_plugins(),
        plugin_templates=templates,
        metaschema=spreads.metadata.Metadata.SCHEMA,
    )
示例#3
0
def setup_parser(config):
    """ Sets up an :py:class:`argparse.ArgumentParser` instance with all
    options and subcommands that are available in the core and activated
    plugins.

    :param config:  Current application configuration
    :type config:   :py:class:`spreads.config.Configuration`
    :returns:       Fully initialized argument parser
    :rtype:         :py:class:`argparse.ArgumentParser`
    """
    plugins = plugin.get_plugins(*config["plugins"].get())

    def _add_arguments(parsers, mixins, extra_names=None):
        if extra_names is None:
            extra_names = []
        for parser in parsers:
            # Only plugins that implement the capture or trigger hook mixins
            # and the currently active device configuration are relevant for
            # this subcommand.
            ext_names = [name for name, cls in plugins.iteritems()
                         if any(issubclass(cls, mixin) for mixin in mixins)]
            ext_names.extend(extra_names)
            for ext in ext_names:
                for key, tmpl in config.templates.get(ext, {}).iteritems():
                    if not should_show_argument(option,
                                                config['plugins'].get()):
                        continue
                    try:
                        add_argument_from_template(ext, key, tmpl, parser,
                                                   config[ext][key].get())
                    except TypeError:
                        continue

    rootparser = argparse.ArgumentParser(
        description="Scanning Tool for  DIY Book Scanner",
        formatter_class=argparse.RawDescriptionHelpFormatter)

    rootparser.add_argument(
        '-V', '--version', action='version',
        version=(
            "spreads {0}\n\n"
            "Licensed under the terms of the GNU Affero General Public "
            "License 3.0.\n"
            "(C) 2013-2014 Johannes Baiter <*****@*****.**>\n"
            "For a complete list of contributors see:\n"
            "https://github.com/DIYBookScanner/spreads/graphs/contributors\n\n"
            .format(util.get_version())))

    for key, option in config.templates['core'].iteritems():
        if not should_show_argument(option, config['plugins'].get()):
            continue
        try:
            add_argument_from_template('core', key, option, rootparser,
                                       config['core'][key].get())
        except TypeError:
            continue

    subparsers = rootparser.add_subparsers()

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

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

    try:
        import spreads.tkconfigure as tkconfigure
        guiconfig_parser = subparsers.add_parser(
            'guiconfigure', help="Perform initial configuration with a GUI")
        guiconfig_parser.set_defaults(subcommand=tkconfigure.configure)
    except ImportError:
        pass

    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=cli.capture)
    # Add arguments from plugins
    _add_arguments(parsers=(capture_parser, wizard_parser),
                   mixins=(plugin.CaptureHooksMixin, plugin.TriggerHooksMixin),
                   extra_names=('device',))

    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=cli.postprocess)
    _add_arguments(parsers=(postprocess_parser, wizard_parser),
                   mixins=(plugin.ProcessHooksMixin,))

    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=cli.output)
    _add_arguments(parsers=(output_parser, wizard_parser),
                   mixins=(plugin.OutputHooksMixin,))

    # Add custom subcommands from plugins
    if config["plugins"].get():
        classes = (cls for cls in plugins.values()
                   if issubclass(cls, plugin.SubcommandHooksMixin))
        for cls in classes:
            cls.add_command_parser(subparsers, config)
    return rootparser
示例#4
0
文件: conf.py 项目: OliPelz/spreads
sys.path.append(os.path.abspath('_themes'))
sys.path.insert(0, os.path.abspath(os.path.join('..')))

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage',
              'sphinx.ext.intersphinx', 'sphinxcontrib.fulltoc',
              'sphinxcontrib.autohttp.flask', 'sphinx.ext.viewcode',
              'sphinxcontrib.aafig']

templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'content'

project = u'spreads'
copyright = u'2013, Johannes Baiter (jbaiter)'
version = util.get_version()
release = version
exclude_patterns = ['_build']
add_function_parentheses = True
pygments_style = 'sphinx'


html_theme = 'flask'
html_theme_path = ['_themes']
html_logo = os.path.join('_static', 'monk.png')
html_static_path = ['_static']
html_use_smartypants = True
htmlhelp_basename = 'spreadsdoc'

latex_elements = {
    'papersize': 'a4paper',
示例#5
0
sys.path.append(os.path.abspath('_themes'))
sys.path.insert(0, os.path.abspath(os.path.join('..')))

extensions = [
    'sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.intersphinx',
    'sphinxcontrib.fulltoc', 'sphinxcontrib.autohttp.flask',
    'sphinx.ext.viewcode'
]

templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'

project = u'spreads'
copyright = u'2013, Johannes Baiter (jbaiter)'
version = util.get_version()
release = version
exclude_patterns = ['_build']
add_function_parentheses = True
pygments_style = 'sphinx'

intersphinx_mapping = {
    'python': ('http://docs.python.org/2.7', None),
    'flask': ('http://flask.pocoo.org/docs/0.10/', None),
    'tornado': ('http://tornado.readthedocs.org/en/branch4.0/', None),
    'pillow': ('http://pillow.readthedocs.org/', None),
    'wand': ('http://docs.wand-py.org/en/0.3.8/', None),
    'pathlib': ('http://pathlib.readthedocs.org/en/pep428/', None),
    'confit': ('http://confit.readthedocs.org/en/latest/', None),
    'futures': ('http://pythonhosted.org//futures/', None)
}
示例#6
0
def setup_parser(config):
    """ Sets up an :py:class:`argparse.ArgumentParser` instance with all
    options and subcommands that are available in the core and activated
    plugins.

    :param config:  Current application configuration
    :type config:   :py:class:`spreads.config.Configuration`
    :returns:       Fully initialized argument parser
    :rtype:         :py:class:`argparse.ArgumentParser`
    """
    plugins = plugin.get_plugins(*config["plugins"].get())

    def _add_arguments(parsers, mixins, extra_names=None):
        if extra_names is None:
            extra_names = []
        for parser in parsers:
            # Only plugins that implement the capture or trigger hook mixins
            # and the currently active device configuration are relevant for
            # this subcommand.
            ext_names = [
                name for name, cls in plugins.iteritems() if any(
                    issubclass(cls, mixin) for mixin in mixins)
            ]
            ext_names.extend(extra_names)
            for ext in ext_names:
                for key, tmpl in config.templates.get(ext, {}).iteritems():
                    if not should_show_argument(option,
                                                config['plugins'].get()):
                        continue
                    try:
                        add_argument_from_template(ext, key, tmpl, parser,
                                                   config[ext][key].get())
                    except TypeError:
                        continue

    rootparser = argparse.ArgumentParser(
        description="Scanning Tool for  DIY Book Scanner",
        formatter_class=argparse.RawDescriptionHelpFormatter)

    rootparser.add_argument(
        '-V',
        '--version',
        action='version',
        version=(
            "spreads {0}\n\n"
            "Licensed under the terms of the GNU Affero General Public "
            "License 3.0.\n"
            "(C) 2013-2014 Johannes Baiter <*****@*****.**>\n"
            "For a complete list of contributors see:\n"
            "https://github.com/DIYBookScanner/spreads/graphs/contributors\n\n"
            .format(util.get_version())))

    for key, option in config.templates['core'].iteritems():
        if not should_show_argument(option, config['plugins'].get()):
            continue
        try:
            add_argument_from_template('core', key, option, rootparser,
                                       config['core'][key].get())
        except TypeError:
            continue

    subparsers = rootparser.add_subparsers()

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

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

    try:
        import spreads.tkconfigure as tkconfigure
        guiconfig_parser = subparsers.add_parser(
            'guiconfigure', help="Perform initial configuration with a GUI")
        guiconfig_parser.set_defaults(subcommand=tkconfigure.configure)
    except ImportError:
        pass

    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=cli.capture)
    # Add arguments from plugins
    _add_arguments(parsers=(capture_parser, wizard_parser),
                   mixins=(plugin.CaptureHooksMixin, plugin.TriggerHooksMixin),
                   extra_names=('device', ))

    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=cli.postprocess)
    _add_arguments(parsers=(postprocess_parser, wizard_parser),
                   mixins=(plugin.ProcessHooksMixin, ))

    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=cli.output)
    _add_arguments(parsers=(output_parser, wizard_parser),
                   mixins=(plugin.OutputHooksMixin, ))

    # Add custom subcommands from plugins
    if config["plugins"].get():
        classes = (cls for cls in plugins.values()
                   if issubclass(cls, plugin.SubcommandHooksMixin))
        for cls in classes:
            cls.add_command_parser(subparsers, config)
    return rootparser
示例#7
0
文件: main.py 项目: duerig/spreads
def setup_parser(config):
    plugins = plugin.get_plugins(*config["plugins"].get())
    rootparser = argparse.ArgumentParser(
        description="Scanning Tool for  DIY Book Scanner",
        formatter_class=argparse.RawDescriptionHelpFormatter)

    rootparser.add_argument(
        '-V', '--version', action='version',
        version=(
            "spreads {0}\n\n"
            "Licensed under the terms of the GNU Affero General Public "
            "License 3.0.\n"
            "(C) 2013-2014 Johannes Baiter <*****@*****.**>\n"
            "For a complete list of contributors see:\n"
            "https://github.com/DIYBookScanner/spreads/graphs/contributors\n\n"
            .format(util.get_version())))

    for key, option in config.templates['core'].iteritems():
        try:
            add_argument_from_template('core', key, option, rootparser,
                                       config['core'][key].get())
        except TypeError:
            continue

    subparsers = rootparser.add_subparsers()

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

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

    try:
        import spreads.tkconfigure as tkconfigure
        guiconfig_parser = subparsers.add_parser(
            'guiconfigure', help="Perform initial configuration with a GUI")
        guiconfig_parser.set_defaults(subcommand=tkconfigure.configure)
    except ImportError:
        print "Could not load _tkinter module, disabling guiconfigure command"

    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=cli.capture)
    # Add arguments from plugins
    for parser in (capture_parser, wizard_parser):
        ext_names = [
            name for name, cls in plugins.iteritems()
            if any(issubclass(cls, mixin) for mixin in
                   (plugin.CaptureHooksMixin, plugin.TriggerHooksMixin))]
        ext_names.append('device')
        for ext in ext_names:
            for key, tmpl in config.templates.get(ext, {}).iteritems():
                try:
                    add_argument_from_template(ext, key, tmpl, parser,
                                               config[ext][key].get())
                except TypeError:
                    continue

    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=cli.postprocess)
    # Add arguments from plugins
    for parser in (postprocess_parser, wizard_parser):
        ext_names = [name for name, cls in plugins.iteritems()
                     if issubclass(cls, plugin.ProcessHookMixin)]
        for ext in ext_names:
            for key, tmpl in config.templates.get(ext, {}).iteritems():
                try:
                    add_argument_from_template(ext, key, tmpl, parser,
                                               config[ext][key].get())
                except TypeError:
                    continue

    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=cli.output)
    # Add arguments from plugins
    for parser in (output_parser, wizard_parser):
        ext_names = [name for name, cls in plugins.iteritems()
                     if issubclass(cls, plugin.OutputHookMixin)]
        for ext in ext_names:
            for key, tmpl in config.templates.get(ext, {}).iteritems():
                try:
                    add_argument_from_template(ext, key, tmpl, parser,
                                               config[ext][key].get())
                except TypeError:
                    continue

    # Add custom subcommands from plugins
    if config["plugins"].get():
        classes = (cls for cls in plugins.values()
                   if issubclass(cls, plugin.SubcommandHookMixin))
        for cls in classes:
            cls.add_command_parser(subparsers, config)
    return rootparser