From: Mark Hymers Date: Wed, 23 Mar 2011 18:33:54 +0000 (+0000) Subject: Merge remote branch 'ftpmaster/master' into psimport X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=b8690d6b1256a4a95198b874d9eb1aab62a825fb;hp=-c;p=dak.git Merge remote branch 'ftpmaster/master' into psimport Conflicts: daklib/dbconn.py Signed-off-by: Mark Hymers --- b8690d6b1256a4a95198b874d9eb1aab62a825fb diff --combined daklib/dbconn.py index 79e0621b,6782c081..4d30e663 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@@ -61,6 -61,8 +61,8 @@@ from sqlalchemy import create_engine, T from sqlalchemy.orm import sessionmaker, mapper, relation, object_session, \ backref, MapperExtension, EXT_CONTINUE, object_mapper, clear_mappers from sqlalchemy import types as sqltypes + from sqlalchemy.orm.collections import attribute_mapped_collection + from sqlalchemy.ext.associationproxy import association_proxy # Don't remove this, we re-export the exceptions to scripts which import us from sqlalchemy.exc import * @@@ -499,6 -501,8 +501,8 @@@ class DBBinary(ORMObject) return ['package', 'version', 'maintainer', 'source', 'poolfile', \ 'binarytype'] + metadata = association_proxy('key', 'value') + def get_component_name(self): return self.poolfile.location.component.component_name @@@ -525,25 -529,6 +529,25 @@@ dpkg.stdout.close() dpkg.wait() + def read_control(self): + ''' + Reads the control information from a binary. + + @rtype: tuple + @return: (stanza, controldict) stanza is the text of the control + section. controldict is the information in a dictionary + form + ''' + import apt_inst, apt_pk + fullpath = self.poolfile.fullpath + deb_file = open(fullpath, 'r') + stanza = apt_inst.debExtractControl(deb_file).rstrip() + control = dict(apt_pkg.TagSection(stanza)) + deb_file.close() + + return stanza, control + + __all__.append('DBBinary') @session_wrapper @@@ -2191,20 -2176,8 +2195,22 @@@ class DBSource(ORMObject) return ['source', 'version', 'install_date', 'maintainer', \ 'changedby', 'poolfile', 'install_date'] + def read_control(self): + ''' + Reads the control information from a dsc + + @rtype: tuple + @return: (stanza, controldict) stanza is the text of the control + section. controldict is the information in a dictionary + form + ''' + from debian.debfile import Deb822 + fullpath = self.poolfile.fullpath + fields = Deb822(open(self.poolfile.fullpath, 'r')) + return fields + + metadata = association_proxy('key', 'value') + __all__.append('DBSource') @session_wrapper @@@ -2850,10 -2823,10 +2856,10 @@@ __all__.append('MetadataKey' ################################################################################ class BinaryMetadata(ORMObject): - def __init__(self, binary = None, key = None, value = None): - self.binary = binary + def __init__(self, key = None, value = None, binary = None): self.key = key self.value = value + self.binary = binary def properties(self): return ['binary', 'key', 'value'] @@@ -2866,10 -2839,10 +2872,10 @@@ __all__.append('BinaryMetadata' ################################################################################ class SourceMetadata(ORMObject): - def __init__(self, source = None, key = None, value = None): - self.source = source + def __init__(self, key = None, value = None, source = None): self.key = key self.value = value + self.source = source def properties(self): return ['source', 'key', 'value'] @@@ -3018,7 -2991,9 +3024,9 @@@ class DBConn(object) suites = relation(Suite, secondary=self.tbl_bin_associations, backref=backref('binaries', lazy='dynamic')), extra_sources = relation(DBSource, secondary=self.tbl_extra_src_references, - backref=backref('extra_binary_references', lazy='dynamic'))), + backref=backref('extra_binary_references', lazy='dynamic')), + key = relation(BinaryMetadata, cascade='all', + collection_class=attribute_mapped_collection('key'))), extension = validator) mapper(BinaryACL, self.tbl_binary_acl, @@@ -3188,7 -3163,9 +3196,9 @@@ primaryjoin=(self.tbl_source.c.id==self.tbl_dsc_files.c.source)), suites = relation(Suite, secondary=self.tbl_src_associations, backref=backref('sources', lazy='dynamic')), - srcuploaders = relation(SrcUploader)), + srcuploaders = relation(SrcUploader), + key = relation(SourceMetadata, cascade='all', + collection_class=attribute_mapped_collection('key'))), extension = validator) mapper(SourceACL, self.tbl_source_acl,