X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Farchive.py;h=0c5d805d10fbc4f84097f4e663b3552a6862ff36;hb=1ce4af9b7b1682a8e1db57e9f566488819c1e921;hp=b97d2f034c8d63fd1b3e4ee49e42a0e8ca73ed6d;hpb=b5a58ba0847514f68d8925e52508ae63bcfae3f7;p=dak.git diff --git a/daklib/archive.py b/daklib/archive.py index b97d2f03..0c5d805d 100644 --- a/daklib/archive.py +++ b/daklib/archive.py @@ -136,7 +136,8 @@ class ArchiveTransaction(object): source = source_query.filter(DBSource.suites.contains(suite)).first() if source is None: if source_suites != True: - source_query = source_query.filter(DBSource.suites.any(source_suites)) + source_query = source_query.join(DBSource.suites) \ + .filter(Suite.suite_id == source_suites.c.id) source = source_query.first() if source is None: raise ArchiveException('{0}: trying to install to {1}, but could not find source'.format(binary.hashed_file.filename, suite.suite_name)) @@ -381,8 +382,14 @@ class ArchiveTransaction(object): if archive.tainted: allow_tainted = True - # make sure built-using packages are present in target archive filename = db_binary.poolfile.filename + + # make sure source is present in target archive + db_source = db_binary.source + if session.query(ArchiveFile).filter_by(archive=archive, file=db_source.poolfile).first() is None: + raise ArchiveException('{0}: cannot copy to {1}: source is not present in target archive'.format(filename, suite.suite_name)) + + # make sure built-using packages are present in target archive for db_source in db_binary.extra_sources: self._ensure_extra_source_exists(filename, db_source, archive, extra_archives=extra_archives) @@ -628,6 +635,29 @@ class ArchiveUpload(object): suites = session.query(Suite).filter(Suite.suite_name.in_(suite_names)) return suites + def _mapped_component(self, component_name): + """get component after mappings + + Evaluate component mappings from ComponentMappings in dak.conf for the + given component name. + + NOTE: ansgar wants to get rid of this. It's currently only used for + the security archive + + Args: + component_name (str): component name + + Returns: + `daklib.dbconn.Component` object + """ + cnf = Config() + for m in cnf.value_list("ComponentMappings"): + (src, dst) = m.split() + if component_name == src: + component_name = dst + component = self.session.query(Component).filter_by(component_name=component_name).one() + return component + def _check_new(self, suite): """Check if upload is NEW @@ -692,7 +722,7 @@ class ArchiveUpload(object): daklib.dbconn.Override or None """ if suite.overridesuite is not None: - suite = session.query(Suite).filter_by(suite_name=suite.overridesuite).one() + suite = self.session.query(Suite).filter_by(suite_name=suite.overridesuite).one() query = self.session.query(Override).filter_by(suite=suite, package=binary.control['Package']) \ .join(Component).filter(Component.component_name == binary.component) \ @@ -714,7 +744,7 @@ class ArchiveUpload(object): daklib.dbconn.Override or None """ if suite.overridesuite is not None: - suite = session.query(Suite).filter_by(suite_name=suite.overridesuite).one() + 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']) \ @@ -725,6 +755,30 @@ class ArchiveUpload(object): except NoResultFound: return None + def _binary_component(self, suite, binary, only_overrides=True): + """get component for a binary + + By default this will only look at overrides to get the right component; + if `only_overrides` is False this method will also look at the Section field. + + Args: + suite (daklib.dbconn.Suite) + binary (daklib.upload.Binary) + + Kwargs: + only_overrides (bool): only use overrides to get the right component. + defaults to True. + + Returns: + `daklib.dbconn.Component` object or None + """ + override = self._binary_override(suite, binary) + if override is not None: + return override.component + if only_overrides: + return None + return self._mapped_component(binary.component) + def check(self, force=False): """run checks against the upload @@ -741,9 +795,11 @@ class ArchiveUpload(object): for chk in ( checks.SignatureCheck, checks.ChangesCheck, + checks.UploadBlockCheck, checks.HashesCheck, checks.SourceCheck, checks.BinaryCheck, + checks.BinaryTimestampCheck, checks.ACLCheck, checks.SingleDistributionCheck, checks.NoSourceOnlyCheck, @@ -802,7 +858,7 @@ class ArchiveUpload(object): changed_by = get_or_set_maintainer(control.get('Changed-By', control['Maintainer']), self.session) if source_suites is None: - source_suites = self.session.query(Suite).join(VersionCheck, VersionCheck.reference_id == Suite.suite_id).filter(VersionCheck.suite == suite).subquery() + source_suites = self.session.query(Suite).join((VersionCheck, VersionCheck.reference_id == Suite.suite_id)).filter(VersionCheck.suite == suite).subquery() source = self.changes.source if source is not None: @@ -898,7 +954,13 @@ class ArchiveUpload(object): remaining = [] for f in byhand: - package, version, archext = f.filename.split('_', 2) + parts = f.filename.split('_', 2) + if len(parts) != 3: + print "W: unexpected byhand filename {0}. No automatic processing.".format(f.filename) + remaining.append(f) + continue + + package, version, archext = parts arch, ext = archext.split('.', 1) rule = automatic_byhand_packages.get(package) @@ -970,6 +1032,11 @@ class ArchiveUpload(object): print >>debinfo, line debinfo.close() + def _policy_queue(self, suite): + if suite.policy_queue is not None: + return suite.policy_queue + return None + def install(self): """install upload @@ -990,20 +1057,22 @@ class ArchiveUpload(object): if suite.overridesuite is not None: overridesuite = self.session.query(Suite).filter_by(suite_name=suite.overridesuite).one() + policy_queue = self._policy_queue(suite) + redirected_suite = suite - if suite.policy_queue is not None: - redirected_suite = suite.policy_queue.suite + if policy_queue is not None: + redirected_suite = policy_queue.suite source_component_func = lambda source: self._source_override(overridesuite, source).component - binary_component_func = lambda binary: self._binary_override(overridesuite, binary).component + binary_component_func = lambda binary: self._binary_component(overridesuite, binary) (db_source, db_binaries) = self._install_to_suite(redirected_suite, source_component_func, binary_component_func, extra_source_archives=[suite.archive]) - if suite.policy_queue is not None: - self._install_policy(suite.policy_queue, suite, db_changes, db_source, db_binaries) + if policy_queue is not None: + self._install_policy(policy_queue, suite, db_changes, db_source, db_binaries) # copy to build queues - if suite.policy_queue is None or suite.policy_queue.send_to_build_queues: + if policy_queue is None or policy_queue.send_to_build_queues: for build_queue in suite.copy_queues: self._install_to_suite(build_queue.suite, source_component_func, binary_component_func, extra_source_archives=[suite.archive]) @@ -1037,12 +1106,7 @@ class ArchiveUpload(object): suite = suites[0] def binary_component_func(binary): - override = self._binary_override(suite, binary) - if override is not None: - return override.component - component_name = binary.component - component = self.session.query(Component).filter_by(component_name=component_name).one() - return component + return self._binary_component(suite, binary, only_overrides=False) # guess source component # XXX: should be moved into an extra method @@ -1051,7 +1115,8 @@ class ArchiveUpload(object): component = binary_component_func(binary) binary_component_names.add(component.component_name) source_component_name = None - for guess in ('main', 'contrib', 'non-free'): + for c in self.session.query(Component).order_by(Component.component_id): + guess = c.component_name if guess in binary_component_names: source_component_name = guess break