Esempio n. 1
0
    def add_command_parser(cls, rootparser, config):
        """
        Add subcommand parsers to root parser.

        :param rootparser: The root parser to add the subcommands to.
        :type rootparser:  :py:class:`argparse.ArgumentParser`
        :param config:     The application configuration
        :type config:      :py:class:`spreads.config.Configuration`
        """
        cmdparser = rootparser.add_parser(
            'web', help="Start the web interface")
        cmdparser.set_defaults(subcommand=cls.run)

        if is_os('windows'):
            wincmdparser = rootparser.add_parser(
                'web-service', help="Start the web interface as a service."
            )
            wincmdparser.set_defaults(subcommand=cls.run_windows_service)

        for key, option in cls.configuration_template().iteritems():
            if not should_show_argument(option, config['plugins'].get()):
                continue
            try:
                add_argument_from_template('web', key, option, cmdparser,
                                           config['web'][key].get())
                if is_os('windows'):
                    add_argument_from_template('web', key, option,
                                               wincmdparser,
                                               config['web'][key].get())
            except TypeError:
                continue
Esempio n. 2
0
    def add_command_parser(cls, rootparser, config):
        cmdparser = rootparser.add_parser(
            'web', help="Start the web interface")
        cmdparser.set_defaults(subcommand=cls.run)

        if is_os('windows'):
            wincmdparser = rootparser.add_parser(
                'web-service', help="Start the web interface as a service."
            )
            wincmdparser.set_defaults(subcommand=cls.run_windows_service)

        for key, option in cls.configuration_template().iteritems():
            try:
                add_argument_from_template('web', key, option, cmdparser,
                                           config['web'][key].get())
                if is_os('windows'):
                    add_argument_from_template('web', key, option,
                                               wincmdparser,
                                               config['web'][key].get())
            except TypeError:
                continue
Esempio n. 3
0
def setup_logging(config):
    """ Conigure application-wide logger.

    :param config:  Global configuration
    :type config:   :py:class:`spreads.config.Configuration`
    """
    loglevel = config['core']['loglevel'].as_choice({
        'none':
        logging.NOTSET,
        'info':
        logging.INFO,
        'debug':
        logging.DEBUG,
        'warning':
        logging.WARNING,
        'error':
        logging.ERROR,
        'critical':
        logging.CRITICAL,
    })
    logger = logging.getLogger()
    # Remove previous handlers
    if logger.handlers:
        for handler in logger.handlers:
            logger.removeHandler(handler)

    # Add stderr handler
    if util.is_os('windows'):
        stdout_handler = logging.StreamHandler()
    else:
        stdout_handler = util.ColourStreamHandler()
    stdout_handler.setLevel(
        logging.DEBUG if config['core']['verbose'].get() else logging.WARNING)
    stdout_handler.setFormatter(logging.Formatter("%(name)s: %(message)s"))
    logger.addHandler(stdout_handler)

    # Add event handler
    logger.addHandler(util.EventHandler())

    # Add logfile handler
    logfile = Path(config['core']['logfile'].as_filename())
    if not logfile.parent.exists():
        logfile.parent.mkdir()
    file_handler = logging.handlers.RotatingFileHandler(
        filename=unicode(logfile), maxBytes=512 * 1024, backupCount=1)
    file_handler.setFormatter(
        logging.Formatter(
            '%(relativeCreated)s %(name)-5s %(levelname)-8s %(message)s'))
    file_handler.setLevel(loglevel)
    logger.addHandler(file_handler)

    # Set root logger level (needed for web plugin)
    logger.setLevel(logging.DEBUG)
Esempio n. 4
0
def setup_logging(config):
    """ Conigure application-wide logger.

    :param config:  Global configuration
    :type config:   :py:class:`spreads.config.Configuration`
    """
    loglevel = config['core']['loglevel'].as_choice({
        'none':     logging.NOTSET,
        'info':     logging.INFO,
        'debug':    logging.DEBUG,
        'warning':  logging.WARNING,
        'error':    logging.ERROR,
        'critical': logging.CRITICAL,
    })
    logger = logging.getLogger()
    # Remove previous handlers
    if logger.handlers:
        for handler in logger.handlers:
            logger.removeHandler(handler)

    # Add stderr handler
    if util.is_os('windows'):
        stdout_handler = logging.StreamHandler()
    else:
        stdout_handler = util.ColourStreamHandler()
    stdout_handler.setLevel(logging.DEBUG if config['core']['verbose'].get()
                            else logging.WARNING)
    stdout_handler.setFormatter(logging.Formatter("%(name)s: %(message)s"))
    logger.addHandler(stdout_handler)

    # Add event handler
    logger.addHandler(util.EventHandler())

    # Add logfile handler
    logfile = Path(config['core']['logfile'].as_filename())
    if not logfile.parent.exists():
        logfile.parent.mkdir()
    file_handler = logging.handlers.RotatingFileHandler(
        filename=unicode(logfile), maxBytes=512*1024, backupCount=1)
    file_handler.setFormatter(logging.Formatter(
        '%(relativeCreated)s %(name)-5s %(levelname)-8s %(message)s'))
    file_handler.setLevel(loglevel)
    logger.addHandler(file_handler)

    # Set root logger level (needed for web plugin)
    logger.setLevel(logging.DEBUG)
Esempio n. 5
0
import pkg_resources
import requests
from flask import (json, jsonify, request, send_file, render_template,
                   redirect, make_response, Response, after_this_request)
from werkzeug.contrib.cache import SimpleCache

import spreads.metadata
import spreads.plugin as plugin
from spreads.util import get_next, is_os, get_version, DeviceException
from spreads.workflow import Workflow, ValidationError

from spreadsplug.web import app
from discovery import discover_servers
from util import WorkflowConverter, get_thumbnail, scale_image, convert_image

if is_os('windows'):
    from util import find_stick_win as find_stick
else:
    from util import find_stick

logger = logging.getLogger('spreadsplug.web')

# Simple dictionary-based cache for expensive calculations
cache = SimpleCache()

# Register custom workflow converter for URL routes
app.url_map.converters['workflow'] = WorkflowConverter


class ApiException(Exception):
    def __init__(self, message, status_code=500, payload=None,
Esempio n. 6
0
import multiprocessing
import re
import shutil
import subprocess
import tempfile
import time
import xml.etree.cElementTree as ET

import psutil
from spreads.vendor.pathlib import Path

import spreads.util as util
from spreads.config import OptionTemplate
from spreads.plugin import HookPlugin, ProcessHooksMixin

IS_WIN = util.is_os('windows')
CLI_BIN = util.find_in_path('scantailor-cli')
GUI_BIN = util.find_in_path('scantailor')

if not CLI_BIN:
    raise util.MissingDependencyException(
        "Could not find executable `scantailor-cli`. Please"
        " install the"
        " appropriate package(s)!")

logger = logging.getLogger('spreadsplug.scantailor')


class ScanTailorPlugin(HookPlugin, ProcessHooksMixin):
    __name__ = 'scantailor'
Esempio n. 7
0
import codecs
import logging
import os
import re
import shutil
import subprocess
import tempfile
import time

from spreads.vendor.pathlib import Path

import spreads.util as util
from spreads.plugin import HookPlugin, OutputHooksMixin

BIN = util.find_in_path('pdfbeads')
IS_WIN = util.is_os('windows')

if not BIN:
    raise util.MissingDependencyException(
        "Could not find executable `pdfbeads`. Please install the appropriate "
        "package(s)!")


logger = logging.getLogger('spreadsplug.pdfbeads')


class PDFBeadsPlugin(HookPlugin, OutputHooksMixin):
    __name__ = 'pdfbeads'

    def output(self, pages, target_path, metadata, table_of_contents):
        """ Go through pages and bundle their most recent images into a PDF
Esempio n. 8
0
import pkg_resources
import requests
from flask import (json, jsonify, request, send_file, render_template,
                   redirect, make_response, Response)
from werkzeug.contrib.cache import SimpleCache

import spreads.metadata
import spreads.plugin as plugin
from spreads.util import is_os, get_version, DeviceException
from spreads.workflow import Workflow, ValidationError

from spreadsplug.web.app import app
from discovery import discover_servers
from util import WorkflowConverter, get_thumbnail, scale_image, convert_image

if is_os('windows'):
    from util import find_stick_win as find_stick
else:
    from util import find_stick

logger = logging.getLogger('spreadsplug.web')

#: Simple dictionary-based cache for expensive calculations
cache = SimpleCache()

# Register custom workflow converter for URL routes
app.url_map.converters['workflow'] = WorkflowConverter


class ApiException(Exception):
    """ General API error that cleanly serializes to JSON.