]> git.decadent.org.uk Git - dak.git/commitdiff
Merge remote branch 'mario/master' into merge
authorJoerg Jaspert <joerg@debian.org>
Sat, 27 Feb 2010 09:07:27 +0000 (10:07 +0100)
committerJoerg Jaspert <joerg@debian.org>
Sat, 27 Feb 2010 09:07:27 +0000 (10:07 +0100)
* mario/master:
  init_db.py: fix for `do_priority'
  init_db.py: `Cnf.get' fix for `do_priority'
  init_db.py: fixes for `do_suite'
  init_db.py: typo fix for `do_suite' comment.
  admin.py: added command to add suites

Signed-off-by: Joerg Jaspert <joerg@debian.org>
dak/admin.py
dak/init_db.py

index eb765a660cb00ac807e0daaee0305539eeaf3662..dbf1d45d5df1c097f499608d5a20826b22de89f4 100755 (executable)
@@ -67,6 +67,10 @@ Perform administrative work on the dak database.
   suite / s:
      s list                 show a list of suites
      s show SUITE           show config details for a suite
+     s add SUITE VERSION [ label=LABEL ] [ description=DESCRIPTION ]
+                         [ origin=ORIGIN ] [ codename=CODENAME ]
+                            add suite SUITE, version VERSION. label,
+                            description, origin and codename are optional.
 
   suite-architecture / s-a:
      s-a list-suite ARCH    show the suites an ARCH is in
@@ -170,6 +174,37 @@ def __suite_show(d, args):
 
     print su.details()
 
+def __suite_add(d, args):
+    die_arglen(args, 4, "E: adding a suite requires at least a name and a version")
+    suite_name = args[2].lower()
+    version = args[3]
+    rest = args[3:]
+
+    def get_field(field):
+        for varval in args:
+            if varval.startswith(field + '='):
+                return varval.split('=')[1]
+        return None
+
+    print "Adding suite %s" % suite_name
+    if not dryrun:
+        try:
+            s = d.session()
+            suite = Suite()
+            suite.suite_name = suite_name
+            suite.version = version
+            suite.label = get_field('label')
+            suite.description = get_field('description')
+            suite.origin = get_field('origin')
+            suite.codename = get_field('codename')
+            s.add(suite)
+            s.commit()
+        except IntegrityError, e:
+            die("E: Integrity error adding suite %s (it probably already exists)" % suite_name)
+        except SQLAlchemyError, e:
+            die("E: Error adding suite %s (%s)" % (suite_name, e))
+    print "Suite %s added" % (suite_name)
+
 def suite(command):
     args = [str(x) for x in command]
     Cnf = utils.get_conf()
@@ -183,6 +218,8 @@ def suite(command):
         __suite_list(d, args)
     elif mode == 'show':
         __suite_show(d, args)
+    elif mode == 'add':
+        __suite_add(d, args)
     else:
         die("E: suite command unknown")
 
index b0589b131b9f05ae8ed38c2ddeedaff7b06b12d9..169f30057cb1d91ff94881057926f8dc4a0dbcb9 100755 (executable)
@@ -127,13 +127,15 @@ class InitDB(object):
         s.commit()
 
     def do_suite(self):
-        """Initalize the suite table."""
+        """Initialize the suite table."""
 
         s = self.projectB.session()
         s.query(Suite).delete()
 
         for suite in self.Cnf.SubTree("Suite").List():
+            suite = suite.lower()
             su = Suite()
+            su.suite_name  = suite
             su.version     = self.Cnf.get("Suite::%s::Version" % suite, "-")
             su.origin      = self.Cnf.get("Suite::%s::Origin" % suite, "")
             su.description = self.Cnf.get("Suite::%s::Description" % suite, "")
@@ -141,11 +143,11 @@ class InitDB(object):
 
             for architecture in self.Cnf.ValueList("Suite::%s::Architectures" % (suite)):
                 sa = SuiteArchitecture()
-                sa.suite_id = su.suite_id
                 a = s.query(Architecture).filter_by(arch_string=architecture)
                 if a.count() < 1:
                     utils.fubar("E: Architecture %s not found for suite %s" % (architecture, suite))
                 sa.arch_id = a.one().arch_id
+                sa.suite_id = su.suite_id
                 s.add(sa)
 
         s.commit()
@@ -172,7 +174,7 @@ class InitDB(object):
         for priority in self.Cnf.SubTree("Priority").List():
             p = Priority()
             p.priority = priority
-            p.level    = self.Cnf.get("Priority::%s", 0)
+            p.level    = self.Cnf.get("Priority::" + priority, "0")
             s.add(p)
 
         s.commit()