[LNT] r188100 - [lnttool] Add a view-comparison command, for quickly viewing results.
Daniel Dunbar
daniel at zuster.org
Fri Aug 9 13:02:57 PDT 2013
Author: ddunbar
Date: Fri Aug 9 15:02:56 2013
New Revision: 188100
URL: http://llvm.org/viewvc/llvm-project?rev=188100&view=rev
Log:
[lnttool] Add a view-comparison command, for quickly viewing results.
- This command acts as a viewer for two raw report files, by spinning up a new
temporary LNT instance, importing the data, then opening a webbrowser to view
the result.
Added:
lnt/trunk/lnt/lnttool/viewcomparison.py
Modified:
lnt/trunk/lnt/lnttool/main.py
Modified: lnt/trunk/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/main.py?rev=188100&r1=188099&r2=188100&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/main.py (original)
+++ lnt/trunk/lnt/lnttool/main.py Fri Aug 9 15:02:56 2013
@@ -91,6 +91,7 @@ from create import action_create
from convert import action_convert
from import_data import action_import
from updatedb import action_updatedb
+from viewcomparison import action_view_comparison
def action_checkformat(name, args):
"""check the format of an LNT test report file"""
Added: lnt/trunk/lnt/lnttool/viewcomparison.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/viewcomparison.py?rev=188100&view=auto
==============================================================================
--- lnt/trunk/lnt/lnttool/viewcomparison.py (added)
+++ lnt/trunk/lnt/lnttool/viewcomparison.py Fri Aug 9 15:02:56 2013
@@ -0,0 +1,107 @@
+import logging
+import os
+import shutil
+import sys
+import tempfile
+import thread
+import time
+import urllib
+import webbrowser
+from optparse import OptionParser, OptionGroup
+
+import lnt.util.ImportData
+from lnt.testing.util.commands import note, warning, error, fatal
+
+def start_browser(url, debug=False):
+ def url_is_up(url):
+ try:
+ o = urllib.urlopen(url)
+ except IOError:
+ return False
+ o.close()
+ return True
+
+ # Wait for server to start...
+ if debug:
+ note('waiting for server to start...')
+ for i in range(10000):
+ if url_is_up(url):
+ break
+ if debug:
+ sys.stderr.write('.')
+ sys.stderr.flush()
+ time.sleep(.01)
+ else:
+ warning('unable to detect that server started')
+
+ if debug:
+ note('opening webbrowser...')
+ webbrowser.open(url)
+
+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, '', '', []))
+ config = lnt.server.config.Config(
+ 'LNT', url, db_path, tmpdir,
+ None, { 'default' : db_info }, 1)
+ instance = lnt.server.instance.Instance(None, config)
+
+ # Create the database.
+ lnt.server.db.migrate.update_path(db_path)
+
+ # Import the two reports.
+ db = config.get_database('default')
+ 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)
More information about the llvm-commits
mailing list