]> err.no Git - dak/commitdiff
dak/admin.py: add archive subcommand
authorAnsgar Burchardt <ansgar@debian.org>
Thu, 31 May 2012 08:24:57 +0000 (10:24 +0200)
committerAnsgar Burchardt <ansgar@debian.org>
Sat, 11 Aug 2012 11:43:07 +0000 (13:43 +0200)
dak/admin.py

index 378a878a7d35c89a9f252ae0abbc60316f2d5d0c..c77e93f32845b464922fbeca55ffd4a1fa22934a 100755 (executable)
@@ -96,6 +96,14 @@ 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)
+
   version-check / v-c:
      v-c list                        show version checks for all suites
      v-c list-suite SUITE            show version checks for suite SUITE
@@ -378,6 +386,64 @@ 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(command):
+    mode = command[1]
+    if mode == 'list':
+        archive_list()
+    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.suite_name):