[llvm-commits] [zorg] r152853 - in /zorg/trunk/lnt/lnt: lnttool/main.py util/ServerUtil.py
Daniel Dunbar
daniel at zuster.org
Thu Mar 15 14:41:35 PDT 2012
Author: ddunbar
Date: Thu Mar 15 16:41:35 2012
New Revision: 152853
URL: http://llvm.org/viewvc/llvm-project?rev=152853&view=rev
Log:
[LNT] Add support to 'lnt runtest --submit' to submit to a local instance.
Modified:
zorg/trunk/lnt/lnt/lnttool/main.py
zorg/trunk/lnt/lnt/util/ServerUtil.py
Modified: zorg/trunk/lnt/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/lnttool/main.py?rev=152853&r1=152852&r2=152853&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/lnttool/main.py (original)
+++ zorg/trunk/lnt/lnt/lnttool/main.py Thu Mar 15 16:41:35 2012
@@ -2,6 +2,7 @@
import os
import sys
+import tempfile
from optparse import OptionParser, OptionGroup
import StringIO
@@ -90,9 +91,9 @@
parser = OptionParser("%%prog %s test-name [options]" % name)
parser.disable_interspersed_args()
- parser.add_option("", "--submit", dest="submit_url", metavar="URL",
+ parser.add_option("", "--submit", dest="submit_url", metavar="URLORPATH",
help=("autosubmit the test result to the given server "
- "[%default]"),
+ "(or local instance) [%default]"),
type=str, default=None)
parser.add_option("", "--commit", dest="commit",
help=("whether the autosubmit result should be committed "
@@ -128,21 +129,24 @@
if output_stream is not sys.stdout:
output_stream.close()
+ # Save the report to a temporary file.
+ #
+ # FIXME: This is silly, the underlying test probably wrote the report to a
+ # file itself. We need to clean this up and make it standard across all
+ # tests. That also has the nice side effect that writing into a local
+ # database records the correct imported_from path.
+ tmp = tempfile.NamedTemporaryFile(suffix='.json')
+ print >>tmp, report.render()
+ tmp.flush()
+
if opts.submit_url is not None:
if report is None:
raise SystemExit,"error: report generation failed"
from lnt.util import ServerUtil
- io = StringIO.StringIO(report.render(indent=None))
- ServerUtil.submitFile(opts.submit_url, io, True, opts.verbose)
+ ServerUtil.submitFile(opts.submit_url, tmp.name, True, opts.verbose)
else:
# Simulate a submission to retrieve the results report.
- import tempfile
-
- # Save the report to a temporary file.
- tmp = tempfile.NamedTemporaryFile(suffix='.json')
- print >>tmp, report.render()
- tmp.flush()
# Construct a temporary database and import the result.
db = lnt.server.db.v4db.V4DB("sqlite:///:memory:")
@@ -151,7 +155,7 @@
lnt.util.ImportData.print_report_result(result, sys.stdout, sys.stderr,
opts.verbose)
- tmp.close()
+ tmp.close()
def action_showtests(name, args):
"""show the available built-in tests"""
Modified: zorg/trunk/lnt/lnt/util/ServerUtil.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/util/ServerUtil.py?rev=152853&r1=152852&r2=152853&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/util/ServerUtil.py (original)
+++ zorg/trunk/lnt/lnt/util/ServerUtil.py Thu Mar 15 16:41:35 2012
@@ -7,6 +7,7 @@
import urllib
import urllib2
+import lnt.server.config
from lnt.util import json
from lnt.util import ImportData
@@ -15,9 +16,10 @@
# system to report to LNT, for example. It might be nice to factor the
# simplified submit code into a separate utility.
-def submitFile(url, file, commit, verbose):
- values = { 'input_data' : file.read(),
- 'commit' : ("0","1")[not not commit] }
+def submitFileToServer(url, file, commit):
+ with open(file, 'rb') as f:
+ values = { 'input_data' : f.read(),
+ 'commit' : ("0","1")[not not commit] }
data = urllib.urlencode(values)
response = urllib2.urlopen(urllib2.Request(url, data))
@@ -37,11 +39,29 @@
print result
return
+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)
+ db_name = 'default'
+ db = config.get_database(db_name)
+ if db is None:
+ raise ValueError("no default database in instance: %r" % (path,))
+ return lnt.util.ImportData.import_and_report(
+ config, db_name, db, file, format='<auto>', commit=commit)
+
+def submitFile(url, file, commit, verbose):
+ # If this is a real url, submit it using urllib.
+ if '://' in url:
+ result = submitFileToServer(url, file, commit)
+ if result is None:
+ return
+ else:
+ result = submitFileToInstance(url, file, commit)
+
# Print the test report.
ImportData.print_report_result(result, sys.stdout, sys.stderr, verbose)
def submitFiles(url, files, commit, verbose):
for file in files:
- f = open(file, 'rb')
- submitFile(url, f, commit, verbose)
- f.close()
+ submitFile(url, file, commit, verbose)
More information about the llvm-commits
mailing list