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
#######################################################################################
#######################################################################################
-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()
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
#######################################################################################
-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
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
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"),
session = DBConn().session()
+ force = Options.has_key("Force") and Options["Force"]
+
action = None
for i in ("add", "list", "remove", "set"):
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()
#######################################################################################