Exemple #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)
Exemple #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)
Exemple #3
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)
Exemple #4
0
def action_view_comparison(name, args):
    """view a report comparison using a temporary server"""

    import lnt.server.instance
    import lnt.server.ui.app
    import lnt.server.db.migrate

    parser = OptionParser("%s [options] <report A> <report B>" % (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("", "--dry-run", dest="dry_run",
                      help="Do a dry run through the comparison. [%default]"
                      " [%default]", action="store_true", default=False)
    (opts, args) = parser.parse_args(args)

    if len(args) != 2:
        parser.error("invalid number of arguments")

    report_a_path, report_b_path = args

    # Set up the default logger.
    logger = logging.getLogger("lnt")
    logger.setLevel(logging.ERROR)
    handler = logging.StreamHandler(sys.stderr)
    handler.setFormatter(logging.Formatter(
        '%(asctime)s %(levelname)s: %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S'))
    logger.addHandler(handler)

    # Create a temporary directory to hold the instance.
    tmpdir = tempfile.mkdtemp(suffix='lnt')

    try:
        # Create a temporary instance.
        url = 'http://%s:%d' % (opts.hostname, opts.port)
        db_path = os.path.join(tmpdir, 'data.db')
        db_info = lnt.server.config.DBInfo(
            'sqlite:///%s' % (db_path,), '0.4', None,
            lnt.server.config.EmailConfig(False, '', '', []), "0")
        # _(self, name, zorgURL, dbDir, tempDir,
        # profileDir, secretKey, databases, blacklist):
        config = lnt.server.config.Config('LNT', url, db_path, tmpdir,
                                          None, None, {'default': db_info},
                                          None)
        instance = lnt.server.instance.Instance(None, config)

        # Create the database.
        lnt.server.db.migrate.update_path(db_path)

        # Import the two reports.
        with contextlib.closing(config.get_database('default')) as db:
            import_and_report(
                config, 'default', db, report_a_path,
                '<auto>', commit=True)
            import_and_report(
                config, 'default', db, report_b_path,
                '<auto>', commit=True)

            # Dispatch another thread to start the webbrowser.
            comparison_url = '%s/v4/nts/2?compare_to=1' % (url,)
            note("opening comparison view: %s" % (comparison_url,))
            
            if not opts.dry_run:
                thread.start_new_thread(start_browser, (comparison_url, True))

            # Run the webserver.
            app = lnt.server.ui.app.App.create_with_instance(instance)
            app.debug = True
            
            if opts.dry_run:
                # Don't catch out exceptions.
                app.testing = True
                # Create a test client.
                client = app.test_client()
                response = client.get(comparison_url)
                assert response.status_code == 200, "Page did not return 200."
            else:
                app.run(opts.hostname, opts.port, use_reloader=False)
    finally:
        shutil.rmtree(tmpdir)
Exemple #5
0
def action_view_comparison(report_a, report_b, hostname, port, dry_run,
                           testsuite):
    """view a report comparison using a temporary server"""
    from .common import init_logger
    from lnt.util import logger
    from lnt.util.ImportData import import_and_report
    import contextlib
    import lnt.server.db.migrate
    import lnt.server.instance
    import lnt.server.ui.app
    import logging
    import os
    import shutil
    import sys
    import tempfile
    import thread
    import time
    import urllib
    import webbrowser

    init_logger(logging.ERROR)

    # Create a temporary directory to hold the instance.
    tmpdir = tempfile.mkdtemp(suffix='lnt')

    try:
        # Create a temporary instance.
        url = 'http://%s:%d' % (hostname, port)
        db_path = os.path.join(tmpdir, 'data.db')
        db_info = lnt.server.config.DBInfo(
            'sqlite:///%s' % (db_path, ), None,
            lnt.server.config.EmailConfig(False, '', '', []), "0")
        # _(self, name, zorgURL, dbDir, tempDir,
        # profileDir, secretKey, databases, blacklist):
        config = lnt.server.config.Config('LNT', url, db_path, tmpdir, None,
                                          "Not secret key.",
                                          {'default': db_info}, None, None)
        instance = lnt.server.instance.Instance(None, config)

        # Create the database.
        lnt.server.db.migrate.update_path(db_path)

        # Import the two reports.
        with contextlib.closing(config.get_database('default')) as db:
            session = db.make_session()
            r = import_and_report(config,
                                  'default',
                                  db,
                                  session,
                                  report_a,
                                  '<auto>',
                                  testsuite,
                                  select_machine='match')
            import_and_report(config,
                              'default',
                              db,
                              session,
                              report_b,
                              '<auto>',
                              testsuite,
                              select_machine='match')

            # Dispatch another thread to start the webbrowser.
            comparison_url = '%s/v4/nts/2?compare_to=1' % (url, )
            logger.info("opening comparison view: %s" % (comparison_url, ))

            if not dry_run:
                thread.start_new_thread(_start_browser, (comparison_url, True))

            # Run the webserver.
            app = lnt.server.ui.app.App.create_with_instance(instance)
            app.debug = True

            if dry_run:
                # Don't catch out exceptions.
                app.testing = True
                # Create a test client.
                client = app.test_client()
                response = client.get(comparison_url)
                assert response.status_code == 200, "Page did not return 200."
            else:
                app.run(hostname, port, use_reloader=False)
    finally:
        shutil.rmtree(tmpdir)
Exemple #6
0
def action_view_comparison(report_a, report_b, hostname, port, dry_run,
                           testsuite):
    """view a report comparison using a temporary server"""
    from .common import init_logger
    from lnt.util import logger
    from lnt.util.ImportData import import_and_report
    import contextlib
    import lnt.server.db.migrate
    import lnt.server.instance
    import lnt.server.ui.app
    import logging
    import os
    import shutil
    import tempfile
    import thread

    init_logger(logging.ERROR)

    # Create a temporary directory to hold the instance.
    tmpdir = tempfile.mkdtemp(suffix='lnt')

    try:
        # Create a temporary instance.
        url = 'http://%s:%d' % (hostname, port)
        db_path = os.path.join(tmpdir, 'data.db')
        db_info = lnt.server.config.DBInfo(
            'sqlite:///%s' % (db_path,), None,
            lnt.server.config.EmailConfig(False, '', '', []), "0")
        # _(self, name, zorgURL, dbDir, tempDir,
        # profileDir, secretKey, databases, blacklist):
        config = lnt.server.config.Config('LNT', url, db_path, tmpdir,
                                          None, "Not secret key.",
                                          {'default': db_info}, None,
                                          None)
        instance = lnt.server.instance.Instance(None, config)

        # Create the database.
        lnt.server.db.migrate.update_path(db_path)

        # Import the two reports.
        with contextlib.closing(config.get_database('default')) as db:
            session = db.make_session()
            import_and_report(config, 'default', db, session, report_a,
                                  '<auto>', testsuite, select_machine='match')
            import_and_report(config, 'default', db, session, report_b,
                              '<auto>', testsuite, select_machine='match')

            # Dispatch another thread to start the webbrowser.
            comparison_url = '%s/v4/nts/2?compare_to=1' % (url,)
            logger.info("opening comparison view: %s" % (comparison_url,))

            if not dry_run:
                thread.start_new_thread(_start_browser, (comparison_url, True))

            # Run the webserver.
            app = lnt.server.ui.app.App.create_with_instance(instance)
            app.debug = True

            if dry_run:
                # Don't catch out exceptions.
                app.testing = True
                # Create a test client.
                client = app.test_client()
                response = client.get(comparison_url)
                assert response.status_code == 200, "Page did not return 200."
            else:
                app.run(hostname, port, use_reloader=False)
    finally:
        shutil.rmtree(tmpdir)
Exemple #7
0
Fichier : main.py Projet : efcs/lnt
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", dest="profiler", default=False,
                      action="store_true", help="enable WSGI profiler")
    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.
    logger = logging.getLogger("lnt")
    if opts.debugger:
        logger.setLevel(logging.DEBUG)
    handler = logging.StreamHandler(sys.stderr)
    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.DEBUG)
        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:
        app.wsgi_app = werkzeug.contrib.profiler.ProfilerMiddleware(
            app.wsgi_app, stream = open('profiler.log', 'w'))
    app.run(opts.hostname, opts.port,
            use_reloader = opts.reloader,
            use_debugger = opts.debugger,
            threaded = opts.threaded,
            processes = opts.processes)
Exemple #8
0
def action_view_comparison(name, args):
    """view a report comparison using a temporary server"""

    import lnt.server.instance
    import lnt.server.ui.app
    import lnt.server.db.migrate

    parser = OptionParser("%s [options] <report A> <report B>" % (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)
    (opts, args) = parser.parse_args(args)

    if len(args) != 2:
        parser.error("invalid number of arguments")

    report_a_path,report_b_path = args

    # Set up the default logger.
    logger = logging.getLogger("lnt")
    logger.setLevel(logging.ERROR)
    handler = logging.StreamHandler(sys.stderr)
    handler.setFormatter(logging.Formatter(
            '%(asctime)s %(levelname)s: %(message)s',
            datefmt='%Y-%m-%d %H:%M:%S'))
    logger.addHandler(handler)

    # Create a temporary directory to hold the instance.
    tmpdir = tempfile.mkdtemp(suffix='lnt')

    try:
        # Create a temporary instance.
        url = 'http://%s:%d' % (opts.hostname, opts.port)
        db_path = os.path.join(tmpdir, 'data.db')
        db_info = lnt.server.config.DBInfo(
            'sqlite:///%s' % (db_path,), '0.4', None,
            lnt.server.config.EmailConfig(False, '', '', []), "0")
        config = lnt.server.config.Config(
            'LNT', url, db_path, tmpdir,
            None, { 'default' : db_info })
        instance = lnt.server.instance.Instance(None, config)

        # Create the database.
        lnt.server.db.migrate.update_path(db_path)

        # Import the two reports.
        with contextlib.closing(config.get_database('default')) as db:
            result = lnt.util.ImportData.import_and_report(
                config, 'default', db, report_a_path,
                '<auto>', commit=True)
            result = lnt.util.ImportData.import_and_report(
                config, 'default', db, report_b_path,
                '<auto>', commit=True)

            # Dispatch another thread to start the webbrowser.
            comparison_url = '%s/v4/nts/2?compare_to=1' % (url,)
            note("opening comparison view: %s" % (comparison_url,))
            thread.start_new_thread(start_browser, (comparison_url, True))

            # Run the webserver.
            app = lnt.server.ui.app.App.create_with_instance(instance)
            app.debug = True
            app.run(opts.hostname, opts.port, use_reloader=False)
    finally:
        shutil.rmtree(tmpdir)