[llvm-commits] [zorg] r151096 - in /zorg/trunk/lnt/lnt: lnttool/main.py lnttool/updatedb.py server/db/testsuitedb.py

Daniel Dunbar daniel at zuster.org
Tue Feb 21 14:25:44 PST 2012


Author: ddunbar
Date: Tue Feb 21 16:25:44 2012
New Revision: 151096

URL: http://llvm.org/viewvc/llvm-project?rev=151096&view=rev
Log:
[lnt] lnttool: Add an 'updatedb' command, which at the moment just provides an
easy way to delete machines and runs.
 - Should be part of the web app but haven't built any log in functionality yet.

Added:
    zorg/trunk/lnt/lnt/lnttool/updatedb.py
Modified:
    zorg/trunk/lnt/lnt/lnttool/main.py
    zorg/trunk/lnt/lnt/server/db/testsuitedb.py

Modified: zorg/trunk/lnt/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/lnttool/main.py?rev=151096&r1=151095&r2=151096&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/lnttool/main.py (original)
+++ zorg/trunk/lnt/lnt/lnttool/main.py Tue Feb 21 16:25:44 2012
@@ -60,6 +60,7 @@
 from convert import action_convert
 from import_data import action_import
 from report import action_report
+from updatedb import action_updatedb
 
 def action_checkformat(name, args):
     """check the format of an LNT test report file"""

Added: zorg/trunk/lnt/lnt/lnttool/updatedb.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/lnttool/updatedb.py?rev=151096&view=auto
==============================================================================
--- zorg/trunk/lnt/lnt/lnttool/updatedb.py (added)
+++ zorg/trunk/lnt/lnt/lnttool/updatedb.py Tue Feb 21 16:25:44 2012
@@ -0,0 +1,78 @@
+import os
+from optparse import OptionParser, OptionGroup
+
+import lnt.server.config
+from lnt.testing.util.commands import note, warning, error, fatal
+
+def action_updatedb(name, args):
+    """modify a database"""
+
+    from optparse import OptionParser, OptionGroup
+
+    parser = OptionParser("%%prog %s [options] <path|config-file> <file>+"%name)
+    parser.add_option("", "--database", dest="database", default="default",
+                      help="database to modify [%default]")
+    parser.add_option("", "--testsuite", dest="testsuite",
+                      help="testsuite to modify")
+    parser.add_option("", "--commit", dest="commit", type=int,
+                      default=False)
+    parser.add_option("", "--show-sql", dest="show_sql", action="store_true",
+                      default=False)
+    parser.add_option("", "--delete-machine", dest="delete_machines",
+                      action="append", default=[])
+    parser.add_option("", "--delete-run", dest="delete_runs",
+                      action="append", default=[], type=int)
+    (opts, args) = parser.parse_args(args)
+
+    if len(args) != 1:
+        parser.error("invalid number of arguments")
+
+    if opts.testsuite is None:
+        parser.error("--testsuite is required")
+        
+    config, = 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
+
+    # Load the config file.
+    config_data = {}
+    exec open(config) in config_data
+    config = lnt.server.config.Config.fromData(config, config_data)
+
+    # Get the database and test suite.
+    db = config.get_database(opts.database, echo=opts.show_sql)
+    ts = db.testsuite[opts.testsuite]
+
+    # Compute a list of all the runs to delete.
+    runs_to_delete = list(opts.delete_runs)
+    if opts.delete_machines:
+        runs_to_delete.extend(
+            id
+            for id, in ts.query(ts.Run.id).\
+                join(ts.Machine).\
+                filter(ts.Machine.name.in_(opts.delete_machines)))
+
+    # Delete all samples associated with those runs.
+    ts.query(ts.Sample).\
+        filter(ts.Sample.run_id.in_(runs_to_delete)).\
+        delete(synchronize_session=False)
+
+    # Delete all those runs.
+    ts.query(ts.Run).\
+        filter(ts.Run.id.in_(runs_to_delete)).\
+        delete(synchronize_session=False)
+
+    # Delete the machines.
+    for name in opts.delete_machines:
+        num_deletes = ts.query(ts.Machine).filter_by(name=name).delete()
+        if num_deletes == 0:
+            warning("unable to find machine named: %r" % name)
+
+    if opts.commit:
+        db.commit()
+    else:
+        db.rollback()

Modified: zorg/trunk/lnt/lnt/server/db/testsuitedb.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/server/db/testsuitedb.py?rev=151096&r1=151095&r2=151096&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/server/db/testsuitedb.py (original)
+++ zorg/trunk/lnt/lnt/server/db/testsuitedb.py Tue Feb 21 16:25:44 2012
@@ -319,6 +319,7 @@
         self.base.metadata.create_all(self.v4db.engine)
 
         # Add several shortcut aliases, similar to the ones on the v4db.
+        self.session = self.v4db.session
         self.add = self.v4db.add
         self.commit = self.v4db.commit
         self.query = self.v4db.query





More information about the llvm-commits mailing list