]> git.decadent.org.uk Git - dak.git/blobdiff - dak/admin.py
Add archive rename command
[dak.git] / dak / admin.py
index 5f0dcc9eeda8848c22ddb4b5536bd7bd647900e7..0de7cd69751ea92336fcb780b6b3dec00f8b37ea 100755 (executable)
@@ -96,11 +96,20 @@ Perform administrative work on the dak database.
      s-a rm SUITE ARCH      remove ARCH from suite (will only work if
                             no packages remain for the arch in the suite)
 
+  archive:
+     archive list           list all archives
+     archive add NAME ROOT DESCRIPTION [primary-mirror=MIRROR] [tainted=1]
+                            add archive NAME with path ROOT,
+                            primary mirror MIRROR.
+     archive rm NAME        remove archive NAME (will only work if there are
+                            no files and no suites in the archive)
+     archive rename OLD NEW rename archive OLD to NEW
+
   version-check / v-c:
      v-c list                        show version checks for all suites
      v-c list-suite SUITE            show version checks for suite SUITE
      v-c add SUITE CHECK REFERENCE   add a version check for suite SUITE
-     v-c rm SUITE CHECK REFERENCE    rmove a version check
+     v-c rm SUITE CHECK REFERENCE    remove a version check
        where
          CHECK     is one of Enhances, MustBeNewerThan, MustBeOlderThan
         REFERENCE is another suite name
@@ -110,7 +119,7 @@ Perform administrative work on the dak database.
 ################################################################################
 
 def __architecture_list(d, args):
-    q = d.session().query(Architecture).order_by('arch_string')
+    q = d.session().query(Architecture).order_by(Architecture.arch_string)
     for j in q.all():
         # HACK: We should get rid of source from the arch table
         if j.arch_string == 'source': continue
@@ -137,9 +146,9 @@ def __architecture_add(d, args):
                 else:
                     warn("W: Cannot find suite %s" % su)
             s.commit()
-        except IntegrityError, e:
+        except IntegrityError as e:
             die("E: Integrity error adding architecture %s (it probably already exists)" % args[2])
-        except SQLAlchemyError, e:
+        except SQLAlchemyError as e:
             die("E: Error adding architecture %s (%s)" % (args[2], e))
     print "Architecture %s added" % (args[2])
 
@@ -154,9 +163,9 @@ def __architecture_rm(d, args):
                 die("E: Cannot find architecture %s" % args[2])
             s.delete(a)
             s.commit()
-        except IntegrityError, e:
+        except IntegrityError as e:
             die("E: Integrity error removing architecture %s (suite-arch entries probably still exist)" % args[2])
-        except SQLAlchemyError, e:
+        except SQLAlchemyError as e:
             die("E: Error removing architecture %s (%s)" % (args[2], e))
     print "Architecture %s removed" % args[2]
 
@@ -184,7 +193,7 @@ dispatch['a'] = architecture
 
 def __suite_list(d, args):
     s = d.session()
-    for j in s.query(Suite).order_by('suite_name').all():
+    for j in s.query(Suite).order_by(Suite.suite_name).all():
         print j.suite_name
 
 def __suite_show(d, args):
@@ -216,6 +225,7 @@ def __suite_add(d, args, addallarches=False):
             s = d.session()
             suite = Suite()
             suite.suite_name = suite_name
+            suite.overridecodename = suite_name
             suite.version = version
             suite.label = get_field('label')
             suite.description = get_field('description')
@@ -224,23 +234,23 @@ def __suite_add(d, args, addallarches=False):
             signingkey = get_field('signingkey')
             if signingkey is not None:
                 suite.signingkeys = [signingkey.upper()]
+            archive_name = get_field('archive')
+            if archive_name is not None:
+                suite.archive = get_archive(archive_name, s)
+            else:
+                suite.archive = s.query(Archive).filter(~Archive.archive_name.in_(['build-queues', 'new', 'policy'])).one()
+            suite.srcformats = s.query(SrcFormat).all()
             s.add(suite)
             s.flush()
-            for sf in s.query(SrcFormat).all():
-                ssf = SuiteSrcFormat()
-                ssf.suite = suite
-                ssf.src_format = sf
-                s.add(ssf)
-                s.flush()
-        except IntegrityError, e:
+        except IntegrityError as e:
             die("E: Integrity error adding suite %s (it probably already exists)" % suite_name)
-        except SQLAlchemyError, e:
+        except SQLAlchemyError as e:
             die("E: Error adding suite %s (%s)" % (suite_name, e))
     print "Suite %s added" % (suite_name)
 
     if addallarches:
         arches = []
-        q = s.query(Architecture).order_by('arch_string')
+        q = s.query(Architecture).order_by(Architecture.arch_string)
         for arch in q.all():
             suite.architectures.append(arch)
             arches.append(arch.arch_string)
@@ -277,7 +287,7 @@ dispatch['s'] = suite
 
 def __suite_architecture_list(d, args):
     s = d.session()
-    for j in s.query(Suite).order_by('suite_name'):
+    for j in s.query(Suite).order_by(Suite.suite_name):
         architectures = j.get_architectures(skipsrc = True, skipall = True)
         print j.suite_name + ': ' + \
               ', '.join([a.arch_string for a in architectures])
@@ -317,9 +327,9 @@ def __suite_architecture_add(d, args):
         try:
             suite.architectures.append(arch)
             s.commit()
-        except IntegrityError, e:
+        except IntegrityError as e:
             die("E: Can't add suite-architecture entry (%s, %s) - probably already exists" % (args[2].lower(), args[3].lower()))
-        except SQLAlchemyError, e:
+        except SQLAlchemyError as e:
             die("E: Can't add suite-architecture entry (%s, %s) - %s" % (args[2].lower(), args[3].lower(), e))
 
     print "Added suite-architecture entry for %s, %s" % (args[2].lower(), args[3].lower())
@@ -342,9 +352,9 @@ def __suite_architecture_rm(d, args):
                 die("E: architecture %s not found in suite %s" % (arch_string, suite_name))
             suite.architectures.remove(architecture)
             s.commit()
-        except IntegrityError, e:
+        except IntegrityError as e:
             die("E: Can't remove suite-architecture entry (%s, %s) - it's probably referenced" % (args[2].lower(), args[3].lower()))
-        except SQLAlchemyError, e:
+        except SQLAlchemyError as e:
             die("E: Can't remove suite-architecture entry (%s, %s) - %s" % (args[2].lower(), args[3].lower(), e))
 
     print "Removed suite-architecture entry for %s, %s" % (args[2].lower(), args[3].lower())
@@ -377,9 +387,80 @@ dispatch['s-a'] = suite_architecture
 
 ################################################################################
 
+def archive_list():
+    session = DBConn().session()
+    for archive in session.query(Archive).order_by(Archive.archive_name):
+        print "{0} path={1} description={2} tainted={3}".format(archive.archive_name, archive.path, archive.description, archive.tainted)
+
+def archive_add(args):
+    (name, path, description) = args[0:3]
+
+    attributes = dict(
+        archive_name=name,
+        path=path,
+        description=description,
+        )
+
+    for option in args[3:]:
+        (key, value) = option.split('=')
+        attributes[key] = value
+
+    session = DBConn().session()
+
+    archive = Archive()
+    for key, value in attributes.iteritems():
+        setattr(archive, key, value)
+
+    session.add(archive)
+    session.flush()
+
+    if dryrun:
+        session.rollback()
+    else:
+        session.commit()
+
+def archive_rm(name):
+    session = DBConn().session()
+    archive = session.query(Archive).filter_by(archive_name=name).one()
+    session.delete(archive)
+    session.flush()
+
+    if dryrun:
+        session.rollback()
+    else:
+        session.commit()
+
+def archive_rename(oldname, newname):
+    session = DBConn().session()
+    archive = get_archive(oldname, session)
+    archive.archive_name = newname
+    session.flush()
+
+    if dryrun:
+        session.rollback()
+    else:
+        session.commit()
+
+def archive(command):
+    mode = command[1]
+    if mode == 'list':
+        archive_list()
+    elif mode == 'rename':
+        archive_rename(command[2], command[3])
+    elif mode == 'add':
+        archive_add(command[2:])
+    elif mode == 'rm':
+        archive_rm(command[2])
+    else:
+        die("E: archive command unknown")
+
+dispatch['archive'] = archive
+
+################################################################################
+
 def __version_check_list(d):
     session = d.session()
-    for s in session.query(Suite).order_by('suite_name'):
+    for s in session.query(Suite).order_by(Suite.suite_name):
         __version_check_list_suite(d, s.suite_name)
 
 def __version_check_list_suite(d, suite_name):
@@ -489,6 +570,8 @@ def show_config(command):
             print "PGPORT=%s" % cnf["DB::Port"]
             e.append('PGPORT')
         print "export " + " ".join(e)
+    elif mode == 'get':
+        print cnf.get(args[2])
     else:
         session = DBConn().session()
         try:
@@ -517,9 +600,9 @@ def show_keyring(command):
     if mode == 'list-all':
         pass
     elif mode == 'list-binary':
-        q = q.filter(Keyring.default_source_acl_id == None)
+        q = q.join(Keyring.acl).filter(ACL.allow_source == False)
     elif mode == 'list-source':
-        q = q.filter(Keyring.default_source_acl_id != None)
+        q = q.join(Keyring.acl).filter(ACL.allow_source == True)
     else:
         die("E: keyring command unknown")
 
@@ -541,9 +624,9 @@ def main():
         if not Cnf.has_key("Admin::Options::%s" % (i)):
             Cnf["Admin::Options::%s" % (i)] = ""
 
-    arguments = apt_pkg.ParseCommandLine(Cnf, arguments, sys.argv)
+    arguments = apt_pkg.parse_commandline(Cnf, arguments, sys.argv)
 
-    options = Cnf.SubTree("Admin::Options")
+    options = Cnf.subtree("Admin::Options")
     if options["Help"] or len(arguments) < 1:
         usage()
     if options["Dry-Run"]: