X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fdbconn.py;h=e1e21d2b2b1f10a386dd42c50460287d7e6c8f4d;hb=221c511735a22974ac5ee9e1d2d5d52bf29e263e;hp=9cdf3f8e12a565a7954886d2da9478179ececc18;hpb=8330a7659bc2794ef98285fa0034400af0fa1ebf;p=dak.git diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 9cdf3f8e..e1e21d2b 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -421,17 +421,6 @@ __all__.append('get_archive') ################################################################################ -class BinAssociation(object): - def __init__(self, *args, **kwargs): - pass - - def __repr__(self): - return '' % (self.ba_id, self.binary, self.suite) - -__all__.append('BinAssociation') - -################################################################################ - class BinContents(object): def __init__(self, *args, **kwargs): pass @@ -458,7 +447,7 @@ class DBBinary(ORMObject): def properties(self): return ['package', 'version', 'maintainer', 'source', 'architecture', \ 'poolfile', 'binarytype', 'fingerprint', 'install_date', \ - 'suites_count'] + 'suites_count', 'binary_id'] def not_null_constraints(self): return ['package', 'version', 'maintainer', 'source', 'poolfile', \ @@ -482,89 +471,6 @@ def get_suites_binary_in(package, session=None): __all__.append('get_suites_binary_in') -@session_wrapper -def get_binary_from_id(binary_id, session=None): - """ - Returns DBBinary object for given C{id} - - @type binary_id: int - @param binary_id: Id of the required binary - - @type session: Session - @param session: Optional SQLA session object (a temporary one will be - generated if not supplied) - - @rtype: DBBinary - @return: DBBinary object for the given binary (None if not present) - """ - - q = session.query(DBBinary).filter_by(binary_id=binary_id) - - try: - return q.one() - except NoResultFound: - return None - -__all__.append('get_binary_from_id') - -@session_wrapper -def get_binaries_from_name(package, version=None, architecture=None, session=None): - """ - Returns list of DBBinary objects for given C{package} name - - @type package: str - @param package: DBBinary package name to search for - - @type version: str or None - @param version: Version to search for (or None) - - @type architecture: str, list or None - @param architecture: Architectures to limit to (or None if no limit) - - @type session: Session - @param session: Optional SQL session object (a temporary one will be - generated if not supplied) - - @rtype: list - @return: list of DBBinary objects for the given name (may be empty) - """ - - q = session.query(DBBinary).filter_by(package=package) - - if version is not None: - q = q.filter_by(version=version) - - if architecture is not None: - if not isinstance(architecture, list): - architecture = [architecture] - q = q.join(Architecture).filter(Architecture.arch_string.in_(architecture)) - - ret = q.all() - - return ret - -__all__.append('get_binaries_from_name') - -@session_wrapper -def get_binaries_from_source_id(source_id, session=None): - """ - Returns list of DBBinary objects for given C{source_id} - - @type source_id: int - @param source_id: source_id to search for - - @type session: Session - @param session: Optional SQL session object (a temporary one will be - generated if not supplied) - - @rtype: list - @return: list of DBBinary objects for the given name (may be empty) - """ - - return session.query(DBBinary).filter_by(source_id=source_id).all() - -__all__.append('get_binaries_from_source_id') - @session_wrapper def get_binary_from_name_suite(package, suitename, session=None): ### For dak examine-package @@ -943,9 +849,9 @@ __all__.append('ChangePendingSource') ################################################################################ -class Component(object): - def __init__(self, *args, **kwargs): - pass +class Component(ORMObject): + def __init__(self, component_name = None): + self.component_name = component_name def __eq__(self, val): if isinstance(val, str): @@ -959,8 +865,12 @@ class Component(object): # This signals to use the normal comparison operator return NotImplemented - def __repr__(self): - return '' % self.component_name + def properties(self): + return ['component_name', 'component_id', 'description', 'location', \ + 'meets_dfsg'] + + def not_null_constraints(self): + return ['component_name'] __all__.append('Component') @@ -1666,9 +1576,12 @@ __all__.append('get_dbchange') ################################################################################ +# TODO: Why do we have a separate Location class? Can't it be fully integrated +# into class Component? class Location(ORMObject): - def __init__(self, path = None): + def __init__(self, path = None, component = None): self.path = path + self.component = component # the column 'type' should go away, see comment at mapper self.archive_type = 'pool' @@ -3022,13 +2935,6 @@ class DBConn(object): properties = dict(archive_id = self.tbl_archive.c.id, archive_name = self.tbl_archive.c.name)) - mapper(BinAssociation, self.tbl_bin_associations, - properties = dict(ba_id = self.tbl_bin_associations.c.id, - suite_id = self.tbl_bin_associations.c.suite, - suite = relation(Suite), - binary_id = self.tbl_bin_associations.c.bin, - binary = relation(DBBinary))) - mapper(PendingBinContents, self.tbl_pending_bin_contents, properties = dict(contents_id =self.tbl_pending_bin_contents.c.id, filename = self.tbl_pending_bin_contents.c.filename, @@ -3077,9 +2983,7 @@ class DBConn(object): fingerprint = relation(Fingerprint), install_date = self.tbl_binaries.c.install_date, suites = relation(Suite, secondary=self.tbl_bin_associations, - backref=backref('binaries', lazy='dynamic')), - binassociations = relation(BinAssociation, - primaryjoin=(self.tbl_binaries.c.id==self.tbl_bin_associations.c.bin))), + backref=backref('binaries', lazy='dynamic'))), extension = validator) mapper(BinaryACL, self.tbl_binary_acl, @@ -3092,7 +2996,8 @@ class DBConn(object): mapper(Component, self.tbl_component, properties = dict(component_id = self.tbl_component.c.id, - component_name = self.tbl_component.c.name)) + component_name = self.tbl_component.c.name), + extension = validator) mapper(DBConfig, self.tbl_config, properties = dict(config_id = self.tbl_config.c.id)) @@ -3184,7 +3089,8 @@ class DBConn(object): mapper(Location, self.tbl_location, properties = dict(location_id = self.tbl_location.c.id, component_id = self.tbl_location.c.component, - component = relation(Component), + component = relation(Component, \ + backref=backref('location', uselist = False)), archive_id = self.tbl_location.c.archive, archive = relation(Archive), # FIXME: the 'type' column is old cruft and