From: Ansgar Burchardt Date: Sat, 13 Jun 2015 12:53:28 +0000 (+0200) Subject: Merge remote-tracking branch 'nthykier/auto-decruft' X-Git-Url: https://git.decadent.org.uk/gitweb/?p=dak.git;a=commitdiff_plain;h=05c66ff1004719368eb7dc54a4db1d632e8930a1;hp=03a86547e5d9b209016cc0b23f825d3baea92f8c Merge remote-tracking branch 'nthykier/auto-decruft' --- diff --git a/dak/clean_queues.py b/dak/clean_queues.py index 88b0bb93..209591ac 100755 --- a/dak/clean_queues.py +++ b/dak/clean_queues.py @@ -39,7 +39,6 @@ import apt_pkg from daklib import utils from daklib import daklog from daklib.config import Config -from daklib.dbconn import get_policy_queue ################################################################################ diff --git a/dak/process_upload.py b/dak/process_upload.py index 9eb23f00..d5425e05 100755 --- a/dak/process_upload.py +++ b/dak/process_upload.py @@ -297,7 +297,6 @@ def accept(directory, upload): @try_or_reject def accept_to_new(directory, upload): - cnf = Config() Logger.log(['ACCEPT-TO-NEW', upload.changes.filename]) print "ACCEPT-TO-NEW" @@ -379,8 +378,6 @@ def action(directory, upload): if Options["No-Action"] or Options["Automatic"]: answer = 'S' - queuekey = '' - print summary print print "\n".join(package_info) @@ -454,7 +451,7 @@ def unlink_if_exists(path): if e.errno != errno.ENOENT: raise -def process_it(directory, changes, keyrings, session): +def process_it(directory, changes, keyrings): global Logger print "\n{0}\n".format(changes.filename) @@ -480,6 +477,7 @@ def process_changes(changes_filenames): session = DBConn().session() keyrings = session.query(Keyring).filter_by(active=True).order_by(Keyring.priority) keyring_files = [ k.keyring_name for k in keyrings ] + session.close() changes = [] for fn in changes_filenames: @@ -493,9 +491,7 @@ def process_changes(changes_filenames): changes.sort(key=lambda x: x[1]) for directory, c in changes: - process_it(directory, c, keyring_files, session) - - session.rollback() + process_it(directory, c, keyring_files) ############################################################################### diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 432ddf8a..a599e5c1 100644 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -745,201 +745,6 @@ __all__.append('DBConfig') ################################################################################ -@session_wrapper -def get_or_set_contents_file_id(filename, session=None): - """ - Returns database id for given filename. - - If no matching file is found, a row is inserted. - - @type filename: string - @param filename: The filename - @type session: SQLAlchemy - @param session: Optional SQL session object (a temporary one will be - generated if not supplied). If not passed, a commit will be performed at - the end of the function, otherwise the caller is responsible for commiting. - - @rtype: int - @return: the database id for the given component - """ - - q = session.query(ContentFilename).filter_by(filename=filename) - - try: - ret = q.one().cafilename_id - except NoResultFound: - cf = ContentFilename() - cf.filename = filename - session.add(cf) - session.commit_or_flush() - ret = cf.cafilename_id - - return ret - -__all__.append('get_or_set_contents_file_id') - -@session_wrapper -def get_contents(suite, overridetype, section=None, session=None): - """ - Returns contents for a suite / overridetype combination, limiting - to a section if not None. - - @type suite: Suite - @param suite: Suite object - - @type overridetype: OverrideType - @param overridetype: OverrideType object - - @type section: Section - @param section: Optional section object to limit results to - - @type session: SQLAlchemy - @param session: Optional SQL session object (a temporary one will be - generated if not supplied) - - @rtype: ResultsProxy - @return: ResultsProxy object set up to return tuples of (filename, section, - package, arch_id) - """ - - # find me all of the contents for a given suite - contents_q = """SELECT (p.path||'/'||n.file) AS fn, - s.section, - b.package, - b.architecture - FROM content_associations c join content_file_paths p ON (c.filepath=p.id) - JOIN content_file_names n ON (c.filename=n.id) - JOIN binaries b ON (b.id=c.binary_pkg) - JOIN override o ON (o.package=b.package) - JOIN section s ON (s.id=o.section) - WHERE o.suite = :suiteid AND o.type = :overridetypeid - AND b.type=:overridetypename""" - - vals = {'suiteid': suite.suite_id, - 'overridetypeid': overridetype.overridetype_id, - 'overridetypename': overridetype.overridetype} - - if section is not None: - contents_q += " AND s.id = :sectionid" - vals['sectionid'] = section.section_id - - contents_q += " ORDER BY fn" - - return session.execute(contents_q, vals) - -__all__.append('get_contents') - -################################################################################ - -class ContentFilepath(object): - def __init__(self, *args, **kwargs): - pass - - def __repr__(self): - return '' % self.filepath - -__all__.append('ContentFilepath') - -@session_wrapper -def get_or_set_contents_path_id(filepath, session=None): - """ - Returns database id for given path. - - If no matching file is found, a row is inserted. - - @type filepath: string - @param filepath: The filepath - - @type session: SQLAlchemy - @param session: Optional SQL session object (a temporary one will be - generated if not supplied). If not passed, a commit will be performed at - the end of the function, otherwise the caller is responsible for commiting. - - @rtype: int - @return: the database id for the given path - """ - - q = session.query(ContentFilepath).filter_by(filepath=filepath) - - try: - ret = q.one().cafilepath_id - except NoResultFound: - cf = ContentFilepath() - cf.filepath = filepath - session.add(cf) - session.commit_or_flush() - ret = cf.cafilepath_id - - return ret - -__all__.append('get_or_set_contents_path_id') - -################################################################################ - -class ContentAssociation(object): - def __init__(self, *args, **kwargs): - pass - - def __repr__(self): - return '' % self.ca_id - -__all__.append('ContentAssociation') - -def insert_content_paths(binary_id, fullpaths, session=None): - """ - Make sure given path is associated with given binary id - - @type binary_id: int - @param binary_id: the id of the binary - @type fullpaths: list - @param fullpaths: the list of paths of the file being associated with the binary - @type session: SQLAlchemy session - @param session: Optional SQLAlchemy session. If this is passed, the caller - is responsible for ensuring a transaction has begun and committing the - results or rolling back based on the result code. If not passed, a commit - will be performed at the end of the function, otherwise the caller is - responsible for commiting. - - @return: True upon success - """ - - privatetrans = False - if session is None: - session = DBConn().session() - privatetrans = True - - try: - # Insert paths - def generate_path_dicts(): - for fullpath in fullpaths: - if fullpath.startswith( './' ): - fullpath = fullpath[2:] - - yield {'filename':fullpath, 'id': binary_id } - - for d in generate_path_dicts(): - session.execute( "INSERT INTO bin_contents ( file, binary_id ) VALUES ( :filename, :id )", - d ) - - session.commit() - if privatetrans: - session.close() - return True - - except: - traceback.print_exc() - - # Only rollback if we set up the session ourself - if privatetrans: - session.rollback() - session.close() - - return False - -__all__.append('insert_content_paths') - -################################################################################ - class DSCFile(object): def __init__(self, *args, **kwargs): pass @@ -1051,25 +856,6 @@ class PoolFile(ORMObject): __all__.append('PoolFile') -@session_wrapper -def get_poolfile_like_name(filename, session=None): - """ - Returns an array of PoolFile objects which are like the given name - - @type filename: string - @param filename: the filename of the file to check against the DB - - @rtype: array - @return: array of PoolFile objects - """ - - # TODO: There must be a way of properly using bind parameters with %FOO% - q = session.query(PoolFile).filter(PoolFile.filename.like('%%/%s' % filename)) - - return q.all() - -__all__.append('get_poolfile_like_name') - ################################################################################ class Fingerprint(ORMObject): @@ -1324,24 +1110,6 @@ def get_active_keyring_paths(session=None): __all__.append('get_active_keyring_paths') -@session_wrapper -def get_primary_keyring_path(session=None): - """ - Get the full path to the highest priority active keyring - - @rtype: str or None - @return: path to the active keyring with the highest priority or None if no - keyring is configured - """ - keyrings = get_active_keyring_paths() - - if len(keyrings) > 0: - return keyrings[0] - else: - return None - -__all__.append('get_primary_keyring_path') - ################################################################################ class DBChange(object): @@ -1990,61 +1758,6 @@ class DBSource(ORMObject): __all__.append('DBSource') -@session_wrapper -def source_exists(source, source_version, suites = ["any"], session=None): - """ - Ensure that source exists somewhere in the archive for the binary - upload being processed. - 1. exact match => 1.0-3 - 2. bin-only NMU => 1.0-3+b1 , 1.0-3.1+b1 - - @type source: string - @param source: source name - - @type source_version: string - @param source_version: expected source version - - @type suites: list - @param suites: list of suites to check in, default I{any} - - @type session: Session - @param session: Optional SQLA session object (a temporary one will be - generated if not supplied) - - @rtype: int - @return: returns 1 if a source with expected version is found, otherwise 0 - - """ - - cnf = Config() - ret = True - - from daklib.regexes import re_bin_only_nmu - orig_source_version = re_bin_only_nmu.sub('', source_version) - - for suite in suites: - q = session.query(DBSource).filter_by(source=source). \ - filter(DBSource.version.in_([source_version, orig_source_version])) - if suite != "any": - # source must exist in 'suite' or a suite that is enhanced by 'suite' - s = get_suite(suite, session) - if s: - enhances_vcs = session.query(VersionCheck).filter(VersionCheck.suite==s).filter_by(check='Enhances') - considered_suites = [ vc.reference for vc in enhances_vcs ] - considered_suites.append(s) - - q = q.filter(DBSource.suites.any(Suite.suite_id.in_([s.suite_id for s in considered_suites]))) - - if q.count() > 0: - continue - - # No source found so return not ok - ret = False - - return ret - -__all__.append('source_exists') - @session_wrapper def get_suites_source_in(source, session=None): """ @@ -2061,41 +1774,6 @@ def get_suites_source_in(source, session=None): __all__.append('get_suites_source_in') -@session_wrapper -def get_sources_from_name(source, version=None, dm_upload_allowed=None, session=None): - """ - Returns list of DBSource objects for given C{source} name and other parameters - - @type source: str - @param source: DBSource package name to search for - - @type version: str or None - @param version: DBSource version name to search for or None if not applicable - - @type dm_upload_allowed: bool - @param dm_upload_allowed: If None, no effect. If True or False, only - return packages with that dm_upload_allowed setting - - @type session: Session - @param session: Optional SQL session object (a temporary one will be - generated if not supplied) - - @rtype: list - @return: list of DBSource objects for the given name (may be empty) - """ - - q = session.query(DBSource).filter_by(source=source) - - if version is not None: - q = q.filter_by(version=version) - - if dm_upload_allowed is not None: - q = q.filter_by(dm_upload_allowed=dm_upload_allowed) - - return q.all() - -__all__.append('get_sources_from_name') - # FIXME: This function fails badly if it finds more than 1 source package and # its implementation is trivial enough to be inlined. @session_wrapper diff --git a/daklib/rm.py b/daklib/rm.py index 71fe792a..3a0a8f43 100644 --- a/daklib/rm.py +++ b/daklib/rm.py @@ -77,18 +77,18 @@ class ReverseDependencyChecker(object): self._session = session dbsuite = get_suite(suite, session) suite_archs2id = dict((x.arch_string, x.arch_id) for x in get_suite_architectures(suite)) - package_dependencies, arch_providors_of, arch_provided_by = self._load_package_information(session, + package_dependencies, arch_providers_of, arch_provided_by = self._load_package_information(session, dbsuite.suite_id, suite_archs2id) self._package_dependencies = package_dependencies - self._arch_providors_of = arch_providors_of + self._arch_providers_of = arch_providers_of self._arch_provided_by = arch_provided_by self._archs_in_suite = set(suite_archs2id) @staticmethod def _load_package_information(session, suite_id, suite_archs2id): package_dependencies = defaultdict(lambda: defaultdict(set)) - arch_providors_of = defaultdict(lambda: defaultdict(set)) + arch_providers_of = defaultdict(lambda: defaultdict(set)) arch_provided_by = defaultdict(lambda: defaultdict(set)) source_deps = defaultdict(set) metakey_d = get_or_set_metadatakey("Depends", session) @@ -108,7 +108,7 @@ class ReverseDependencyChecker(object): deps = defaultdict(set) providers_of = defaultdict(set) provided_by = defaultdict(set) - arch_providors_of[architecture] = providers_of + arch_providers_of[architecture] = providers_of arch_provided_by[architecture] = provided_by package_dependencies[architecture] = deps @@ -177,7 +177,7 @@ class ReverseDependencyChecker(object): except ValueError as e: print "Error for package %s: %s" % (source, e) - return package_dependencies, arch_providors_of, arch_provided_by + return package_dependencies, arch_providers_of, arch_provided_by def check_reverse_depends(self, removal_requests): """Bulk check reverse dependencies @@ -205,7 +205,7 @@ class ReverseDependencyChecker(object): removals_by_arch = defaultdict(set) affected_virtual_by_arch = defaultdict(set) package_dependencies = self._package_dependencies - arch_providors_of = self._arch_providors_of + arch_providers_of = self._arch_providers_of arch_provided_by = self._arch_provided_by arch_provides2removal = defaultdict(lambda: defaultdict(set)) dep_problems = defaultdict(set) @@ -227,7 +227,7 @@ class ReverseDependencyChecker(object): arch_all_removals.add(pkg) continue removals_by_arch[arch].add(pkg) - if pkg in arch_providors_of[arch]: + if pkg in arch_providers_of[arch]: affected_virtual_by_arch[arch].add(pkg) if arch_all_removals: @@ -236,7 +236,7 @@ class ReverseDependencyChecker(object): continue removals_by_arch[arch].update(arch_all_removals) for pkg in arch_all_removals: - if pkg in arch_providors_of[arch]: + if pkg in arch_providers_of[arch]: affected_virtual_by_arch[arch].add(pkg) if not removals_by_arch: diff --git a/daklib/utils.py b/daklib/utils.py index 12798ab2..efae7756 100644 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -49,7 +49,7 @@ import daklib.config as config import daklib.daksubprocess from dbconn import DBConn, get_architecture, get_component, get_suite, \ get_override_type, Keyring, session_wrapper, \ - get_active_keyring_paths, get_primary_keyring_path, \ + get_active_keyring_paths, \ get_suite_architectures, get_or_set_metadatakey, DBSource, \ Component, Override, OverrideType from sqlalchemy import desc diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index 53b3c80f..82641270 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -113,10 +113,6 @@ class PackageTestCase(DBDakTestCase): self.assertEqual((False, self.file['sl_3.03-16.dsc']), \ check_poolfile('main/s/sl/sl_3.03-16.dsc', 0, 'deadbeef', \ contrib.location_id, self.session)) - # test get_poolfile_like_name() - self.assertEqual([self.file['sl_3.03-16.dsc']], \ - get_poolfile_like_name('sl_3.03-16.dsc', self.session)) - self.assertEqual([], get_poolfile_like_name('foobar', self.session)) def test_maintainers(self): ''' @@ -210,27 +206,6 @@ class PackageTestCase(DBDakTestCase): self.assertEqual(self.loc['main'].location_id, dsc_location_id) self.assertEqual([], pfs) - def test_source_exists(self): - 'test function source_exists()' - - hello = self.source['hello_2.2-2'] - self.assertTrue(source_exists(hello.source, hello.version, \ - suites = ['sid'], session = self.session)) - # binNMU - self.assertTrue(source_exists(hello.source, hello.version + '+b7', \ - suites = ['sid'], session = self.session)) - self.assertTrue(not source_exists(hello.source, hello.version, \ - suites = ['lenny', 'squeeze'], session = self.session)) - self.assertTrue(not source_exists(hello.source, hello.version, \ - suites = ['lenny', 'sid'], session = self.session)) - self.assertTrue(not source_exists(hello.source, hello.version, \ - suites = ['sid', 'lenny'], session = self.session)) - self.assertTrue(not source_exists(hello.source, '0815', \ - suites = ['sid'], session = self.session)) - # 'any' suite - self.assertTrue(source_exists(hello.source, hello.version, \ - session = self.session)) - def test_get_suite_version_by_source(self): 'test function get_suite_version_by_source()'