X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=inline;f=dak%2Fcontrol_suite.py;h=3ba5acdced15ae8f5bc731f00ce754d86238d15e;hb=d092db5a64fc5ee4143493a7f2bbb327077e08a3;hp=740b88365d6b630580f6c0904f6560b52c7a0139;hpb=886522194878afe478e4dd61397493f35b5b0e5d;p=dak.git diff --git a/dak/control_suite.py b/dak/control_suite.py index 740b8836..3ba5acdc 100755 --- a/dak/control_suite.py +++ b/dak/control_suite.py @@ -193,6 +193,17 @@ def version_checks(package, architecture, target_suite, new_version, session, fo ####################################################################################### +def cmp_package_version(a, b): + """ + comparison function for tuples of the form (package-name, version ...) + """ + cmp_package = cmp(a[0], b[0]) + if cmp_package != 0: + return cmp_package + return apt_pkg.VersionCompare(a[1], b[1]) + +####################################################################################### + def set_suite(file, suite, session, britney=False, force=False): suite_id = suite.suite_id lines = file.readlines() @@ -227,19 +238,8 @@ def set_suite(file, suite, session, britney=False, force=False): key = " ".join(split_line) desired[key] = "" - # Check to see which packages need removed and remove them - for key in current.keys(): - if not desired.has_key(key): - (package, version, architecture) = key.split() - pkid = current[key] - if architecture == "source": - session.execute("""DELETE FROM src_associations WHERE id = :pkid""", {'pkid': pkid}) - else: - session.execute("""DELETE FROM bin_associations WHERE id = :pkid""", {'pkid': pkid}) - Logger.log(["removed", key, pkid]) - # Check to see which packages need added and add them - for key in desired.keys(): + for key in sorted(desired.keys(), cmp=cmp_package_version): if not current.has_key(key): (package, version, architecture) = key.split() version_checks(package, architecture, suite.suite_name, version, session, force) @@ -254,6 +254,17 @@ def set_suite(file, suite, session, britney=False, force=False): VALUES (:suiteid, :pkid)""", {'suiteid': suite_id, 'pkid': pkid}) Logger.log(["added", key, pkid]) + # Check to see which packages need removed and remove them + for key in current.keys(): + if not desired.has_key(key): + (package, version, architecture) = key.split() + pkid = current[key] + if architecture == "source": + session.execute("""DELETE FROM src_associations WHERE id = :pkid""", {'pkid': pkid}) + else: + session.execute("""DELETE FROM bin_associations WHERE id = :pkid""", {'pkid': pkid}) + Logger.log(["removed", key, pkid]) + session.commit() if britney: @@ -268,17 +279,19 @@ def process_file(file, suite, action, session, britney=False, force=False): suite_id = suite.suite_id - lines = file.readlines() + request = [] # Our session is already in a transaction - for line in lines: + for line in file: split_line = line.strip().split() if len(split_line) != 3: utils.warn("'%s' does not break into 'package version architecture'." % (line[:-1])) continue + request.append(split_line) - (package, version, architecture) = split_line + request.sort(cmp=cmp_package_version) + for package, version, architecture in request: pkid = get_id(package, version, architecture, session) if not pkid: continue @@ -383,7 +396,7 @@ def main (): try: file_list = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv); - except SystemError, e: + except SystemError as e: print "%s\n" % e usage(1) Options = cnf.SubTree("Control-Suite::Options") @@ -408,15 +421,17 @@ def main (): utils.fubar("Can only perform one action at a time.") action = i + # Safety/Sanity check + if action == "set" and (not suite.allowcsset): + if force: + utils.warn("Would not normally allow setting suite %s (allowsetcs is FALSE), but --force used" % (suite_name)) + else: + utils.fubar("Will not reset suite %s due to its database configuration (allowsetcs is FALSE)" % (suite_name)) + # Need an action... if action == None: utils.fubar("No action specified.") - # Safety/Sanity check - # XXX: This should be stored in the database - if action == "set" and suite_name not in ["testing", "squeeze-updates"]: - utils.fubar("Will not reset suite %s" % (suite_name)) - britney = False if action == "set" and cnf["Control-Suite::Options::Britney"]: britney = True @@ -424,7 +439,7 @@ def main (): if action == "list": get_list(suite, session) else: - Logger = daklog.Logger(cnf.Cnf, "control-suite") + Logger = daklog.Logger("control-suite") if file_list: for f in file_list: process_file(utils.open_file(f), suite, action, session, britney, force)