From 3a7846025b1d282c0499373983eee641d8220cff Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt Date: Thu, 28 May 2015 23:15:12 +0200 Subject: [PATCH] Remove obsolete code. --- daklib/queue.py | 269 ---------------------------------- daklib/queue_install.py | 302 --------------------------------------- daklib/regexes.py | 2 - tests/dbtest_packages.py | 46 +----- 4 files changed, 1 insertion(+), 618 deletions(-) delete mode 100644 daklib/queue_install.py diff --git a/daklib/queue.py b/daklib/queue.py index b869e04f..44176bf7 100644 --- a/daklib/queue.py +++ b/daklib/queue.py @@ -197,35 +197,12 @@ def edit_note(note, upload, session, trainee=False): ############################################################################### -# FIXME: Should move into the database -# suite names DMs can upload to -dm_suites = ['unstable', 'experimental', 'squeeze-backports','squeeze-backports-sloppy', 'wheezy-backports'] - -def get_newest_source(source, session): - 'returns the newest DBSource object in dm_suites' - ## the most recent version of the package uploaded to unstable or - ## experimental includes the field "DM-Upload-Allowed: yes" in the source - ## section of its control file - q = session.query(DBSource).filter_by(source = source). \ - filter(DBSource.suites.any(Suite.suite_name.in_(dm_suites))). \ - order_by(desc('source.version')) - return q.first() - def get_suite_version_by_source(source, session): 'returns a list of tuples (suite_name, version) for source package' q = session.query(Suite.suite_name, DBSource.version). \ join(Suite.sources).filter_by(source = source) return q.all() -def get_source_by_package_and_suite(package, suite_name, session): - ''' - returns a DBSource query filtered by DBBinary.package and this package's - suite_name - ''' - return session.query(DBSource). \ - join(DBSource.binaries).filter_by(package = package). \ - join(DBBinary.suites).filter_by(suite_name = suite_name) - def get_suite_version_by_package(package, arch_string, session): ''' returns a list of tuples (suite_name, version) for binary package and @@ -308,79 +285,6 @@ class Upload(object): ########################################################################### - def check_distributions(self): - "Check and map the Distribution field" - - Cnf = Config() - - # Handle suite mappings - for m in Cnf.value_list("SuiteMappings"): - args = m.split() - mtype = args[0] - if mtype == "map" or mtype == "silent-map": - (source, dest) = args[1:3] - if self.pkg.changes["distribution"].has_key(source): - del self.pkg.changes["distribution"][source] - self.pkg.changes["distribution"][dest] = 1 - if mtype != "silent-map": - self.notes.append("Mapping %s to %s." % (source, dest)) - if self.pkg.changes.has_key("distribution-version"): - if self.pkg.changes["distribution-version"].has_key(source): - self.pkg.changes["distribution-version"][source]=dest - elif mtype == "map-unreleased": - (source, dest) = args[1:3] - if self.pkg.changes["distribution"].has_key(source): - for arch in self.pkg.changes["architecture"].keys(): - if arch not in [ a.arch_string for a in get_suite_architectures(source) ]: - self.notes.append("Mapping %s to %s for unreleased architecture %s." % (source, dest, arch)) - del self.pkg.changes["distribution"][source] - self.pkg.changes["distribution"][dest] = 1 - break - elif mtype == "ignore": - suite = args[1] - if self.pkg.changes["distribution"].has_key(suite): - del self.pkg.changes["distribution"][suite] - self.warnings.append("Ignoring %s as a target suite." % (suite)) - elif mtype == "reject": - suite = args[1] - if self.pkg.changes["distribution"].has_key(suite): - self.rejects.append("Uploads to %s are not accepted." % (suite)) - elif mtype == "propup-version": - # give these as "uploaded-to(non-mapped) suites-to-add-when-upload-obsoletes" - # - # changes["distribution-version"] looks like: {'testing': 'testing-proposed-updates'} - if self.pkg.changes["distribution"].has_key(args[1]): - self.pkg.changes.setdefault("distribution-version", {}) - for suite in args[2:]: - self.pkg.changes["distribution-version"][suite] = suite - - # Ensure there is (still) a target distribution - if len(self.pkg.changes["distribution"].keys()) < 1: - self.rejects.append("No valid distribution remaining.") - - # Ensure target distributions exist - for suite in self.pkg.changes["distribution"].keys(): - if not get_suite(suite.lower()): - self.rejects.append("Unknown distribution `%s'." % (suite)) - - ########################################################################### - - def per_suite_file_checks(self, f, suite, session): - raise Exception('removed') - - # Handle component mappings - for m in cnf.value_list("ComponentMappings"): - (source, dest) = m.split() - if entry["component"] == source: - entry["original component"] = source - entry["component"] = dest - - ########################################################################### - - # Sanity check the time stamps of files inside debs. - # [Files in the near future cause ugly warnings and extreme time - # travel can cause errors on extraction] - def check_if_upload_is_sponsored(self, uid_email, uid_name): for key in "maintaineremail", "changedbyemail", "maintainername", "changedbyname": if not self.pkg.changes.has_key(key): @@ -406,40 +310,10 @@ class Upload(object): return sponsored - def check_dm_upload(self, fpr, session): - # Quoth the GR (https://www.debian.org/vote/2007/vote_003): - ## none of the uploaded packages are NEW - ## none of the packages are being taken over from other source packages - for b in self.pkg.changes["binary"].keys(): - for suite in self.pkg.changes["distribution"].keys(): - for s in get_source_by_package_and_suite(b, suite, session): - if s.source != self.pkg.changes["source"]: - self.rejects.append("%s may not hijack %s from source package %s in suite %s" % (fpr.uid.uid, b, s, suite)) - ########################################################################### # End check_signed_by_key checks ########################################################################### - def build_summaries(self): - """ Build a summary of changes the upload introduces. """ - - (byhand, new, summary, override_summary) = self.pkg.file_summary() - - short_summary = summary - - # This is for direport's benefit... - f = re_fdnic.sub("\n .\n", self.pkg.changes.get("changes", "")) - - summary += "\n\nChanges:\n" + f - - summary += "\n\nOverride entries for your package:\n" + override_summary + "\n" - - summary += self.announce(short_summary, 0) - - return (summary, short_summary) - - ########################################################################### - def announce(self, short_summary, action): """ Send an announce mail about a new upload. @@ -533,146 +407,3 @@ class Upload(object): mail_message = utils.TemplateSubst(self.Subst, overridetemplate) utils.send_mail(mail_message) del self.Subst["__SUMMARY__"] - - ################################################################################ - def get_anyversion(self, sv_list, suite): - """ - @type sv_list: list - @param sv_list: list of (suite, version) tuples to check - - @type suite: string - @param suite: suite name - - Description: TODO - """ - Cnf = Config() - anyversion = None - anysuite = [suite] + [ vc.reference.suite_name for vc in get_version_checks(suite, "Enhances") ] - for (s, v) in sv_list: - if s in [ x.lower() for x in anysuite ]: - if not anyversion or apt_pkg.version_compare(anyversion, v) <= 0: - anyversion = v - - return anyversion - - ################################################################################ - - def cross_suite_version_check(self, sv_list, filename, new_version, sourceful=False): - """ - @type sv_list: list - @param sv_list: list of (suite, version) tuples to check - - @type filename: string - @param filename: XXX - - @type new_version: string - @param new_version: XXX - - Ensure versions are newer than existing packages in target - suites and that cross-suite version checking rules as - set out in the conf file are satisfied. - """ - - cnf = Config() - - # Check versions for each target suite - for target_suite in self.pkg.changes["distribution"].keys(): - # Check we can find the target suite - ts = get_suite(target_suite) - if ts is None: - self.rejects.append("Cannot find target suite %s to perform version checks" % target_suite) - continue - - 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") ] - - # Enforce "must be newer than target suite" even if conffile omits it - if target_suite not in must_be_newer_than: - must_be_newer_than.append(target_suite) - - for (suite, existent_version) in sv_list: - vercmp = apt_pkg.version_compare(new_version, existent_version) - - if suite in must_be_newer_than and sourceful and vercmp < 1: - self.rejects.append("%s: old version (%s) in %s >= new version (%s) targeted at %s." % (filename, existent_version, suite, new_version, target_suite)) - - if suite in must_be_older_than and vercmp > -1: - cansave = 0 - - if self.pkg.changes.get('distribution-version', {}).has_key(suite): - # we really use the other suite, ignoring the conflicting one ... - addsuite = self.pkg.changes["distribution-version"][suite] - - add_version = self.get_anyversion(sv_list, addsuite) - target_version = self.get_anyversion(sv_list, target_suite) - - if not add_version: - # not add_version can only happen if we map to a suite - # that doesn't enhance the suite we're propup'ing from. - # so "propup-ver x a b c; map a d" is a problem only if - # d doesn't enhance a. - # - # i think we could always propagate in this case, rather - # than complaining. either way, this isn't a REJECT issue - # - # And - we really should complain to the dorks who configured dak - self.warnings.append("%s is mapped to, but not enhanced by %s - adding anyways" % (suite, addsuite)) - self.pkg.changes.setdefault("propdistribution", {}) - self.pkg.changes["propdistribution"][addsuite] = 1 - cansave = 1 - elif not target_version: - # not targets_version is true when the package is NEW - # we could just stick with the "...old version..." REJECT - # for this, I think. - self.rejects.append("Won't propogate NEW packages.") - elif apt_pkg.version_compare(new_version, add_version) < 0: - # propogation would be redundant. no need to reject though. - self.warnings.append("ignoring versionconflict: %s: old version (%s) in %s <= new version (%s) targeted at %s." % (filename, existent_version, suite, new_version, target_suite)) - cansave = 1 - elif apt_pkg.version_compare(new_version, add_version) > 0 and \ - apt_pkg.version_compare(add_version, target_version) >= 0: - # propogate!! - self.warnings.append("Propogating upload to %s" % (addsuite)) - self.pkg.changes.setdefault("propdistribution", {}) - self.pkg.changes["propdistribution"][addsuite] = 1 - cansave = 1 - - if not cansave: - self.rejects.append("%s: old version (%s) in %s <= new version (%s) targeted at %s." % (filename, existent_version, suite, new_version, target_suite)) - - ################################################################################ - - def accepted_checks(self, overwrite_checks, session): - # Recheck anything that relies on the database; since that's not - # frozen between accept and our run time when called from p-a. - - # overwrite_checks is set to False when installing to stable/oldstable - - propogate={} - nopropogate={} - - for checkfile in self.pkg.files.keys(): - # The .orig.tar.gz can disappear out from under us is it's a - # duplicate of one in the archive. - if not self.pkg.files.has_key(checkfile): - continue - - entry = self.pkg.files[checkfile] - - # propogate in the case it is in the override tables: - for suite in self.pkg.changes.get("propdistribution", {}).keys(): - if self.in_override_p(entry["package"], entry["component"], suite, entry.get("dbtype",""), checkfile, session): - propogate[suite] = 1 - else: - nopropogate[suite] = 1 - - for suite in propogate.keys(): - if suite in nopropogate: - continue - self.pkg.changes["distribution"][suite] = 1 - - for checkfile in self.pkg.files.keys(): - # Check the package is still in the override tables - for suite in self.pkg.changes["distribution"].keys(): - if not self.in_override_p(entry["package"], entry["component"], suite, entry.get("dbtype",""), checkfile, session): - self.rejects.append("%s is NEW for %s." % (checkfile, suite)) diff --git a/daklib/queue_install.py b/daklib/queue_install.py deleted file mode 100644 index 8f05e7bf..00000000 --- a/daklib/queue_install.py +++ /dev/null @@ -1,302 +0,0 @@ -#!/usr/bin/env python -# vim:set et sw=4: - -""" -Utility functions for process-upload - -@contact: Debian FTP Master -@copyright: 2000, 2001, 2002, 2003, 2004, 2005, 2006 James Troup -@copyright: 2009 Joerg Jaspert -@copyright: 2009 Mark Hymers -@license: GNU General Public License version 2 or later -""" - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -import os -from shutil import copyfile - -from daklib import utils -from daklib.dbconn import * -from daklib.config import Config - -################################################################################ - -def package_to_suite(u, suite_name, session): - if suite_name not in u.pkg.changes["distribution"]: - return False - - if 'source' in u.pkg.changes["architecture"]: - return True - - q = session.query(Suite).filter_by(suite_name = suite_name). \ - filter(Suite.sources.any( \ - source = u.pkg.changes['source'], \ - version = u.pkg.changes['version'])) - - # NB: Careful, this logic isn't what you would think it is - # Source is already in the target suite so no need to go to policy - # Instead, we don't move to the policy area, we just do an ACCEPT - if q.count() > 0: - return False - else: - return True - -def package_to_queue(u, summary, short_summary, queue, chg, session, announce=None): - cnf = Config() - dir = queue.path - - print "Moving to %s policy queue" % queue.queue_name.upper() - u.logger.log(["Moving to %s" % queue.queue_name, u.pkg.changes_file]) - - u.move_to_queue(queue) - chg.in_queue_id = queue.policy_queue_id - session.add(chg) - - # send to build queues - if queue.send_to_build_queues: - for suite_name in u.pkg.changes["distribution"].keys(): - suite = get_suite(suite_name, session) - for q in suite.copy_queues: - q.add_changes_from_policy_queue(queue, chg) - - session.commit() - - # Check for override disparities - u.check_override() - - # Send accept mail, announce to lists and close bugs - if announce: - template = os.path.join(cnf["Dir::Templates"], announce) - u.update_subst() - mail_message = utils.TemplateSubst(u.Subst, template) - utils.send_mail(mail_message) - u.announce(short_summary, True) - -################################################################################ - -def is_unembargo(u): - session = DBConn().session() - - # If we dont have the disembargo queue we are not on security and so not interested - # in doing any security queue handling - disembargo_queue = get_policy_queue("unembargoed") - if not disembargo_queue: - return False - - # If we already are in newstage, then it means this just got passed through and accepted - # by a security team member. Don't try to accept it for disembargo again - dbc = get_dbchange(u.pkg.changes_file, session) - if dbc and dbc.in_queue.queue_name in [ 'newstage' ]: - return False - - q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version", - {'source': u.pkg.changes["source"], - 'version': u.pkg.changes["version"]}) - if q.rowcount > 0: - session.close() - return True - - # Ensure we don't have a / on the end or something - disdir = os.path.abspath(disembargo_queue.path) - - ret = False - - if u.pkg.directory == disdir: - if u.pkg.changes["architecture"].has_key("source"): - session.execute("INSERT INTO disembargo (package, version) VALUES (:source, :version)", - {'source': u.pkg.changes["source"], - 'version': u.pkg.changes["version"]}) - session.commit() - - ret = True - - session.close() - - return ret - -def do_unembargo(u, summary, short_summary, chg, session=None): - polq=get_policy_queue('unembargoed') - package_to_queue(u, summary, short_summary, - polq, chg, session, - announce=None) -# -################################################################################# -# -def is_embargo(u): - # if we are the security archive, we always have a embargo queue and its the - # last in line, so if that exists, return true - # Of course do not return true when we accept from out of newstage, as that means - # it just left embargo and we want it in the archive - if get_policy_queue('embargoed'): - session = DBConn().session() - dbc = get_dbchange(u.pkg.changes_file, session) - if dbc and dbc.in_queue.queue_name in [ 'newstage' ]: - return False - - return True - -def do_embargo(u, summary, short_summary, chg, session=None): - polq=get_policy_queue('embargoed') - package_to_queue(u, summary, short_summary, - polq, chg, session, - announce=None) - -################################################################################ - -def is_autobyhand(u): - cnf = Config() - - all_auto = 1 - any_auto = 0 - for f in u.pkg.files.keys(): - if u.pkg.files[f].has_key("byhand"): - any_auto = 1 - - # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH - # don't contain underscores, and ARCH doesn't contain dots. - # further VER matches the .changes Version:, and ARCH should be in - # the .changes Architecture: list. - if f.count("_") < 2: - all_auto = 0 - continue - - (pckg, ver, archext) = f.split("_", 2) - if archext.count(".") < 1 or u.pkg.changes["version"] != ver: - all_auto = 0 - continue - - ABH = cnf.subtree("AutomaticByHandPackages") - if not ABH.has_key(pckg) or \ - ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]: - print "not match %s %s" % (pckg, u.pkg.changes["source"]) - all_auto = 0 - continue - - (arch, ext) = archext.split(".", 1) - if arch not in u.pkg.changes["architecture"]: - all_auto = 0 - continue - - u.pkg.files[f]["byhand-arch"] = arch - u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)] - - return any_auto and all_auto - -def do_autobyhand(u, summary, short_summary, chg, session): - print "Attempting AUTOBYHAND." - byhandleft = False - for f, entry in u.pkg.files.items(): - byhandfile = f - - if not entry.has_key("byhand"): - continue - - if not entry.has_key("byhand-script"): - byhandleft = True - continue - - os.system("ls -l %s" % byhandfile) - - result = os.system("%s %s %s %s %s" % ( - entry["byhand-script"], - byhandfile, - u.pkg.changes["version"], - entry["byhand-arch"], - os.path.abspath(u.pkg.changes_file))) - - if result == 0: - os.unlink(byhandfile) - del u.pkg.files[f] - else: - print "Error processing %s, left as byhand." % (f) - byhandleft = True - - if byhandleft: - do_byhand(u, summary, short_summary, chg, session) - else: - u.accept(summary, short_summary, session) - u.check_override() - -################################################################################ - -def is_byhand(u): - for f in u.pkg.files.keys(): - if u.pkg.files[f].has_key("byhand"): - return True - return False - -def do_byhand(u, summary, short_summary, chg, session): - return package_to_queue(u, summary, short_summary, - get_policy_queue('byhand'), chg, session, - announce=None) - -################################################################################ - -def is_new(u): - for f in u.pkg.files.keys(): - if u.pkg.files[f].has_key("new"): - return True - return False - -def acknowledge_new(u, summary, short_summary, chg, session): - cnf = Config() - - print "Moving to NEW queue." - u.logger.log(["Moving to new", u.pkg.changes_file]) - - q = get_policy_queue('new', session) - - u.move_to_queue(q) - chg.in_queue_id = q.policy_queue_id - session.add(chg) - session.commit() - - print "Sending new ack." - template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new') - u.update_subst() - u.Subst["__SUMMARY__"] = summary - new_ack_message = utils.TemplateSubst(u.Subst, template) - utils.send_mail(new_ack_message) - -################################################################################ - -# FIXME: queues should be able to get autobuild -# the current logic doesnt allow this, as buildd stuff is AFTER accept... -# embargo/disembargo use a workaround due to this -# q-unapproved hax0ring -QueueInfo = { - "new": { "is": is_new, "process": acknowledge_new }, - "autobyhand" : { "is" : is_autobyhand, "process": do_autobyhand }, - "byhand" : { "is": is_byhand, "process": do_byhand }, - "embargoed" : { "is": is_embargo, "process": do_embargo }, - "unembargoed" : { "is": is_unembargo, "process": do_unembargo }, -} - -def determine_target(u): - cnf = Config() - - # Statically handled queues - target = None - - for q in ["autobyhand", "byhand", "new", "unembargoed", "embargoed"]: - if QueueInfo[q]["is"](u): - target = q - break - - return target - -############################################################################### - diff --git a/daklib/regexes.py b/daklib/regexes.py index dd1c3dd8..6e00164c 100644 --- a/daklib/regexes.py +++ b/daklib/regexes.py @@ -34,8 +34,6 @@ re_isanum = re.compile (r"^\d+$") #: Looking for the default reply re_default_answer = re.compile(r"\[(.*)\]") -#: Used in build_summaries to make changes output look better -re_fdnic = re.compile(r"\n\n") #: Detect a binnmu re_bin_only_nmu = re.compile(r"\+b\d+$") diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index 73679b57..53b3c80f 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -4,9 +4,7 @@ from db_test import DBDakTestCase from base_test import fixture from daklib.dbconn import * -from daklib.queue_install import package_to_suite -from daklib.queue import get_newest_source, get_suite_version_by_source, \ - get_source_by_package_and_suite, get_suite_version_by_package +from daklib.queue import get_suite_version_by_source, get_suite_version_by_package from sqlalchemy.orm.exc import MultipleResultsFound import unittest @@ -233,36 +231,6 @@ class PackageTestCase(DBDakTestCase): self.assertTrue(source_exists(hello.source, hello.version, \ session = self.session)) - def test_package_to_suite(self): - 'test function package_to_suite()' - - pkg = Pkg() - pkg.changes = { 'distribution': {} } - upload = Upload(pkg) - self.assertTrue(not package_to_suite(upload, 'sid', self.session)) - pkg.changes['distribution'] = { 'sid': '' } - pkg.changes['architecture'] = { 'source': '' } - self.assertTrue(package_to_suite(upload, 'sid', self.session)) - pkg.changes['architecture'] = {} - pkg.changes['source'] = self.source['hello_2.2-2'].source - pkg.changes['version'] = self.source['hello_2.2-2'].version - self.assertTrue(not package_to_suite(upload, 'sid', self.session)) - pkg.changes['version'] = '42' - self.assertTrue(package_to_suite(upload, 'sid', self.session)) - pkg.changes['source'] = 'foobar' - pkg.changes['version'] = self.source['hello_2.2-2'].version - self.assertTrue(package_to_suite(upload, 'sid', self.session)) - pkg.changes['distribution'] = { 'lenny': '' } - self.assertTrue(package_to_suite(upload, 'lenny', self.session)) - - def test_get_newest_source(self): - 'test function get_newest_source()' - - import daklib.queue - daklib.queue.dm_suites = ['sid'] - self.assertEqual(self.source['hello_2.2-2'], get_newest_source('hello', self.session)) - self.assertEqual(None, get_newest_source('foobar', self.session)) - def test_get_suite_version_by_source(self): 'test function get_suite_version_by_source()' @@ -338,18 +306,6 @@ class PackageTestCase(DBDakTestCase): self.assertEqual('deadbeef', poolfile.sha1sum) self.assertEqual('deadbeef', poolfile.sha256sum) - def test_get_source_by_package_and_suite(self): - 'test get_source_by_package_and_suite()' - - query = get_source_by_package_and_suite('hello', 'sid', self.session) - self.assertEqual(self.source['hello_2.2-1'], query.one()) - query = get_source_by_package_and_suite('gnome-hello', 'squeeze', self.session) - self.assertEqual(self.source['hello_2.2-1'], query.one()) - query = get_source_by_package_and_suite('hello', 'hamm', self.session) - self.assertEqual(0, query.count()) - query = get_source_by_package_and_suite('foobar', 'squeeze', self.session) - self.assertEqual(0, query.count()) - def test_get_suite_version_by_package(self): 'test function get_suite_version_by_package()' -- 2.39.5