X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fdbconn.py;h=47b933e43728bafe73850a4922ab429cc8a0cc92;hb=1549379cef7c649ab3b65f7b44baaddef9339c08;hp=2237099d75eb296c44b95e478357c6d76ab82031;hpb=b8f3795c314213197754bd476cc43c5dc2bb0b8d;p=dak.git diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 2237099d..47b933e4 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -53,7 +53,8 @@ from tempfile import mkstemp, mkdtemp from inspect import getargspec import sqlalchemy -from sqlalchemy import create_engine, Table, MetaData, Column, Integer, desc +from sqlalchemy import create_engine, Table, MetaData, Column, Integer, desc, \ + Text, ForeignKey from sqlalchemy.orm import sessionmaker, mapper, relation, object_session, \ backref, MapperExtension, EXT_CONTINUE, object_mapper from sqlalchemy import types as sqltypes @@ -465,12 +466,13 @@ __all__.append('get_archive') ################################################################################ -class BinContents(object): - def __init__(self, *args, **kwargs): - pass +class BinContents(ORMObject): + def __init__(self, file = None, binary = None): + self.file = file + self.binary = binary - def __repr__(self): - return '' % (self.binary, self.filename) + def properties(self): + return ['file', 'binary'] __all__.append('BinContents') @@ -491,7 +493,7 @@ class DBBinary(ORMObject): def properties(self): return ['package', 'version', 'maintainer', 'source', 'architecture', \ 'poolfile', 'binarytype', 'fingerprint', 'install_date', \ - 'suites_count', 'binary_id'] + 'suites_count', 'binary_id', 'contents_count'] def not_null_constraints(self): return ['package', 'version', 'maintainer', 'source', 'poolfile', \ @@ -1871,12 +1873,15 @@ __all__.append('get_override') ################################################################################ -class OverrideType(object): - def __init__(self, *args, **kwargs): - pass +class OverrideType(ORMObject): + def __init__(self, overridetype = None): + self.overridetype = overridetype - def __repr__(self): - return '' % self.overridetype + def properties(self): + return ['overridetype', 'overridetype_id', 'overrides_count'] + + def not_null_constraints(self): + return ['overridetype'] __all__.append('OverrideType') @@ -2143,9 +2148,15 @@ __all__.append('get_priorities') ################################################################################ -class Section(object): - def __init__(self, *args, **kwargs): - pass +class Section(ORMObject): + def __init__(self, section = None): + self.section = section + + def properties(self): + return ['section', 'section_id', 'overrides_count'] + + def not_null_constraints(self): + return ['section'] def __eq__(self, val): if isinstance(val, str): @@ -2159,9 +2170,6 @@ class Section(object): # This signals to use the normal comparison operator return NotImplemented - def __repr__(self): - return '
' % self.section - __all__.append('Section') @session_wrapper @@ -2874,7 +2882,9 @@ class DBConn(object): 'binary_acl', 'binary_acl_map', 'build_queue', + 'build_queue_files', 'changelogs_text', + 'changes', 'component', 'config', 'changes_pending_binaries', @@ -2901,15 +2911,9 @@ class DBConn(object): 'suite', 'uid', 'upload_blocks', - # The following tables have primary keys but sqlalchemy - # version 0.5 fails to reflect them correctly with database - # versions before upgrade #41. - #'changes', - #'build_queue_files', ) tables_no_primary = ( - 'bin_contents', 'changes_pending_files_map', 'changes_pending_source_files', 'changes_pool_files', @@ -2919,9 +2923,6 @@ class DBConn(object): 'suite_src_formats', 'suite_build_queue_copy', 'udeb_contents', - # see the comment above - 'changes', - 'build_queue_files', ) views = ( @@ -2961,6 +2962,14 @@ class DBConn(object): table = Table(table_name, self.db_meta, autoload=True) setattr(self, 'tbl_%s' % table_name, table) + # bin_contents needs special attention until update #41 has been + # applied + self.tbl_bin_contents = Table('bin_contents', self.db_meta, \ + Column('file', Text, primary_key = True), + Column('binary_id', Integer, ForeignKey('binaries.id'), \ + primary_key = True), + autoload=True, useexisting=True) + for view_name in views: view = Table(view_name, self.db_meta, autoload=True) setattr(self, 'view_%s' % view_name, view) @@ -3160,9 +3169,11 @@ class DBConn(object): priority_id = self.tbl_override.c.priority, priority = relation(Priority), section_id = self.tbl_override.c.section, - section = relation(Section), + section = relation(Section, \ + backref=backref('overrides', lazy='dynamic')), overridetype_id = self.tbl_override.c.type, - overridetype = relation(OverrideType))) + overridetype = relation(OverrideType, \ + backref=backref('overrides', lazy='dynamic')))) mapper(OverrideType, self.tbl_override_type, properties = dict(overridetype = self.tbl_override_type.c.type, @@ -3233,6 +3244,12 @@ class DBConn(object): fingerprint = relation(Fingerprint, backref="uploadblocks"), uid = relation(Uid, backref="uploadblocks"))) + mapper(BinContents, self.tbl_bin_contents, + properties = dict( + binary = relation(DBBinary, + backref=backref('contents', lazy='dynamic')), + file = self.tbl_bin_contents.c.file)) + ## Connection functions def __createconn(self): from config import Config