X-Git-Url: https://git.decadent.org.uk/gitweb/?p=dak.git;a=blobdiff_plain;f=dak%2Foverride.py;h=1d43a62579fe08012426cb5dcd1fc2d435c50883;hp=3e8a9b4149ea7e9f7328534e171ea30283038c59;hb=0d69fff35ef45fda573467873ae2f01ca1954650;hpb=f0bfd37e7286156598d79b53501ebe2000bb7924 diff --git a/dak/override.py b/dak/override.py index 3e8a9b41..1d43a625 100755 --- a/dak/override.py +++ b/dak/override.py @@ -49,28 +49,83 @@ def usage (exit_code=0): Make microchanges or microqueries of the binary overrides -h, --help show this help and exit + -c, --check check override compliance -d, --done=BUG# send priority/section change as closure to bug# -n, --no-action don't do anything -s, --suite specify the suite to use """ sys.exit(exit_code) +def check_override_compliance(package, priority, archive_path, suite_name, cnf, session): + print "Checking compliance with related overrides..." + + depends = set() + rdepends = set() + components = get_component_names(session) + arches = set([x.arch_string for x in get_suite_architectures(suite_name)]) + arches -= set(["source", "all"]) + for arch in arches: + for component in components: + Packages = utils.get_packages_from_ftp(archive_path, suite_name, component, arch) + while Packages.step(): + package_name = Packages.section.find("Package") + dep_list = Packages.section.find("Depends") + if dep_list: + if package_name == package: + for d in apt_pkg.parse_depends(dep_list): + for i in d: + depends.add(i[0]) + else: + for d in apt_pkg.parse_depends(dep_list): + for i in d: + if i[0] == package: + rdepends.add(package_name) + + query = """SELECT o.package, p.level, p.priority + FROM override o + JOIN suite s ON s.id = o.suite + JOIN priority p ON p.id = o.priority + WHERE s.suite_name = '%s' + AND o.package in ('%s')""" \ + % (suite_name, "', '".join(depends.union(rdepends))) + packages = session.execute(query) + + excuses = [] + for p in packages: + if p[0] == package or not p[1]: + continue + if p[0] in depends: + if priority.level < p[1]: + excuses.append("%s would have priority %s, its dependency %s has priority %s" \ + % (package, priority.priority, p[0], p[2])) + if p[0] in rdepends: + if priority.level > p[1]: + excuses.append("%s would have priority %s, its reverse dependency %s has priority %s" \ + % (package, priority.priority, p[0], p[2])) + + if excuses: + for ex in excuses: + print ex + else: + print "Proposed override change complies with Debian Policy" + def main (): cnf = Config() Arguments = [('h',"help","Override::Options::Help"), + ('c',"check","Override::Options::Check"), ('d',"done","Override::Options::Done", "HasArg"), ('n',"no-action","Override::Options::No-Action"), ('s',"suite","Override::Options::Suite", "HasArg"), ] - for i in ["help", "no-action"]: + for i in ["help", "check", "no-action"]: if not cnf.has_key("Override::Options::%s" % (i)): cnf["Override::Options::%s" % (i)] = "" if not cnf.has_key("Override::Options::Suite"): cnf["Override::Options::Suite"] = "unstable" - arguments = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv) - Options = cnf.SubTree("Override::Options") + arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) + Options = cnf.subtree("Override::Options") if Options["Help"]: usage() @@ -81,10 +136,14 @@ def main (): utils.fubar("package name is a required argument.") package = arguments.pop(0) - suite = Options["Suite"] + suite_name = Options["Suite"] if arguments and len(arguments) > 2: utils.fubar("Too many arguments") + suite = get_suite(suite_name, session) + if suite is None: + utils.fubar("Unknown suite '{0}'".format(suite_name)) + if arguments and len(arguments) == 1: # Determine if the argument is a priority or a section... arg = arguments.pop() @@ -115,13 +174,13 @@ def main (): AND override.section = section.id AND override.package = :package AND override.suite = suite.id - AND suite.suite_name = :suite - """ % (eqdsc), {'package': package, 'suite': suite}) + AND suite.suite_name = :suite_name + """ % (eqdsc), {'package': package, 'suite_name': suite_name}) if q.rowcount == 0: continue if q.rowcount > 1: - utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.ntuples())) + utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.rowcount)) r = q.fetchone() if packagetype == 'binary': @@ -171,6 +230,9 @@ def main (): if oldpriority == 'source' and newpriority != 'source': utils.fubar("Trying to change priority of a source-only package") + if Options["Check"] and newpriority != oldpriority: + check_override_compliance(package, p, suite.archive.path, suite_name, cnf, session) + # If we're in no-action mode if Options["No-Action"]: if newpriority != oldpriority: @@ -196,7 +258,7 @@ def main (): game_over() - Logger = daklog.Logger(cnf.Cnf, "override") + Logger = daklog.Logger("override") dsc_otype_id = get_override_type('dsc').overridetype_id @@ -208,9 +270,9 @@ def main (): SET priority = :newprioid WHERE package = :package AND override.type != :otypedsc - AND suite = (SELECT id FROM suite WHERE suite_name = :suite)""", + AND suite = (SELECT id FROM suite WHERE suite_name = :suite_name)""", {'newprioid': newprioid, 'package': package, - 'otypedsc': dsc_otype_id, 'suite': suite}) + 'otypedsc': dsc_otype_id, 'suite_name': suite_name}) Logger.log(["changed priority", package, oldpriority, newpriority]) @@ -219,33 +281,41 @@ def main (): UPDATE override SET section = :newsecid WHERE package = :package - AND suite = (SELECT id FROM suite WHERE suite_name = :suite)""", + AND suite = (SELECT id FROM suite WHERE suite_name = :suite_name)""", {'newsecid': newsecid, 'package': package, - 'suite': suite}) + 'suite_name': suite_name}) Logger.log(["changed section", package, oldsection, newsection]) session.commit() if Options.has_key("Done"): + if not cnf.has_key("Dinstall::BugServer"): + utils.warn("Asked to send Done message but Dinstall::BugServer is not configured") + Logger.close() + return + Subst = {} Subst["__OVERRIDE_ADDRESS__"] = cnf["Dinstall::MyEmailAddress"] Subst["__BUG_SERVER__"] = cnf["Dinstall::BugServer"] bcc = [] - if cnf.Find("Dinstall::Bcc") != "": + if cnf.find("Dinstall::Bcc") != "": bcc.append(cnf["Dinstall::Bcc"]) if bcc: Subst["__BCC__"] = "Bcc: " + ", ".join(bcc) else: Subst["__BCC__"] = "X-Filler: 42" - Subst["__CC__"] = "Cc: " + package + "@" + cnf["Dinstall::PackagesServer"] + "\nX-DAK: dak override" + if cnf.has_key("Dinstall::PackagesServer"): + Subst["__CC__"] = "Cc: " + package + "@" + cnf["Dinstall::PackagesServer"] + "\nX-DAK: dak override" + else: + Subst["__CC__"] = "X-DAK: dak override" Subst["__ADMIN_ADDRESS__"] = cnf["Dinstall::MyAdminAddress"] Subst["__DISTRO__"] = cnf["Dinstall::MyDistribution"] Subst["__WHOAMI__"] = utils.whoami() Subst["__SOURCE__"] = package summary = "Concerning package %s...\n" % (package) - summary += "Operating on the %s suite\n" % (suite) + summary += "Operating on the %s suite\n" % (suite_name) if newpriority != oldpriority: summary += "Changed priority from %s to %s\n" % (oldpriority,newpriority) if newsection != oldsection: