[llvm-commits] [zorg] r99119 - in /zorg/trunk/lnt: README.txt lnt/lnttool/__init__.py lnt/viewer/PerfDB.py lnt/viewer/app.py lnt/viewer/root.ptl lnt/viewer/zorg.cfg.sample

Daniel Dunbar daniel at zuster.org
Sun Mar 21 04:37:37 PDT 2010


Author: ddunbar
Date: Sun Mar 21 06:37:37 2010
New Revision: 99119

URL: http://llvm.org/viewvc/llvm-project?rev=99119&view=rev
Log:
LNT: Add support for 'lnt create path/to/install' to create a new LNT installation, and fix a few related bugs.

Removed:
    zorg/trunk/lnt/lnt/viewer/zorg.cfg.sample
Modified:
    zorg/trunk/lnt/README.txt
    zorg/trunk/lnt/lnt/lnttool/__init__.py
    zorg/trunk/lnt/lnt/viewer/PerfDB.py
    zorg/trunk/lnt/lnt/viewer/app.py
    zorg/trunk/lnt/lnt/viewer/root.ptl

Modified: zorg/trunk/lnt/README.txt
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/README.txt?rev=99119&r1=99118&r2=99119&view=diff
==============================================================================
--- zorg/trunk/lnt/README.txt (original)
+++ zorg/trunk/lnt/README.txt Sun Mar 21 06:37:37 2010
@@ -35,14 +35,22 @@
 
 These are the rough steps to get a working LNT installation:
 
- 1. Install external dependencies. FIXME: Elaborate.
+ 1. Install LNT:
 
- 2. Choose a data directory and create the initial SQLite or MySQL
-    databases. SQLite databases need to be writable by the Apache user, as does
-    the directory they are contained in.
+      python setup.py install
 
- 3. Copy viewer/zorg.cfg.sample to viewer/zorg.cfg, and modify for your
-    installation.
+    It is recommended that you install LNT into a virtualenv.
+
+ 2. Create a new LNT installation:
+
+      lnt create path/to/install-dir
+
+    This will create the LNT configuration file, the default database, and a
+    .wsgi wrapper to create the application. You can execute the generated app
+    directly to run with the builtin web server, or use 'lnt runserver' with the
+    path the config file.
+
+ 3. Edit the generated 'lnt.cfg' file if necessary, for example to:
 
     a. Update the databases list.
 
@@ -52,7 +60,8 @@
 
  4. Add the zorg.wsgi app to your Apache configuration. You should set also
     configure the WSGIDaemonProcess and WSGIProcessGroup variables if not
-    already done.
+    already done. If running in a virtualenv you will need to configure that as
+    well.
 
  5. Add a link or copy of the zorg.cgi app in the appropriate place if you want
     to use the CGI script. The WSGI app is significantly faster, but currently

Modified: zorg/trunk/lnt/lnt/lnttool/__init__.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/lnttool/__init__.py?rev=99119&r1=99118&r2=99119&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/lnttool/__init__.py (original)
+++ zorg/trunk/lnt/lnt/lnttool/__init__.py Sun Mar 21 06:37:37 2010
@@ -2,9 +2,144 @@
 
 from werkzeug import script
 
+###
+
+kConfigVersion = (0,1,0)
+kConfigTemplate = """\
+# LNT (aka Zorg) configuration file
+#
+# Paths are resolved relative to this file.
+
+# The configuration file version.
+config_version = %(cfg_version)r
+
+# Name to use for this installation. This appears in web page headers, for
+# example.
+name = %(name)r
+
+# Path to the LNT root.
+zorg = %(zorg_dir)r
+
+# Path to the LNT server.
+zorgURL = %(hosturl)r
+
+# The list of available databases, and their properties. At a minimum, there
+# should be a 'default' entry for the default database.
+databases = {
+    'default' : { 'path' : %(default_db)r,
+                  'showNightlytest' : 1 },
+    }
+
+# The LNT email configuration.
+#
+# The 'to' field can be either a single email address, or a list of
+# (regular-expression, address) pairs. In the latter form, the machine name of
+# the submitted results is matched against the regular expressions to determine
+# which email address to use for the results.
+nt_emailer = {
+    'enabled' : False,
+    'host' : None,
+    'from' : None,
+
+    # This is a list of (filter-regexp, address) pairs -- it is evaluated in
+    # order based on the machine name. This can be used to dispatch different
+    # reports to different email address.
+    'to' : [(".*", None)],
+    }
+
+# Enable automatic restart using the wsgi_restart module; this should be off in
+# a production environment.
+wsgi_restart = False
+"""
+
+kWSGITemplate = """\
+#!/usr/bin/env python2.6
+# -*- Python -*-
+
+from lnt.viewer import app
+
+application = app.create_app(%(cfg_path)r)
+
+if __name__ == "__main__":
+    import werkzeug
+    werkzeug.run_simple('localhost', 8000, application)
+"""
+
+###
+
+import os
+import platform
 from lnt.viewer import app
 
-action_runserver = script.make_runserver(app.create_app, use_reloader=True)
+def action_runserver(config='', hostname=('h','localhost'), port=('p',8000),
+                     reloader=False, debugger=False, evalex=False,
+                     threaded=False, processes=1):
+    """Start a new development server."""
+    from werkzeug import run_simple
+
+    # 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
+
+    if not config or not os.path.exists(config):
+        raise SystemExit,"error: invalid config: %r" % config
+
+    run_simple(hostname, port, app.create_app(config), reloader, debugger,
+               evalex, None, 1, threaded, processes)
+
+
+def action_create(path='', name='LNT', config='lnt.cfg', wsgi='lnt.wsgi',
+                  default_db='lnt.db',
+                  hostname=platform.uname()[1], hostsuffix='perf'):
+    """Create an LLVM nightly test installation"""
+
+    if not path:
+        raise SystemExit,"error: invalid path: %r" % path
+
+    basepath = os.path.abspath(path)
+    if os.path.exists(basepath):
+        raise SystemExit,"error: invalid path: %r already exists" % path
+
+    hosturl = "http://%s/%s" % (hostname, hostsuffix)
+
+    # FIXME: Eliminate this variable and just require that LNT be installed.
+    import lnt
+    zorg_dir = os.path.dirname(lnt.__file__)
+
+    cfg_path = os.path.join(basepath, config)
+    db_path = os.path.join(basepath, default_db)
+    wsgi_path = os.path.join(basepath, wsgi)
+
+    os.mkdir(path)
+
+    cfg_version = kConfigVersion
+    cfg_file = open(cfg_path, 'w')
+    cfg_file.write(kConfigTemplate % locals())
+    cfg_file.close()
+
+    wsgi_file = open(wsgi_path, 'w')
+    wsgi_file.write(kWSGITemplate % locals())
+    wsgi_file.close()
+
+    from lnt.viewer import PerfDB
+    db = PerfDB.PerfDB('sqlite:///' + db_path)
+    db.commit()
+
+    print 'created LNT configuration in %r' % basepath
+    print '  configuration file: %s' % cfg_path
+    print '  WSGI app          : %s' % wsgi_path
+    print '  database file     : %s' % db_path
+    print '  host URL          : %s' % hosturl
+    print
+    print 'You can execute:'
+    print '  python %s' % wsgi_path
+    print 'to test your installation with the builtin server.'
+    print
+    print 'For production use configure this application to run with any'
+    print 'WSGI capable web server.'
+    print
 
 def main():
     script.run(globals())

Modified: zorg/trunk/lnt/lnt/viewer/PerfDB.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/viewer/PerfDB.py?rev=99119&r1=99118&r2=99119&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/viewer/PerfDB.py (original)
+++ zorg/trunk/lnt/lnt/viewer/PerfDB.py Sun Mar 21 06:37:37 2010
@@ -152,11 +152,15 @@
 
 class PerfDB:
     def __init__(self, path, echo=False):
-        if not path.startswith('mysql://'):
+        if (not path.startswith('mysql://') and
+            not path.startswith('sqlite://')):
             path = 'sqlite:///' + path
         self.engine = sqlalchemy.create_engine(path, echo=echo)
-        Session = sqlalchemy.orm.sessionmaker(self.engine)
-        self.session = Session()
+
+        # Create the tables in case this is a new database.
+        Base.metadata.create_all(self.engine)
+
+        self.session = sqlalchemy.orm.sessionmaker(self.engine)()
 
     def machines(self, name=None):
         q = self.session.query(Machine)

Modified: zorg/trunk/lnt/lnt/viewer/app.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/viewer/app.py?rev=99119&r1=99118&r2=99119&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/viewer/app.py (original)
+++ zorg/trunk/lnt/lnt/viewer/app.py Sun Mar 21 06:37:37 2010
@@ -1,14 +1,18 @@
 import os
 import sys
 
-def create_publisher():
+def create_publisher(configPath=None):
     import warnings
     warnings.simplefilter("ignore", category=DeprecationWarning)
 
-    # We expect the config file to be adjacent to the absolute path of
-    # the cgi script.
-    configPath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
-                              "zorg.cfg")
+    if configPath is None:
+        # We expect the config file to be adjacent to the absolute path of
+        # the cgi script.
+        #
+        # FIXME: This behavior is deprecated and should be removed.
+        configPath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+                                  "zorg.cfg")
+
     configData = {}
     exec open(configPath) in configData
 
@@ -19,7 +23,7 @@
         sys.path.append(zorgDir)
 
     # Optionally enable auto-restart.
-    if configData.get('wsgiAutoRestart', 'True'):
+    if configData.get('wsgi_restart', False):
         from viewer import wsgi_restart
         wsgi_restart.track(configPath)
         wsgi_restart.start()
@@ -27,6 +31,6 @@
     from viewer import publisher
     return publisher.create_publisher(configPath, configData, threaded=True)
 
-def create_app():
+def create_app(cfg_path=None):
     import quixote.wsgi
-    return quixote.wsgi.QWIP(create_publisher())
+    return quixote.wsgi.QWIP(create_publisher(cfg_path))

Modified: zorg/trunk/lnt/lnt/viewer/root.ptl
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/viewer/root.ptl?rev=99119&r1=99118&r2=99119&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/viewer/root.ptl (original)
+++ zorg/trunk/lnt/lnt/viewer/root.ptl Sun Mar 21 06:37:37 2010
@@ -30,7 +30,6 @@
         if self.dbInfo is None:
             self.dbInfo = config.databases[dbName]
         self.pathToRoot = pathToRoot
-        self.db_log = None
 
     def getDB(self):
         db = PerfDB.PerfDB(self.dbInfo.path)
@@ -39,12 +38,12 @@
         #
         # FIXME: Conditionalize on an is_production variable.
         request = quixote.get_request()
-        if self.db_log is None and request.form.get('db_log'):
+        if request.form.get('db_log'):
             import logging, StringIO
-            self.db_log = StringIO.StringIO()
+            request.db_log = StringIO.StringIO()
             logger = logging.getLogger("sqlalchemy")
-            logger.addHandler(logging.StreamHandler(self.db_log))
-            db.db2.engine.echo = True
+            logger.addHandler(logging.StreamHandler(request.db_log))
+            db.engine.echo = True
 
         return db
 
@@ -133,8 +132,9 @@
         """
 
     def getFooter [html] (self):
-        if self.db_log:
-            """<hr><h3>SQL Log</h3><pre>%s</pre>""" % self.db_log.getvalue()
+        db_log = getattr(quixote.get_request(), str('db_log'), None)
+        if db_log:
+            """<hr><h3>SQL Log</h3><pre>%s</pre>""" % db_log.getvalue()
 
         current = time.time()
         """

Removed: zorg/trunk/lnt/lnt/viewer/zorg.cfg.sample
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/viewer/zorg.cfg.sample?rev=99118&view=auto
==============================================================================
--- zorg/trunk/lnt/lnt/viewer/zorg.cfg.sample (original)
+++ zorg/trunk/lnt/lnt/viewer/zorg.cfg.sample (removed)
@@ -1,46 +0,0 @@
-# -*- Python -*-
-
-# LNT (aka Zorg) configuration file
-#
-# Paths are resolved relative to this file.
-
-# Path to the LNT root.
-zorg = ".."
-
-# Path to the LNT server.
-zorgURL = "http://llvm.org/perf/"
-
-# The list of available databases, and their properties. At a minimum, there
-# should be a 'default' entry for the default database.
-databases = {
-    'default' : { 'path' : '../data/default.db',
-                  'showNightlytest' : 1 },
-    'test' : { 'path' : '../data/test.db',
-               'showNightlytest' : 1,
-               'showGeneral' : 1 },
-    'nt' : { 'path' : '../data/nt_internal.db',
-             'showNightlytest' : 1 },
-    'nt_mysql' : { 'path' : 'mysql://root:admin@localhost/nt_internal',
-                   'showNightlytest' : 1 },
-    }
-
-# The LNT email configuration.
-#
-# The 'to' field can be either a single email address, or a list of
-# (regular-expression, address) pairs. In the latter form, the machine name of
-# the submitted results is matched against the regular expressions to determine
-# which email address to use for the results.
-nt_emailer = {
-    'enabled' : False,
-    'host' : "llvm.org",
-    'from' : "lnt at llvm.org",
-
-    # This is a list of (filter-regexp, address) pairs -- it is evaluated in
-    # order based on the machine name. This can be used to dispatch different
-    # reports to different email address.
-    'to' : [(".*", "llvm-testresults at cs.uiuc.edu")],
-    }
-
-# Enable automatic restart using the wsgi_restart module; this should be off in
-# a production environment.
-wsgi_restart = False





More information about the llvm-commits mailing list