X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=daklib%2Fdbconn.py;h=9cdf3f8e12a565a7954886d2da9478179ececc18;hb=8330a7659bc2794ef98285fa0034400af0fa1ebf;hp=837ce8e47b39dfe270d9a70b0f9a2eeed8395a35;hpb=b114f8978208938ea05cf2e3c69e84740cedb831;p=dak.git diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 837ce8e4..9cdf3f8e 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -443,12 +443,26 @@ __all__.append('BinContents') ################################################################################ -class DBBinary(object): - def __init__(self, *args, **kwargs): - pass +class DBBinary(ORMObject): + def __init__(self, package = None, source = None, version = None, \ + maintainer = None, architecture = None, poolfile = None, \ + binarytype = 'deb'): + self.package = package + self.source = source + self.version = version + self.maintainer = maintainer + self.architecture = architecture + self.poolfile = poolfile + self.binarytype = binarytype - def __repr__(self): - return '' % (self.package, self.version, self.architecture) + def properties(self): + return ['package', 'version', 'maintainer', 'source', 'architecture', \ + 'poolfile', 'binarytype', 'fingerprint', 'install_date', \ + 'suites_count'] + + def not_null_constraints(self): + return ['package', 'version', 'maintainer', 'source', 'poolfile', \ + 'binarytype'] __all__.append('DBBinary') @@ -464,7 +478,7 @@ def get_suites_binary_in(package, session=None): @return: list of Suite objects for the given package """ - return session.query(Suite).join(BinAssociation).join(DBBinary).filter_by(package=package).all() + return session.query(Suite).filter(Suite.binaries.any(DBBinary.package == package)).all() __all__.append('get_suites_binary_in') @@ -1243,7 +1257,7 @@ class PoolFile(ORMObject): def properties(self): return ['filename', 'file_id', 'filesize', 'md5sum', 'sha1sum', \ - 'sha256sum', 'location', 'source', 'last_used'] + 'sha256sum', 'location', 'source', 'binary', 'last_used'] def not_null_constraints(self): return ['filename', 'md5sum', 'location'] @@ -2257,7 +2271,7 @@ class DBSource(ORMObject): def properties(self): return ['source', 'source_id', 'maintainer', 'changedby', \ 'fingerprint', 'poolfile', 'version', 'suites_count', \ - 'install_date'] + 'install_date', 'binaries_count'] def not_null_constraints(self): return ['source', 'version', 'install_date', 'maintainer', \ @@ -2558,14 +2572,10 @@ def add_deb_to_db(u, filename, session=None): # Add and flush object so it has an ID session.add(bin) - session.flush() - # Add BinAssociations - for suite_name in u.pkg.changes["distribution"].keys(): - ba = BinAssociation() - ba.binary_id = bin.binary_id - ba.suite_id = get_suite(suite_name).suite_id - session.add(ba) + suite_names = u.pkg.changes["distribution"].keys() + bin.suites = session.query(Suite). \ + filter(Suite.suite_name.in_(suite_names)).all() session.flush() @@ -2639,7 +2649,7 @@ class Suite(ORMObject): self.version = version def properties(self): - return ['suite_name', 'version'] + return ['suite_name', 'version', 'sources_count', 'binaries_count'] def not_null_constraints(self): return ['suite_name', 'version'] @@ -2802,7 +2812,7 @@ __all__.append('get_suite_src_formats') ################################################################################ -class Uid(object): +class Uid(ORMObject): def __init__(self, uid = None, name = None): self.uid = uid self.name = name @@ -2819,8 +2829,11 @@ class Uid(object): # This signals to use the normal comparison operator return NotImplemented - def __repr__(self): - return '' % (self.uid, self.name) + def properties(self): + return ['uid', 'name', 'fingerprint'] + + def not_null_constraints(self): + return ['uid'] __all__.append('Uid') @@ -3054,17 +3067,20 @@ class DBConn(object): maintainer_id = self.tbl_binaries.c.maintainer, maintainer = relation(Maintainer), source_id = self.tbl_binaries.c.source, - source = relation(DBSource), + source = relation(DBSource, backref='binaries'), arch_id = self.tbl_binaries.c.architecture, architecture = relation(Architecture), poolfile_id = self.tbl_binaries.c.file, - poolfile = relation(PoolFile), + poolfile = relation(PoolFile, backref=backref('binary', uselist = False)), binarytype = self.tbl_binaries.c.type, fingerprint_id = self.tbl_binaries.c.sig_fpr, 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)))) + primaryjoin=(self.tbl_binaries.c.id==self.tbl_bin_associations.c.bin))), + extension = validator) mapper(BinaryACL, self.tbl_binary_acl, properties = dict(binary_acl_id = self.tbl_binary_acl.c.id)) @@ -3226,7 +3242,7 @@ class DBConn(object): srcfiles = relation(DSCFile, primaryjoin=(self.tbl_source.c.id==self.tbl_dsc_files.c.source)), suites = relation(Suite, secondary=self.tbl_src_associations, - backref='sources'), + backref=backref('sources', lazy='dynamic')), srcuploaders = relation(SrcUploader)), extension = validator) @@ -3261,7 +3277,8 @@ class DBConn(object): mapper(Uid, self.tbl_uid, properties = dict(uid_id = self.tbl_uid.c.id, - fingerprint = relation(Fingerprint))) + fingerprint = relation(Fingerprint)), + extension = validator) mapper(UploadBlock, self.tbl_upload_blocks, properties = dict(upload_block_id = self.tbl_upload_blocks.c.id,