def remove_suite(conf, session, suite): logging.info('remove sticky suite %s from the archive...' % suite) db_suite = db_storage.lookup_db_suite(session, suite, sticky=True) if not db_suite: logging.error('sticky suite %s does not exist in DB, abort.' % suite) return sticky_suites = statistics.sticky_suites(session) if updater.STAGE_GC in conf['stages']: for package in session.query(Package) \ .join(Suite) \ .filter(Suite.suite == suite) \ .filter(Package.sticky): pkg = SourcePackage.from_db_model(package) other_suites = \ session.query(Suite.suite.distinct()) \ .filter(Suite.package_id == package.id) \ .filter(Suite.suite != suite) other_suites = [row[0] for row in other_suites] if not other_suites: if not conf['single_transaction']: with session.begin(): updater._rm_package(pkg, conf, session, db_package=package) else: updater._rm_package(pkg, conf, session, db_package=package) else: other_sticky_suites = [ s for s in other_suites if s in sticky_suites ] if not other_sticky_suites and not conf['dry_run']: # package is only listed in "live" suites, drop sticky flag logging.debug('clearing sticky bit on %s' % pkg) package.sticky = False suitemap = db_storage.lookup_suitemapping(session, package, suite) if suitemap and not conf['dry_run']: session.delete(suitemap) if not conf['dry_run']: session.delete(db_suite) _remove_stats_for(conf, session, suite) logging.info('sticky suite %s removed from the archive.' % suite)
def remove_suite(conf, session, suite): logging.info('remove sticky suite %s from the archive...' % suite) db_suite = db_storage.lookup_db_suite(session, suite, sticky=True) if not db_suite: logging.error('sticky suite %s does not exist in DB, abort.' % suite) return sticky_suites = statistics.sticky_suites(session) if updater.STAGE_GC in conf['stages']: for package in session.query(Package) \ .join(Suite) \ .filter(Suite.suite == suite) \ .filter(Package.sticky): pkg = SourcePackage.from_db_model(package) other_suites = \ session.query(Suite.suite.distinct()) \ .filter(Suite.package_id == package.id) \ .filter(Suite.suite != suite) other_suites = [row[0] for row in other_suites] if not other_suites: if not conf['single_transaction']: with session.begin(): updater._rm_package(pkg, conf, session, db_package=package) else: updater._rm_package(pkg, conf, session, db_package=package) else: other_sticky_suites = [s for s in other_suites if s in sticky_suites] if not other_sticky_suites and not conf['dry_run']: # package is only listed in "live" suites, drop sticky flag logging.debug('clearing sticky bit on %s' % pkg) package.sticky = False suitemap = db_storage.lookup_suitemapping(session, package, suite) if suitemap and not conf['dry_run']: session.delete(suitemap) if not conf['dry_run']: session.delete(db_suite) _remove_stats_for(conf, session, suite) logging.info('sticky suite %s removed from the archive.' % suite)
def add_suite(conf, session, suite, archive): logging.info('add sticky suite %s to the archive...' % suite) db_suite = db_storage.lookup_db_suite(session, suite, sticky=True) if not db_suite: if updater.STAGE_EXTRACT in conf['stages']: updater._add_suite(conf, session, suite, sticky=True) else: logging.warn('sticky suite %s already exist, looking for new packages' % suite) if updater.STAGE_EXTRACT in conf['stages']: for pkg in archive.ls(suite): db_package = db_storage.lookup_package(session, pkg['package'], pkg['version']) if db_package: # avoid GC upon removal from a non-sticky suite if not db_package.sticky and not conf['dry_run']: logging.debug('setting sticky bit on %s' % pkg) db_package.sticky = True else: if not conf['single_transaction']: with session.begin(): updater._add_package(pkg, conf, session, sticky=True) else: updater._add_package(pkg, conf, session, sticky=True) session.flush() # to fill Package.id-s if updater.STAGE_SUITES in conf['stages']: suitemap_q = sql.insert(Suite.__table__) suitemaps = [] for (pkg, version) in archive.suites[suite]: db_package = db_storage.lookup_package(session, pkg, version) if not db_package: logging.warn('package %s/%s not found in sticky suite' ' %s, skipping' % (pkg, version, suite)) continue if not db_storage.lookup_suitemapping(session, db_package, suite): suitemaps.append({'package_id': db_package.id, 'suite': suite}) if suitemaps and not conf['dry_run']: session.execute(suitemap_q, suitemaps) _add_stats_for(conf, session, suite) logging.info('sticky suite %s added to the archive.' % suite)
def addsStickySuites(self): SUITES = ['hamm', 'slink'] PACKAGES = [('3dchess', '0.8.1-3'), # hamm ('ed', '0.2-16'), # hamm ('WMRack', '1.0b3-1')] # slink, pkg w/ weird naming for suite in SUITES: archiver.add_suite(self.conf, self.session, suite, self.archive) for suite in SUITES: self.assertHasStickySuite(suite) s = db_storage.lookup_db_suite(self.session, suite, sticky=True) rel_info = DEBIAN_RELEASES[suite] self.assertEqual(s.version, rel_info['version']) self.assertEqual(s.release_date, rel_info['date']) for pkg in PACKAGES: self.assertHasStickyPackage(*pkg)
def addsStickySuites(self): SUITES = ["hamm", "slink"] PACKAGES = [ ("3dchess", "0.8.1-3"), # hamm ("ed", "0.2-16"), # hamm ("WMRack", "1.0b3-1"), ] # slink, pkg w/ weird naming for suite in SUITES: archiver.add_suite(self.conf, self.session, suite, self.archive) for suite in SUITES: self.assertHasStickySuite(suite) s = db_storage.lookup_db_suite(self.session, suite, sticky=True) rel_info = DEBIAN_RELEASES[suite] self.assertEqual(s.version, rel_info["version"]) self.assertEqual(s.release_date, rel_info["date"]) for pkg in PACKAGES: self.assertHasStickyPackage(*pkg)
def assertLacksStickySuite(self, suite): s = db_storage.lookup_db_suite(self.session, suite, sticky=True) self.assertIsNone(s, msg='present sticky suite ' + suite)
def assertHasStickySuite(self, suite): s = db_storage.lookup_db_suite(self.session, suite, sticky=True) self.assertIsNotNone(s, msg='missing sticky suite ' + suite)