[llvm-commits] [zorg] r153974 - /zorg/trunk/lnt/lnt/lnttool/main.py

Daniel Dunbar daniel at zuster.org
Tue Apr 3 15:09:27 PDT 2012


Author: ddunbar
Date: Tue Apr  3 17:09:27 2012
New Revision: 153974

URL: http://llvm.org/viewvc/llvm-project?rev=153974&view=rev
Log:
[LNT] lnt runserver: Add support for running on tarballs directly, convenient
for passing results (or test cases for LNT failures) back and forth.

Modified:
    zorg/trunk/lnt/lnt/lnttool/main.py

Modified: zorg/trunk/lnt/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/lnttool/main.py?rev=153974&r1=153973&r2=153974&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/lnttool/main.py (original)
+++ zorg/trunk/lnt/lnt/lnttool/main.py Tue Apr  3 17:09:27 2012
@@ -1,7 +1,9 @@
 """Implement the command line 'lnt' tool."""
 
 import os
+import shutil
 import sys
+import tarfile
 import tempfile
 from optparse import OptionParser, OptionGroup
 
@@ -35,27 +37,53 @@
     if len(args) != 1:
         parser.error("invalid number of arguments")
 
-    config, = args
+    input_path, = args
 
     # 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
+    tmpdir = None
+    if os.path.isdir(input_path):
+        config_path = os.path.join(input_path, 'lnt.cfg')
+    elif tarfile.is_tarfile(input_path):
+        # Accept paths to tar/tgz etc. files, which we automatically unpack into
+        # a temporary directory.
+        tmpdir = tempfile.mkdtemp(suffix='lnt')
+        
+        note("extracting input tarfile %r to %r" % (input_path, tmpdir))
+        tf = tarfile.open(input_path)
+        tf.extractall(tmpdir)
+
+        # Find the LNT instance inside the tar file. Support tarballs that
+        # either contain the instance directly, or contain a single subdirectory
+        # which is the instance.
+        if os.path.exists(os.path.join(tmpdir, "lnt.cfg")):
+            config_path = os.path.join(tmpdir, "lnt.cfg")
+        else:
+            filenames = os.listdir(tmpdir)
+            if len(filenames) != 1:
+                fatal("unable to find LNT instance inside tarfile")
+            config_path = os.path.join(tmpdir, filenames[0], "lnt.cfg")
+    else:
+        config_path = input_path
 
-    if not config or not os.path.exists(config):
-        raise SystemExit,"error: invalid config: %r" % config
+    if not config_path or not os.path.exists(config_path):
+        raise SystemExit,"error: invalid config: %r" % config_path
 
     import lnt.server.ui.app
     instance = lnt.server.ui.app.App.create_standalone(
-        config_path = config)
+        config_path = config_path)
     if opts.debugger:
         instance.debug = True
-    instance.run(opts.hostname, opts.port,
-                 use_reloader = opts.reloader,
-                 use_debugger = opts.debugger,
-                 threaded = opts.threaded,
-                 processes = opts.processes)
+    try:
+        instance.run(opts.hostname, opts.port,
+                     use_reloader = opts.reloader,
+                     use_debugger = opts.debugger,
+                     threaded = opts.threaded,
+                     processes = opts.processes)
+    finally:
+        # Clean up the tmpdir if we automatically unpacked a tarfile.
+        if tmpdir is not None:
+            print tmpdir
+            shutil.rmtree(tmpdir)
 
 from create import action_create
 from convert import action_convert





More information about the llvm-commits mailing list