]> err.no Git - dak/commitdiff
control-suite: Validate version_checks
authorAnsgar Burchardt <ansgar@debian.org>
Thu, 24 Mar 2011 16:38:18 +0000 (16:38 +0000)
committerAnsgar Burchardt <ansgar@debian.org>
Thu, 24 Mar 2011 16:38:18 +0000 (16:38 +0000)
Also test version_checks when using control-suite instead of only for
uploaded packages.

Signed-off-by: Ansgar Burchardt <ansgar@debian.org>
dak/control_suite.py

index 7ec321f0a8474f2962dd4d47b1d95bf2e324f8f1..fa20100b40a69167f173dd8657c954dd40d84240 100755 (executable)
@@ -49,6 +49,7 @@ from daklib.config import Config
 from daklib.dbconn import *
 from daklib import daklog
 from daklib import utils
+from daklib.queue import get_suite_version_by_package, get_suite_version_by_source
 
 #######################################################################################
 
@@ -160,7 +161,39 @@ def britney_changelog(packages, suite, session):
 
 #######################################################################################
 
-def set_suite(file, suite, session, britney=False):
+def version_checks(package, architecture, target_suite, new_version, session, force = False):
+    if architecture == "source":
+        suite_version_list = get_suite_version_by_source(package, session)
+    else:
+        suite_version_list = get_suite_version_by_package(package, architecture, session)
+
+    must_be_newer_than = [ vc.reference.suite_name for vc in get_version_checks(target_suite, "MustBeNewerThan") ]
+    must_be_older_than = [ vc.reference.suite_name for vc in get_version_checks(target_suite, "MustBeOlderThan") ]
+
+    # Must be newer than an existing version in target_suite
+    if target_suite not in must_be_newer_than:
+        must_be_newer_than.append(target_suite)
+
+    violations = False
+
+    for suite, version in suite_version_list:
+        cmp = apt_pkg.VersionCompare(new_version, version)
+        if suite in must_be_newer_than and cmp < 1:
+            utils.warn("%s (%s): version check violated: %s in %s is *not* newer than %s targeted at %s" % (package, architecture, version, suite, new_version, target_suite))
+            violations = True
+        if suite in must_be_older_than and cmp > 1:
+            utils.warn("%s (%s): version check violated: %s in %s is *not* older than %s targeted at %s" % (package, architecture, version, suite, new_version, target_suite))
+            violations = True
+
+    if violations:
+        if forced:
+            utils.warn("Continuing anyway (forced)...")
+        else:
+            utils.fubar("Aborting. Version checks violated and not forced.")
+
+#######################################################################################
+
+def set_suite(file, suite, session, britney=False, force=False):
     suite_id = suite.suite_id
     lines = file.readlines()
 
@@ -209,6 +242,7 @@ def set_suite(file, suite, session, britney=False):
     for key in desired.keys():
         if not current.has_key(key):
             (package, version, architecture) = key.split()
+            version_checks(package, architecture, suite.suite_name, version, session, force)
             pkid = get_id (package, version, architecture, session)
             if not pkid:
                 continue
@@ -227,9 +261,9 @@ def set_suite(file, suite, session, britney=False):
 
 #######################################################################################
 
-def process_file(file, suite, action, session, britney=False):
+def process_file(file, suite, action, session, britney=False, force=False):
     if action == "set":
-        set_suite(file, suite, session, britney)
+        set_suite(file, suite, session, britney, force)
         return
 
     suite_id = suite.suite_id
@@ -249,6 +283,10 @@ def process_file(file, suite, action, session, britney=False):
         if not pkid:
             continue
 
+        # Do version checks when adding packages
+        if action == "add":
+            version_checks(package, architecture, suite.suite_name, version, session, force)
+
         if architecture == "source":
             # Find the existing association ID, if any
             q = session.execute("""SELECT id FROM src_associations
@@ -333,6 +371,7 @@ def main ():
 
     Arguments = [('a',"add","Control-Suite::Options::Add", "HasArg"),
                  ('b',"britney","Control-Suite::Options::Britney"),
+                 ('f','force','Control-Suite::Options::Force'),
                  ('h',"help","Control-Suite::Options::Help"),
                  ('l',"list","Control-Suite::Options::List","HasArg"),
                  ('r',"remove", "Control-Suite::Options::Remove", "HasArg"),
@@ -354,6 +393,8 @@ def main ():
 
     session = DBConn().session()
 
+    force = Options.has_key("Force") and Options["Force"]
+
     action = None
 
     for i in ("add", "list", "remove", "set"):
@@ -386,9 +427,9 @@ def main ():
         Logger = daklog.Logger(cnf.Cnf, "control-suite")
         if file_list:
             for f in file_list:
-                process_file(utils.open_file(f), suite, action, session, britney)
+                process_file(utils.open_file(f), suite, action, session, britney, force)
         else:
-            process_file(sys.stdin, suite, action, session, britney)
+            process_file(sys.stdin, suite, action, session, britney, force)
         Logger.close()
 
 #######################################################################################