[llvm-commits] [zorg] r99163 - in /zorg/trunk/lnt/lnt/lnttool: __init__.py create.py
Daniel Dunbar
daniel at zuster.org
Mon Mar 22 00:18:23 PDT 2010
Author: ddunbar
Date: Mon Mar 22 02:18:22 2010
New Revision: 99163
URL: http://llvm.org/viewvc/llvm-project?rev=99163&view=rev
Log:
'lnt': Factor out create tool, and move to OptionParser, its easier to document.
Added:
zorg/trunk/lnt/lnt/lnttool/create.py
- copied, changed from r99162, zorg/trunk/lnt/lnt/lnttool/__init__.py
Modified:
zorg/trunk/lnt/lnt/lnttool/__init__.py
Modified: zorg/trunk/lnt/lnt/lnttool/__init__.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/lnttool/__init__.py?rev=99163&r1=99162&r2=99163&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/lnttool/__init__.py (original)
+++ zorg/trunk/lnt/lnt/lnttool/__init__.py Mon Mar 22 02:18:22 2010
@@ -1,89 +1,33 @@
"""Implement the command line 'lnt' tool."""
-from werkzeug import script
-
-###
+import os
+import sys
-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
-
-# Temporary directory, for use by the web app. This must be writable by the user
-# the web app runs as.
-tmp_dir = %(tmp_dir)r
-
-# Database directory, for easily rerooting the entire set of database. Database
-# paths are resolved relative to the config path + this path.
-db_dir = %(db_dir)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)
-"""
+def action_runserver(name, args):
+ """start a new development server."""
-###
+ from optparse import OptionParser, OptionGroup
+ parser = OptionParser("%%prog %s [options] [<path|config file>]" % 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("", "--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")
-import os
-import platform
-from lnt.viewer import app
-
-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
+ config, = args
# Accept paths to config files, or to directories containing 'lnt.cfg'.
if os.path.isdir(config):
@@ -94,70 +38,32 @@
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',
- tmp_dir='lnt_tmp', db_dir='data', 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__)
-
- db_dir_path = os.path.join(basepath, db_dir)
- cfg_path = os.path.join(basepath, config)
- db_path = os.path.join(db_dir_path, default_db)
- tmp_path = os.path.join(basepath, tmp_dir)
- wsgi_path = os.path.join(basepath, wsgi)
-
- os.mkdir(path)
- os.mkdir(db_dir_path)
- os.mkdir(tmp_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 ' temporary dir : %s' % tmp_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. You may need to modify the permissions'
- print 'on the database and temporary file directory to allow writing'
- print 'by the web app.'
- print
+ from werkzeug import run_simple
+ from lnt.viewer import app
+ run_simple(opts.hostname, opts.port, app.create_app(opts.config),
+ opts.reloader, opts.debugger,
+ False, None, 1, opts.threaded, opts.processes)
+
+from create import action_create
+
+commands = dict((name[7:], f) for name,f in locals().items()
+ if name.startswith('action_'))
+
+def usage():
+ print >>sys.stderr, "Usage: %s command [options]" % (
+ os.path.basename(sys.argv[0]))
+ print >>sys.stderr
+ print >>sys.stderr, "Available commands:"
+ cmds_width = max(map(len, commands))
+ for name,func in sorted(commands.items()):
+ print >>sys.stderr, " %-*s - %s" % (cmds_width, name, func.__doc__)
+ sys.exit(1)
def main():
- script.run(globals())
+ import sys
+
+ if len(sys.argv) < 2 or sys.argv[1] not in commands:
+ usage()
-if __name__ == '__main__':
- main()
+ cmd = sys.argv[1]
+ commands[cmd](cmd, sys.argv[2:])
Copied: zorg/trunk/lnt/lnt/lnttool/create.py (from r99162, zorg/trunk/lnt/lnt/lnttool/__init__.py)
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/lnttool/create.py?p2=zorg/trunk/lnt/lnt/lnttool/create.py&p1=zorg/trunk/lnt/lnt/lnttool/__init__.py&r1=99162&r2=99163&rev=99163&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/lnttool/__init__.py (original)
+++ zorg/trunk/lnt/lnt/lnttool/create.py Mon Mar 22 02:18:22 2010
@@ -1,6 +1,5 @@
-"""Implement the command line 'lnt' tool."""
-
-from werkzeug import script
+import os
+import platform
###
@@ -17,9 +16,6 @@
# example.
name = %(name)r
-# Path to the LNT root.
-zorg = %(zorg_dir)r
-
# Path to the LNT server.
zorgURL = %(hosturl)r
@@ -75,36 +71,44 @@
###
-import os
-import platform
-from lnt.viewer import app
-
-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',
- tmp_dir='lnt_tmp', db_dir='data', default_db='lnt.db',
- hostname=platform.uname()[1], hostsuffix='perf'):
- """Create an LLVM nightly test installation"""
+def action_create(name, args):
+ """create an LLVM nightly test installation"""
- if not path:
- raise SystemExit,"error: invalid path: %r" % path
+ from optparse import OptionParser, OptionGroup
+ parser = OptionParser("%%prog %s [options] [<path|config file>]" % name)
+ parser.add_option("", "--name", dest="name", default="LNT",
+ help="name to use for the installation [%default]")
+ parser.add_option("", "--config", dest="config", default="lnt.cfg",
+ help="name of the LNT config file [%default]")
+ parser.add_option("", "--wsgi", dest="wsgi", default="lnt.wsgi",
+ help="name of the WSGI app [%default]")
+ parser.add_option("", "--tmp-dir", dest="tmp_dir", default="lnt_tmp",
+ help="name of the temp file directory [%default]")
+ parser.add_option("", "--db-dir", dest="db_dir", default="data",
+ help="name of the directory to hold databases")
+ parser.add_option("", "--default-db", dest="default_db", default="lnt.db",
+ help="name for the default db [%default]", metavar="NAME")
+ parser.add_option("", "--hostname", dest="hostname",
+ default=platform.uname()[1],
+ help="host name of the server [%default]", metavar="NAME")
+ parser.add_option("", "--hostsuffix", dest="hostsuffix", default="perf",
+ help="suffix at which WSGI app lives [%default]",
+ metavar="NAME")
+
+ (opts, args) = parser.parse_args(args)
+ if len(args) != 1:
+ parser.error("invalid number of arguments")
+
+ path, = args
+
+ name = opts.name
+ config = opts.config
+ wsgi = opts.wsgi
+ tmp_dir = opts.tmp_dir
+ db_dir = opts.db_dir
+ default_db = opts.default_db
+ hostname = opts.hostname
+ hostsuffix = opts.hostsuffix
basepath = os.path.abspath(path)
if os.path.exists(basepath):
@@ -112,10 +116,6 @@
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__)
-
db_dir_path = os.path.join(basepath, db_dir)
cfg_path = os.path.join(basepath, config)
db_path = os.path.join(db_dir_path, default_db)
@@ -155,9 +155,3 @@
print 'on the database and temporary file directory to allow writing'
print 'by the web app.'
print
-
-def main():
- script.run(globals())
-
-if __name__ == '__main__':
- main()
More information about the llvm-commits
mailing list