コード例 #1
0
ファイル: manage.py プロジェクト: tiddlyweb/tiddlyweb
def handle(args):
    """
    Dispatch to the proper function for the command given in ``args[1]``.
    """
    from tiddlyweb.config import config

    options = _extract_options(args, ['load'])
    if 'load' in options:
        _external_load(options['load'], config)
    if 'tb' in options:
        config['twanager.tracebacks'] = True

    initialize_logging(config)

    plugins = INTERNAL_PLUGINS
    try:
        plugins.extend(config['twanager_plugins'])
        for plugin in plugins:
            LOGGER.debug('attempting to import twanager plugin %s', plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ['init'])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    candidate_command = None
    try:
        candidate_command = args[1]
    except IndexError:
        usage('Missing command')

    try:
        args = args[2:]
    except IndexError:
        args = []

    args = [unicode(arg) for arg in args]
    if candidate_command and candidate_command in COMMANDS:
        try:
            LOGGER.debug('running command %s with %s',
                    candidate_command, args)
            COMMANDS[candidate_command](args)
        except IndexError:
            usage('Incorect number of arguments')
        except Exception as exc:
            if config.get('twanager.tracebacks', False):
                raise
            import traceback
            LOGGER.error('twanager error with command "%s %s"\n%s',
                    candidate_command, args, traceback.format_exc())
            usage('%s: %s' % (exc.__class__.__name__, exc.args[0]))
    else:
        usage('No matching command found')
コード例 #2
0
ファイル: manage.py プロジェクト: kang2367/tiddlyweb
def handle(args):
    """
    Dispatch to the proper function for the command given in ``args[1]``.
    """
    from tiddlyweb.config import config

    options = _extract_options(args, ['load'])
    if 'load' in options:
        _external_load(options['load'], config)
    if 'tb' in options:
        config['twanager.tracebacks'] = True

    initialize_logging(config)

    plugins = INTERNAL_PLUGINS
    try:
        plugins.extend(config['twanager_plugins'])
        for plugin in plugins:
            LOGGER.debug('attempting to import twanager plugin %s', plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ['init'])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    candidate_command = None
    try:
        candidate_command = args[1]
    except IndexError:
        usage('Missing command')

    try:
        args = args[2:]
    except IndexError:
        args = []

    args = [unicode(arg) for arg in args]
    if candidate_command and candidate_command in COMMANDS:
        try:
            LOGGER.debug('running command %s with %s', candidate_command, args)
            COMMANDS[candidate_command](args)
        except IndexError:
            usage('Incorect number of arguments')
        except Exception as exc:
            if config.get('twanager.tracebacks', False):
                raise
            import traceback
            LOGGER.error('twanager error with command "%s %s"\n%s',
                         candidate_command, args, traceback.format_exc())
            usage('%s: %s' % (exc.__class__.__name__, exc.args[0]))
    else:
        usage('No matching command found')
コード例 #3
0
ファイル: manage.py プロジェクト: JazzDeben/tiddlyweb-xmobile
def handle(args):
    """
    Dispatch to the proper function for the command
    given in a args[1].
    """
    from tiddlyweb.config import config

    try:
        if args[1] == "--load":
            args = _external_load(args, config)
    except IndexError:
        args = []

    initialize_logging(config)

    plugins = INTERNAL_PLUGINS
    try:
        plugins.extend(config["twanager_plugins"])
        for plugin in plugins:
            logging.debug("attempting to import twanager plugin %s", plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ["init"])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    candidate_command = None
    try:
        candidate_command = args[1]
    except IndexError:
        usage("Missing command")

    try:
        args = args[2:]
    except IndexError:
        args = []

    if candidate_command and candidate_command in COMMANDS:
        try:
            logging.debug("running command %s with %s", candidate_command, args)
            COMMANDS[candidate_command](args)
        except IndexError, exc:
            usage("Incorect number of arguments")
        except Exception, exc:
            if config.get("twanager.tracebacks", False):
                raise
            import traceback

            logging.error('twanager error with command "%s %s"\n%s', candidate_command, args, traceback.format_exc())
            usage("%s: %s" % (exc.__class__.__name__, exc.args))
コード例 #4
0
ファイル: serve.py プロジェクト: 24king/tiddlyweb
def load_app(app_prefix=None, dirname=None):
    """
    Create our application from a series of layers. The innermost
    layer is a Selector application based on ``urls_map`` defined in
    :py:mod:`config <tiddlyweb.config>`. This is surrounded by wrappers,
    which either set something in the environment, modify the request,
    or transform the response. The wrappers are WSGI middleware defined
    by ``server_request_filters`` and ``server_response_filters`` in
    :py:mod:`tiddlyweb.config`.
    """
    from tiddlyweb.config import config
    if dirname:
        config['root_dir'] = dirname

    # If the logger is not already initialized (from twanager),
    # let's initialize it.
    if LOGGER.parent.name is not 'tiddlyweb':
        initialize_logging(config, server=True)

    mapfile = config['urls_map']
    if app_prefix is not None:
        prefix = app_prefix
    else:
        prefix = config['server_prefix']
    app = Selector(mapfile=mapfile, prefix=prefix)
    config['selector'] = app

    try:
        plugins = config['system_plugins']
        for plugin in plugins:
            LOGGER.debug('attempt to import system plugin %s', plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ['init'])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    wrappers = []
    wrappers.extend(reversed(config['server_request_filters']))
    wrappers.append(RequestStarter)  # required as the first app
    wrappers.append(Configurator)  # required as the second app
    wrappers.extend(config['server_response_filters'])
    if wrappers:
        for wrapper in wrappers:
            LOGGER.debug('wrapping app with %s', wrapper)
            if wrapper == Configurator:
                app = wrapper(app, config=config)
            else:
                app = wrapper(app)
    return app
コード例 #5
0
ファイル: serve.py プロジェクト: sgml/tiddlyweb
def load_app(app_prefix=None, dirname=None):
    """
    Create our application from a series of layers. The innermost
    layer is a Selector application based on ``urls_map`` defined in
    :py:mod:`config <tiddlyweb.config>`. This is surrounded by wrappers,
    which either set something in the environment, modify the request,
    or transform the response. The wrappers are WSGI middleware defined
    by ``server_request_filters`` and ``server_response_filters`` in
    :py:mod:`tiddlyweb.config`.
    """
    from tiddlyweb.config import config
    if dirname:
        config['root_dir'] = dirname

    # If the logger is not already initialized (from twanager),
    # let's initialize it.
    if LOGGER.parent.name is not 'tiddlyweb':
        initialize_logging(config, server=True)

    mapfile = config['urls_map']
    if app_prefix is not None:
        prefix = app_prefix
    else:
        prefix = config['server_prefix']
    app = Selector(mapfile=mapfile, prefix=prefix)
    config['selector'] = app

    try:
        plugins = config['system_plugins']
        for plugin in plugins:
            LOGGER.debug('attempt to import system plugin %s', plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ['init'])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    wrappers = []
    wrappers.extend(reversed(config['server_request_filters']))
    wrappers.append(RequestStarter)  # required as the first app
    wrappers.append(Configurator)  # required as the second app
    wrappers.extend(config['server_response_filters'])
    if wrappers:
        for wrapper in wrappers:
            LOGGER.debug('wrapping app with %s', wrapper)
            if wrapper == Configurator:
                app = wrapper(app, config=config)
            else:
                app = wrapper(app)
    return app
コード例 #6
0
def handle(args):
    """
    Dispatch to the proper function for the command
    given in a args[1].
    """
    from tiddlyweb.config import config
    try:
        if args[1] == '--load':
            args = _external_load(args, config)
    except IndexError:
        args = []

    initialize_logging(config)

    plugins = INTERNAL_PLUGINS
    try:
        plugins.extend(config['twanager_plugins'])
        for plugin in plugins:
            logging.debug('attempting to import twanager plugin %s', plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ['init'])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    candidate_command = None
    try:
        candidate_command = args[1]
    except IndexError:
        usage('Missing command')

    try:
        args = args[2:]
    except IndexError:
        args = []

    if candidate_command and candidate_command in COMMANDS:
        try:
            logging.debug('running command %s with %s', candidate_command,
                          args)
            COMMANDS[candidate_command](args)
        except IndexError, exc:
            usage('Incorect number of arguments')
        except Exception, exc:
            if config.get('twanager.tracebacks', False):
                raise
            import traceback
            logging.error('twanager error with command "%s %s"\n%s',
                          candidate_command, args, traceback.format_exc())
            usage('%s: %s' % (exc.__class__.__name__, exc.args))
コード例 #7
0
ファイル: serve.py プロジェクト: FND/tiddlyweb
def load_app(app_prefix=None, dirname=None):
    """
    Create our application from a series of layers. The innermost
    layer is a selector application based on urls_map in config. This
    is surround by wrappers, which either set something in the
    environment, modify the request, or transform output.
    """
    from tiddlyweb.config import config

    if dirname:
        config["root_dir"] = dirname

    # If the logger is not already initialized (from twanager),
    # let's initialize it.
    if LOGGER.parent.name is not "tiddlyweb":
        initialize_logging(config, server=True)

    mapfile = config["urls_map"]
    if app_prefix is not None:
        prefix = app_prefix
    else:
        prefix = config["server_prefix"]
    app = Selector(mapfile=mapfile, prefix=prefix)
    config["selector"] = app

    try:
        plugins = config["system_plugins"]
        for plugin in plugins:
            LOGGER.debug("attempt to import system plugin %s", plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ["init"])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    wrappers = []
    wrappers.extend(reversed(config["server_request_filters"]))
    wrappers.append(RequestLogger)  # required as the first app
    wrappers.append(Configurator)  # required as the second app
    wrappers.extend(config["server_response_filters"])
    if wrappers:
        for wrapper in wrappers:
            LOGGER.debug("wrapping app with %s", wrapper)
            if wrapper == Configurator:
                app = wrapper(app, config=config)
            else:
                app = wrapper(app)
    return app
コード例 #8
0
def load_app(app_prefix=None, dirname=None):
    """
    Create our application from a series of layers. The innermost
    layer is a selector application based on urls_map in config. This
    is surround by wrappers, which either set something in the
    environment, modify the request, or transform output.
    """
    from tiddlyweb.config import config
    if dirname:
        config['root_dir'] = dirname

    initialize_logging(config)

    mapfile = config['urls_map']
    if app_prefix != None:
        prefix = app_prefix
    else:
        prefix = config['server_prefix']
    app = selector.Selector(mapfile=mapfile, prefix=prefix)
    config['selector'] = app

    try:
        plugins = config['system_plugins']
        for plugin in plugins:
            logging.debug('attempt to import system plugin %s', plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ['init'])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    wrappers = []
    wrappers.extend(reversed(config['server_request_filters']))
    wrappers.append(Environator)  # required as the first app
    wrappers.append(Configurator)  # required as the second app
    wrappers.extend(config['server_response_filters'])
    if wrappers:
        for wrapper in wrappers:
            logging.debug('wrapping app with %s', wrapper)
            if wrapper == Configurator:
                app = wrapper(app, config=config)
            else:
                app = wrapper(app)
    return app
コード例 #9
0
ファイル: serve.py プロジェクト: chancejiang/tiddlyweb
def load_app(app_prefix=None, dirname=None):
    """
    Create our application from a series of layers. The innermost
    layer is a selector application based on urls_map in config. This
    is surround by wrappers, which either set something in the
    environment, modify the request, or transform output.
    """
    from tiddlyweb.config import config
    if dirname:
        config['root_dir'] = dirname

    initialize_logging(config)

    mapfile = config['urls_map']
    if app_prefix != None:
        prefix = app_prefix
    else:
        prefix = config['server_prefix']
    app = selector.Selector(mapfile=mapfile, prefix=prefix)
    config['selector'] = app

    try:
        plugins = config['system_plugins']
        for plugin in plugins:
            logging.debug('attempt to import system plugin %s', plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ['init'])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    wrappers = []
    wrappers.extend(reversed(config['server_request_filters']))
    wrappers.append(Environator)  # required as the first app
    wrappers.append(Configurator)  # required as the second app
    wrappers.extend(config['server_response_filters'])
    if wrappers:
        for wrapper in wrappers:
            logging.debug('wrapping app with %s', wrapper)
            if wrapper == Configurator:
                app = wrapper(app, config=config)
            else:
                app = wrapper(app)
    return app