From 2b8e14db14a20525fc6bb4b38fee86d99e4d382c Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt Date: Tue, 7 Oct 2014 21:18:52 +0200 Subject: [PATCH] Handle packages with overrides in multiple components This should make moving packages between components (e.g. packages moving from non-free to main) less painful. Bug: https://bugs.debian.org/690444 --- dak/process_policy.py | 24 ++++++++++++++++-------- daklib/archive.py | 34 +++++++++++++++++++++++++++++++++- daklib/policy.py | 21 ++++++++------------- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/dak/process_policy.py b/dak/process_policy.py index 2890c861..c8c9f2d0 100755 --- a/dak/process_policy.py +++ b/dak/process_policy.py @@ -43,8 +43,9 @@ from daklib import daklog from daklib import utils from daklib.dak_exceptions import CantOpenError, AlreadyLockedError, CantGetLockError from daklib.config import Config -from daklib.archive import ArchiveTransaction +from daklib.archive import ArchiveTransaction, source_component_from_package_list from daklib.urgencylog import UrgencyLog +from daklib.packagelist import PackageList import daklib.announce @@ -131,16 +132,23 @@ def comment_accept(upload, srcqueue, comments, transaction): overridesuite = session.query(Suite).filter_by(suite_name=overridesuite.overridesuite).one() def binary_component_func(db_binary): - override = session.query(Override).filter_by(suite=overridesuite, package=db_binary.package) \ - .join(OverrideType).filter(OverrideType.overridetype == db_binary.binarytype) \ - .join(Component).one() - return override.component + section = db_binary.proxy['Section'] + component_name = 'main' + if section.find('/') != -1: + component_name = section.split('/', 1)[0] + return session.query(Component).filter_by(component_name=component_name).one() def source_component_func(db_source): - override = session.query(Override).filter_by(suite=overridesuite, package=db_source.source) \ + package_list = PackageList(db_source.proxy) + component = source_component_from_package_list(package_list, upload.target_suite) + if component is not None: + return component + + # Fallback for packages without Package-List field + query = session.query(Override).filter_by(suite=overridesuite, package=db_source.source) \ .join(OverrideType).filter(OverrideType.overridetype == 'dsc') \ - .join(Component).one() - return override.component + .join(Component) + return query.one().component all_target_suites = [upload.target_suite] all_target_suites.extend([q.suite for q in upload.target_suite.copy_queues]) diff --git a/daklib/archive.py b/daklib/archive.py index b78a1cb4..04c55c0a 100644 --- a/daklib/archive.py +++ b/daklib/archive.py @@ -33,6 +33,7 @@ from datetime import datetime import os import shutil from sqlalchemy.orm.exc import NoResultFound +from sqlalchemy.orm import object_session import sqlalchemy.exc import tempfile import traceback @@ -540,6 +541,34 @@ class ArchiveTransaction(object): self.rollback() return None +def source_component_from_package_list(package_list, suite): + """Get component for a source package + + This function will look at the Package-List field to determine the + component the source package belongs to. This is the first component + the source package provides binaries for (first with respect to the + ordering of components). + + It the source package has no Package-List field, None is returned. + + @type package_list: L{daklib.packagelist.PackageList} + @param package_list: package list of the source to get the override for + + @type suite: L{daklib.dbconn.Suite} + @param suite: suite to consider for binaries produced + + @rtype: L{daklib.dbconn.Component} or C{None} + @return: component for the given source or C{None} + """ + if package_list.fallback: + return None + session = object_session(suite) + packages = package_list.packages_for_suite(suite) + components = set(p.component for p in packages) + query = session.query(Component).order_by(Component.ordering) \ + .filter(Component.component_name.in_(components)) + return query.first() + class ArchiveUpload(object): """handle an upload @@ -854,10 +883,13 @@ class ArchiveUpload(object): if suite.overridesuite is not None: suite = self.session.query(Suite).filter_by(suite_name=suite.overridesuite).one() - # XXX: component for source? query = self.session.query(Override).filter_by(suite=suite, package=source.dsc['Source']) \ .join(OverrideType).filter(OverrideType.overridetype == 'dsc') + component = source_component_from_package_list(source.package_list, suite) + if component is not None: + query = query.filter(Override.component == component) + try: return query.one() except NoResultFound: diff --git a/daklib/policy.py b/daklib/policy.py index 943d5686..dad9e9d1 100644 --- a/daklib/policy.py +++ b/daklib/policy.py @@ -284,18 +284,13 @@ class PolicyQueueUploadHandler(object): for p in packages: check_override(p.name, p.type, p.priority, p.section, included=False) - source_component = '(unknown)' - for component, in self.session.query(Component.component_name).order_by(Component.ordering): - if component in components: - source_component = component - break - else: - if source is not None: - if self._source_override(component) is not None: - source_component = component - break + # see daklib.archive.source_component_from_package_list + # which we cannot use here as we might not have a Package-List + # field for old packages + query = self.session.query(Component).order_by(Component.ordering) \ + .filter(Component.component_name.in_(components)) + source_component = query.first().component_name - if source is not None: override = self._source_override(source_component) if override is None: hint = hints_map.get(('dsc', source.source)) @@ -303,8 +298,8 @@ class PolicyQueueUploadHandler(object): missing.append(hint) else: section = 'misc' - if component != 'main': - section = "{0}/{1}".format(component, section) + if source_component != 'main': + section = "{0}/{1}".format(source_component, section) missing.append(dict( package = source.source, priority = 'extra', -- 2.39.5