Skip to content

Commit

Permalink
[lnttool] Add a view-comparison command, for quickly viewing results.
Browse files Browse the repository at this point in the history
 - 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.

git-svn-id: https://llvm.org/svn/llvm-project/lnt/trunk@188100 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ddunbar committed Aug 9, 2013
1 parent 66c57d4 commit 4e29f4a
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions lnt/lnttool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def action_runserver(name, args):
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"""
Expand Down
107 changes: 107 additions & 0 deletions lnt/lnttool/viewcomparison.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 4e29f4a

Please sign in to comment.