[llvm-commits] [LNT] r154404 - in /lnt/trunk: docs/tools.rst lnt/lnttool/import_data.py lnt/lnttool/main.py lnt/lnttool/updatedb.py lnt/server/config.py lnt/server/instance.py lnt/server/ui/app.py lnt/util/ServerUtil.py
Daniel Dunbar
daniel at zuster.org
Tue Apr 10 09:39:25 PDT 2012
Author: ddunbar
Date: Tue Apr 10 11:39:25 2012
New Revision: 154404
URL: http://llvm.org/viewvc/llvm-project?rev=154404&view=rev
Log:
Add lnt.server.instance.Instance class and unify all the different places that
were loading instance config files to load an Instance.
Added:
lnt/trunk/lnt/server/instance.py
Modified:
lnt/trunk/docs/tools.rst
lnt/trunk/lnt/lnttool/import_data.py
lnt/trunk/lnt/lnttool/main.py
lnt/trunk/lnt/lnttool/updatedb.py
lnt/trunk/lnt/server/config.py
lnt/trunk/lnt/server/ui/app.py
lnt/trunk/lnt/util/ServerUtil.py
Modified: lnt/trunk/docs/tools.rst
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/docs/tools.rst?rev=154404&r1=154403&r2=154404&view=diff
==============================================================================
--- lnt/trunk/docs/tools.rst (original)
+++ lnt/trunk/docs/tools.rst Tue Apr 10 11:39:25 2012
@@ -56,19 +56,26 @@
``lnt createdb <path>``
Creates a new LNT sqlite3 database at the specified path.
- ``lnt import <path | config file> <file>+``
+ ``lnt import <instance path> <file>+``
Import an LNT data file into a database. You can use ``--database`` to
select the database to write to. Note that by default this will also
generate report emails if enabled in the configuration, you can use
``--no-email`` to disable this.
- ``lnt runserver <path | config file | tarball>``
+ ``lnt runserver <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.
+ ``lnt updatedb --database <NAME> --testsuite <NAME> <instance path>``
+ Modify the given database and testsuite.
+
+ Currently the only supported commands are ``--delete-machine`` and
+ ``--delete-run``.
+
+All commands which take an instance path support passing in either the path to
+the ``lnt.cfg`` file, the path to the instance directory, or the path to a
+(compressed) tarball. The tarball will be automatically unpacked into a
+temporary directory and removed on exit. This is useful for testing and for
+passing database instances back and forth, for example when others only need to
+be able to view the results.
Modified: lnt/trunk/lnt/lnttool/import_data.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/import_data.py?rev=154404&r1=154403&r2=154404&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/import_data.py (original)
+++ lnt/trunk/lnt/lnttool/import_data.py Tue Apr 10 11:39:25 2012
@@ -5,13 +5,14 @@
import lnt.server.config
import lnt.server.db.v4db
import lnt.util.ImportData
+import lnt.server.instance
def action_import(name, args):
"""import test data into a database"""
from optparse import OptionParser, OptionGroup
- parser = OptionParser("%%prog %s [options] <path|config-file> <file>+"%name)
+ parser = OptionParser("%%prog %s [options] <instance path> <file>+"%name)
parser.add_option("", "--database", dest="database", default="default",
help="database to write to [%default]")
parser.add_option("", "--format", dest="format",
@@ -39,8 +40,9 @@
path = args.pop(0)
- # Load the LNT configuration.
- config = lnt.server.config.get_config_from_path(path)
+ # Load the LNT instance.
+ instance = lnt.server.instance.Instance.frompath(path)
+ config = instance.config
# Get the database.
db = config.get_database(opts.database, echo=opts.show_sql)
Modified: lnt/trunk/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/main.py?rev=154404&r1=154403&r2=154404&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/main.py (original)
+++ lnt/trunk/lnt/lnttool/main.py Tue Apr 10 11:39:25 2012
@@ -1,9 +1,7 @@
"""Implement the command line 'lnt' tool."""
import os
-import shutil
import sys
-import tarfile
import tempfile
from optparse import OptionParser, OptionGroup
@@ -18,7 +16,7 @@
"""start a new development server"""
parser = OptionParser("""\
-%%prog %s [options] [<path|config file|tarball>]
+%%prog %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
@@ -51,51 +49,15 @@
input_path, = args
- # Accept paths to config files, or to directories containing 'lnt.cfg'.
- tmpdir = None
- if os.path.isdir(input_path):
- config_path = os.path.join(input_path, 'lnt.cfg')
- elif tarfile.is_tarfile(input_path):
- # Accept paths to tar/tgz etc. files, which we automatically unpack into
- # a temporary directory.
- tmpdir = tempfile.mkdtemp(suffix='lnt')
-
- note("extracting input tarfile %r to %r" % (input_path, tmpdir))
- tf = tarfile.open(input_path)
- tf.extractall(tmpdir)
-
- # Find the LNT instance inside the tar file. Support tarballs that
- # either contain the instance directly, or contain a single subdirectory
- # which is the instance.
- if os.path.exists(os.path.join(tmpdir, "lnt.cfg")):
- config_path = os.path.join(tmpdir, "lnt.cfg")
- else:
- filenames = os.listdir(tmpdir)
- if len(filenames) != 1:
- fatal("unable to find LNT instance inside tarfile")
- config_path = os.path.join(tmpdir, filenames[0], "lnt.cfg")
- else:
- config_path = input_path
-
- if not config_path or not os.path.exists(config_path):
- raise SystemExit,"error: invalid config: %r" % config_path
-
import lnt.server.ui.app
- instance = lnt.server.ui.app.App.create_standalone(
- config_path = config_path)
+ app = lnt.server.ui.app.App.create_standalone(input_path,)
if opts.debugger:
- instance.debug = True
- try:
- instance.run(opts.hostname, opts.port,
- use_reloader = opts.reloader,
- use_debugger = opts.debugger,
- threaded = opts.threaded,
- processes = opts.processes)
- finally:
- # Clean up the tmpdir if we automatically unpacked a tarfile.
- if tmpdir is not None:
- print tmpdir
- shutil.rmtree(tmpdir)
+ app.debug = True
+ app.run(opts.hostname, opts.port,
+ use_reloader = opts.reloader,
+ use_debugger = opts.debugger,
+ threaded = opts.threaded,
+ processes = opts.processes)
from create import action_create
from convert import action_convert
Modified: lnt/trunk/lnt/lnttool/updatedb.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/updatedb.py?rev=154404&r1=154403&r2=154404&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/updatedb.py (original)
+++ lnt/trunk/lnt/lnttool/updatedb.py Tue Apr 10 11:39:25 2012
@@ -1,7 +1,7 @@
import os
from optparse import OptionParser, OptionGroup
-import lnt.server.config
+import lnt.server.instance
from lnt.testing.util.commands import note, warning, error, fatal
def action_updatedb(name, args):
@@ -9,7 +9,7 @@
from optparse import OptionParser, OptionGroup
- parser = OptionParser("%%prog %s [options] <path|config-file> <file>+"%name)
+ parser = OptionParser("%%prog %s [options] <instance> <file>+"%name)
parser.add_option("", "--database", dest="database", default="default",
help="database to modify [%default]")
parser.add_option("", "--testsuite", dest="testsuite",
@@ -30,21 +30,13 @@
if opts.testsuite is None:
parser.error("--testsuite is required")
- config, = args
+ path, = args
- # Accept paths to config files, or to directories containing 'lnt.cfg'.
- if os.path.isdir(config):
- tmp = os.path.join(config, 'lnt.cfg')
- if os.path.exists(tmp):
- config = tmp
-
- # Load the config file.
- config_data = {}
- exec open(config) in config_data
- config = lnt.server.config.Config.fromData(config, config_data)
+ # Load the instance.
+ instance = lnt.server.instance.Instance.frompath(path)
# Get the database and test suite.
- db = config.get_database(opts.database, echo=opts.show_sql)
+ db = instance.get_database(opts.database, echo=opts.show_sql)
ts = db.testsuite[opts.testsuite]
# Compute a list of all the runs to delete.
Modified: lnt/trunk/lnt/server/config.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/config.py?rev=154404&r1=154403&r2=154404&view=diff
==============================================================================
--- lnt/trunk/lnt/server/config.py (original)
+++ lnt/trunk/lnt/server/config.py Tue Apr 10 11:39:25 2012
@@ -125,16 +125,3 @@
raise NotImplementedError,"unable to import to version %r database" % (
db_entry.db_version,)
-
-def get_config_from_path(path):
- # Accept paths to config files or to directories containing 'lnt.cfg'.
- if os.path.isdir(path):
- config_path = os.path.join(path, 'lnt.cfg')
- else:
- config_path = path
-
- # Load the config file.
- config_data = {}
- exec open(config_path) in config_data
- return lnt.server.config.Config.fromData(config_path, config_data)
-
Added: lnt/trunk/lnt/server/instance.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/instance.py?rev=154404&view=auto
==============================================================================
--- lnt/trunk/lnt/server/instance.py (added)
+++ lnt/trunk/lnt/server/instance.py Tue Apr 10 11:39:25 2012
@@ -0,0 +1,73 @@
+import os
+import shutil
+import tarfile
+import tempfile
+
+import lnt.server.config
+
+from lnt.testing.util.commands import note, warning, error, fatal
+
+class Instance(object):
+ """
+ Wrapper object for representing an LNT instance.
+ """
+
+ @staticmethod
+ def frompath(path):
+ """
+ frompath(path) -> Insance
+
+ Load an LNT instance from the given instance specifier. The instance
+ path can be one of:
+ * The directory containing the instance.
+ * The instance config file.
+ * A tarball containing an instance.
+ """
+
+ # Accept paths to config files, or to directories containing 'lnt.cfg'.
+ tmpdir = None
+ if os.path.isdir(path):
+ config_path = os.path.join(path, 'lnt.cfg')
+ elif tarfile.is_tarfile(path):
+ # Accept paths to tar/tgz etc. files, which we automatically unpack
+ # into a temporary directory.
+ tmpdir = tempfile.mkdtemp(suffix='lnt')
+
+ note("extracting input tarfile %r to %r" % (path, tmpdir))
+ tf = tarfile.open(path)
+ tf.extractall(tmpdir)
+
+ # Find the LNT instance inside the tar file. Support tarballs that
+ # either contain the instance directly, or contain a single
+ # subdirectory which is the instance.
+ if os.path.exists(os.path.join(tmpdir, "lnt.cfg")):
+ config_path = os.path.join(tmpdir, "lnt.cfg")
+ else:
+ filenames = os.listdir(tmpdir)
+ if len(filenames) != 1:
+ fatal("unable to find LNT instance inside tarfile")
+ config_path = os.path.join(tmpdir, filenames[0], "lnt.cfg")
+ else:
+ config_path = path
+
+ if not config_path or not os.path.exists(config_path):
+ fatal("invalid config: %r" % config_path)
+
+ config_data = {}
+ exec open(config_path) in config_data
+ config = lnt.server.config.Config.fromData(config_path, config_data)
+
+ return Instance(config_path, config, tmpdir)
+
+ def __init__(self, config_path, config, tmpdir=None):
+ self.config_path = config_path
+ self.config = config
+ self.tmpdir = tmpdir
+
+ def __del__(self):
+ # If we have a temporary dir, clean it up now.
+ if self.tmpdir is not None:
+ shutil.rmtree(self.tmpdir)
+
+ def get_database(self, *args, **kwargs):
+ return self.config.get_database(*args, **kwargs)
Modified: lnt/trunk/lnt/server/ui/app.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/app.py?rev=154404&r1=154403&r2=154404&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/app.py (original)
+++ lnt/trunk/lnt/server/ui/app.py Tue Apr 10 11:39:25 2012
@@ -10,11 +10,11 @@
from flask import url_for
import lnt
-import lnt.server.config
+import lnt.server.db.v4db
+import lnt.server.instance
import lnt.server.ui.filters
import lnt.server.ui.globals
import lnt.server.ui.views
-import lnt.server.db.v4db
from lnt.db import perfdbsummary
from lnt.db import perfdb
@@ -109,11 +109,8 @@
self.wsgi_app = RootSlashPatchMiddleware(self.wsgi_app)
def load_config(self, config_path):
- config_data = {}
- exec open(config_path) in config_data
-
- self.old_config = lnt.server.config.Config.fromData(
- config_path, config_data)
+ self.instance = lnt.server.instance.Instance.frompath(config_path)
+ self.old_config = self.instance.config
self.jinja_env.globals.update(
app=current_app,
Modified: lnt/trunk/lnt/util/ServerUtil.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/ServerUtil.py?rev=154404&r1=154403&r2=154404&view=diff
==============================================================================
--- lnt/trunk/lnt/util/ServerUtil.py (original)
+++ lnt/trunk/lnt/util/ServerUtil.py Tue Apr 10 11:39:25 2012
@@ -7,7 +7,7 @@
import urllib
import urllib2
-import lnt.server.config
+import lnt.server.instance
from lnt.util import json
from lnt.util import ImportData
@@ -42,7 +42,8 @@
def submitFileToInstance(path, file, commit):
# Otherwise, assume it is a local url and submit to the default database
# in the instance.
- config = lnt.server.config.get_config_from_path(path)
+ instance = lnt.server.instance.Instance(path)
+ config = instance.config
db_name = 'default'
db = config.get_database(db_name)
if db is None:
More information about the llvm-commits
mailing list