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
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])
import os
import shutil
from sqlalchemy.orm.exc import NoResultFound
+from sqlalchemy.orm import object_session
import sqlalchemy.exc
import tempfile
import traceback
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
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:
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))
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',