Esempio n. 1
0
def run_server(bindaddr,
               env,
               output_path,
               prune=True,
               verbosity=0,
               lektor_dev=False,
               ui_lang='en',
               browse=False,
               extra_flags=None):
    """This runs a server but also spawns a background process.  It's
    not safe to call this more than once per python process!
    """
    wz_as_main = os.environ.get('WERKZEUG_RUN_MAIN') == 'true'
    in_main_process = not lektor_dev or wz_as_main
    extra_flags = process_extra_flags(extra_flags)

    if in_main_process:
        background_builder = BackgroundBuilder(env,
                                               output_path=output_path,
                                               prune=prune,
                                               verbosity=verbosity,
                                               extra_flags=extra_flags)
        background_builder.setDaemon(True)
        background_builder.start()
        env.plugin_controller.emit('server-spawn',
                                   bindaddr=bindaddr,
                                   extra_flags=extra_flags)

    app = WebAdmin(env,
                   output_path=output_path,
                   verbosity=verbosity,
                   debug=lektor_dev,
                   ui_lang=ui_lang,
                   extra_flags=extra_flags)

    dt = None
    if lektor_dev and not wz_as_main:
        dt = DevTools(env)
        dt.start()

    if browse:
        browse_to_address(bindaddr)

    try:
        return run_simple(
            bindaddr[0],
            bindaddr[1],
            app,
            use_debugger=True,
            threaded=True,
            use_reloader=lektor_dev,
            request_handler=not lektor_dev and SilentWSGIRequestHandler
            or WSGIRequestHandler)
    finally:
        if dt is not None:
            dt.stop()
        if in_main_process:
            env.plugin_controller.emit('server-stop')
Esempio n. 2
0
def run_server(bindaddr, env, output_path, prune=True, verbosity=0,
               lektor_dev=False, ui_lang='en', browse=False, extra_flags=None):
    """This runs a server but also spawns a background process.  It's
    not safe to call this more than once per python process!
    """
    wz_as_main = os.environ.get('WERKZEUG_RUN_MAIN') == 'true'
    in_main_process = not lektor_dev or wz_as_main
    extra_flags = process_extra_flags(extra_flags)

    if in_main_process:
        background_builder = BackgroundBuilder(env, output_path=output_path,
                                               prune=prune, verbosity=verbosity,
                                               extra_flags=extra_flags)
        background_builder.setDaemon(True)
        background_builder.start()
        env.plugin_controller.emit('server-spawn', bindaddr=bindaddr,
                                   extra_flags=extra_flags)

    app = WebAdmin(env, output_path=output_path, verbosity=verbosity,
                   debug=lektor_dev, ui_lang=ui_lang,
                   extra_flags=extra_flags)

    dt = None
    if lektor_dev and not wz_as_main:
        dt = DevTools(env)
        dt.start()

    if browse:
        browse_to_address(bindaddr)

    try:
        return run_simple(bindaddr[0], bindaddr[1], app,
                          use_debugger=True, threaded=True,
                          use_reloader=lektor_dev,
                          request_handler=not lektor_dev
                          and SilentWSGIRequestHandler or WSGIRequestHandler)
    finally:
        if dt is not None:
            dt.stop()
        if in_main_process:
            env.plugin_controller.emit('server-stop')
 def emit(self, event, **kwargs):
     from lektor.builder import process_extra_flags
     rv = {}
     kwargs['extra_flags'] = process_extra_flags(self.extra_flags)
     funcname = 'on_' + event.replace('-', '_')
     for plugin in self.iter_plugins():
         handler = getattr(plugin, funcname, None)
         if handler is not None:
             try:
                 rv[plugin.id] = handler(**kwargs)
             except TypeError:
                 old_style_kwargs = kwargs.copy()
                 old_style_kwargs.pop("extra_flags")
                 rv[plugin.id] = handler(**old_style_kwargs)
                 warnings.warn(
                     'The plugin "{}" function "{}" does not accept extra_flags. '
                     "It should be updated to accept `**extra` so that it will "
                     "not break if new parameters are passed to it by newer "
                     "versions of Lektor.".format(plugin.id, funcname),
                     DeprecationWarning)
     return rv