Пример #1
0
def action_runserver(instance_path, hostname, port, reloader, debugger,
                     profiler, profiler_file, profiler_dir, shell, show_sql,
                     threaded, processes):
    """start a new development server

\b
Start the LNT server using a development WSGI server. Additional options can be
used to control the server host and port, as well as useful development
features such as automatic reloading.

The command has built-in support for running the server on an instance which
has been packed into a (compressed) tarball. The tarball will be automatically
unpacked into a temporary directory and removed on exit. This is useful for
passing database instances back and forth, when others only need to be able to
view the results.
    """
    import lnt.server.ui.app
    import os

    init_logger(logging.INFO, show_sql=show_sql)

    app = lnt.server.ui.app.App.create_standalone(instance_path, )
    if debugger:
        app.debug = True
    if profiler:
        import werkzeug.contrib.profiler
        if profiler_dir:
            if not os.path.isdir(profiler_dir):
                os.mkdir(profiler_dir)
        app.wsgi_app = werkzeug.contrib.profiler.ProfilerMiddleware(
            app.wsgi_app,
            stream=open(profiler_file, 'w'),
            profile_dir=profiler_dir)
    if shell:
        from flask import current_app
        from flask import g
        import code
        ctx = app.test_request_context()
        ctx.push()

        vars = globals().copy()
        vars.update(locals())
        shell = code.InteractiveConsole(vars)
        shell.interact()
    else:
        app.run(hostname,
                port,
                use_reloader=reloader,
                use_debugger=debugger,
                threaded=threaded,
                processes=processes)
Пример #2
0
def action_runserver(instance_path, hostname, port, reloader, debugger,
                     profiler, profiler_file, profiler_dir, shell, show_sql,
                     threaded, processes):
    """start a new development server

\b
Start the LNT server using a development WSGI server. Additional options can be
used to control the server host and port, as well as useful development
features such as automatic reloading.

The command has built-in support for running the server on an instance which
has been packed into a (compressed) tarball. The tarball will be automatically
unpacked into a temporary directory and removed on exit. This is useful for
passing database instances back and forth, when others only need to be able to
view the results.
    """
    import lnt.server.ui.app
    import os

    init_logger(logging.INFO, show_sql=show_sql)

    app = lnt.server.ui.app.App.create_standalone(instance_path,)
    if debugger:
        app.debug = True
    if profiler:
        import werkzeug.contrib.profiler
        if profiler_dir:
            if not os.path.isdir(profiler_dir):
                os.mkdir(profiler_dir)
        app.wsgi_app = werkzeug.contrib.profiler.ProfilerMiddleware(
            app.wsgi_app, stream=open(profiler_file, 'w'),
            profile_dir=profiler_dir)
    if shell:
        from flask import current_app
        from flask import g
        import code
        ctx = app.test_request_context()
        ctx.push()

        vars = globals().copy()
        vars.update(locals())
        shell = code.InteractiveConsole(vars)
        shell.interact()
    else:
        app.run(hostname, port,
                use_reloader=reloader,
                use_debugger=debugger,
                threaded=threaded,
                processes=processes)
Пример #3
0
    def setUp(self):
        _, instance_path = sys.argv

        # Create the application instance.
        app = lnt.server.ui.app.App.create_standalone(instance_path)
        app.old_config.blacklist = here + "/blacklist"
        app.app_context().push()
        # Get the test suite wrapper.
        with app.test_request_context('/db_default/nts/foo') as r:
            app.preprocess_request()
            r.g.db_name = "default"
            r.g.testsuite_name = "nts"
            self.ts = r.request.get_testsuite()
            self.ts_db = self.ts
        ts_db = self.ts_db
        order1234 = self.order1234 = self._mkorder(ts_db, "1234")
        order1236 = self.order1236 = self._mkorder(ts_db, "1236")

        machine = self.machine = ts_db.Machine("test-machine")
        ts_db.add(machine)

        a_field = ts_db.Sample.fields[0]

        ts_db.commit()

        test = self.test = ts_db.Test("Foo")
        test2 = self.test2 = ts_db.Test("SingleSource/Foo/Bar/baz")
        test3 = self.test3 = ts_db.Test("SingleSource/UnitTests/Bar/baz")
        test4 = self.test4 = ts_db.Test("MultiSource/Benchmarks/Ptrdist/ks/ks")

        self.field_change1 = ts_db.FieldChange(order1234, order1236, machine,
                                               test, a_field)
        self.field_change2 = ts_db.FieldChange(order1234, order1236, machine,
                                               test2, a_field)
        self.field_change3 = ts_db.FieldChange(order1234, order1236, machine,
                                               test3, a_field)
        self.field_change4 = ts_db.FieldChange(order1234, order1236, machine,
                                               test4, a_field)
        ts_db.add(self.field_change1)
        ts_db.add(self.field_change2)
        ts_db.add(self.field_change3)
        ts_db.add(self.field_change4)

        ts_db.commit()
Пример #4
0
def action_runserver(name, args):
    """start a new development server"""

    parser = OptionParser("""\
%s [options] <instance path>

Start the LNT server using a development WSGI server. Additional options can be
used to control the server host and port, as well as useful development features
such as automatic reloading.

The command has built-in support for running the server on an instance which has
been packed into a (compressed) tarball. The tarball will be automatically
unpacked into a temporary directory and removed on exit. This is useful for
passing database instances back and forth, when others only need to be able to
view the results.\
""" % name)
    parser.add_option("",
                      "--hostname",
                      dest="hostname",
                      type=str,
                      help="host interface to use [%default]",
                      default='localhost')
    parser.add_option("",
                      "--port",
                      dest="port",
                      type=int,
                      metavar="N",
                      help="local port to use [%default]",
                      default=8000)
    parser.add_option("",
                      "--reloader",
                      dest="reloader",
                      default=False,
                      action="store_true",
                      help="use WSGI reload monitor")
    parser.add_option("",
                      "--debugger",
                      dest="debugger",
                      default=False,
                      action="store_true",
                      help="use WSGI debugger")
    parser.add_option("",
                      "--profiler-file",
                      dest="profiler_file",
                      help="file to dump profile info to [%default]",
                      default="profiler.log")
    parser.add_option("", "--profiler-dir", dest="profiler_dir",
                      help="pstat.Stats files are saved to this directory " \
                          +"[%default]",
                      default=None)
    parser.add_option("",
                      "--profiler",
                      dest="profiler",
                      default=False,
                      action="store_true",
                      help="enable WSGI profiler")
    parser.add_option("",
                      "--shell",
                      dest="shell",
                      default=False,
                      action="store_true",
                      help="Load in shell.")
    parser.add_option("",
                      "--show-sql",
                      dest="show_sql",
                      default=False,
                      action="store_true",
                      help="show all SQL queries")
    parser.add_option("",
                      "--threaded",
                      dest="threaded",
                      default=False,
                      action="store_true",
                      help="use a threaded server")
    parser.add_option("",
                      "--processes",
                      dest="processes",
                      type=int,
                      metavar="N",
                      help="number of processes to use [%default]",
                      default=1)

    (opts, args) = parser.parse_args(args)
    if len(args) != 1:
        parser.error("invalid number of arguments")

    input_path, = args

    # Setup the base LNT logger.
    # Root logger in debug.
    logger = logging.getLogger(LOGGER_NAME)
    if opts.debugger:
        logger.setLevel(logging.DEBUG)
    handler = logging.StreamHandler()
    handler.setLevel(logging.DEBUG)
    handler.setFormatter(
        logging.Formatter('%(asctime)s %(levelname)s: %(message)s',
                          datefmt='%Y-%m-%d %H:%M:%S'))
    logger.addHandler(handler)

    # Enable full SQL logging, if requested.
    if opts.show_sql:
        sa_logger = logging.getLogger("sqlalchemy")
        if opts.debugger:
            sa_logger.setLevel(logging.DEBUG)
        sa_logger.setLevel(logging.INFO)
        sa_logger.addHandler(handler)

    import lnt.server.ui.app
    app = lnt.server.ui.app.App.create_standalone(input_path, )
    if opts.debugger:
        app.debug = True
    if opts.profiler:
        if opts.profiler_dir:
            if not os.path.isdir(opts.profiler_dir):
                os.mkdir(opts.profiler_dir)
        app.wsgi_app = werkzeug.contrib.profiler.ProfilerMiddleware(
            app.wsgi_app,
            stream=open(opts.profiler_file, 'w'),
            profile_dir=opts.profiler_dir)
    if opts.shell:
        from flask import current_app
        from flask import g
        ctx = app.test_request_context()
        ctx.push()

        vars = globals().copy()
        vars.update(locals())
        shell = code.InteractiveConsole(vars)
        shell.interact()
    else:
        app.run(opts.hostname,
                opts.port,
                use_reloader=opts.reloader,
                use_debugger=opts.debugger,
                threaded=opts.threaded,
                processes=opts.processes)