]> git.decadent.org.uk Git - dak.git/commitdiff
Handle packages with overrides in multiple components
authorAnsgar Burchardt <ansgar@debian.org>
Tue, 7 Oct 2014 19:18:52 +0000 (21:18 +0200)
committerAnsgar Burchardt <ansgar@debian.org>
Tue, 7 Oct 2014 19:18:52 +0000 (21:18 +0200)
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
daklib/archive.py
daklib/policy.py

index 2890c8615403b4017710e711194de46f7cda7f7b..c8c9f2d01070fd8785b05f2bd870a8b6254f8815 100755 (executable)
@@ -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])
index b78a1cb4351fb7899b4f7bdf546fddaf03d394cd..04c55c0ae8f45ba0e7b4f63870b24a627fe191e5 100644 (file)
@@ -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:
index 943d5686659182e29de49b1e327b2bdbedc7270f..dad9e9d1ec20c685848dac377ae23ecf87e70942 100644 (file)
@@ -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',