X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fdbconn.py;h=fb2cc3b0d6a91808df8d393fd41edf884dc922dc;hb=f4d0cfd8845073f82513a5e1a1c08f7b6ec0d2e2;hp=aab025136f0b35139f6f1ef590d52b11ea921cb8;hpb=759d4478ec33ec1721d1eb24b1de4e8b5b56dd5d;p=dak.git diff --git a/daklib/dbconn.py b/daklib/dbconn.py index aab02513..fb2cc3b0 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -508,18 +508,25 @@ class DBBinary(ORMObject): def scan_contents(self): ''' Yields the contents of the package. Only regular files are yielded and - the path names are normalized after converting them from iso8859-1 - encoding. + the path names are normalized after converting them from either utf-8 + or iso8859-1 encoding. It yields the string ' ' if the + package does not contain any regular file. ''' fullpath = self.poolfile.fullpath - debdata = Popen(['dpkg-deb', '--fsys-tarfile', fullpath], - stdout = PIPE).stdout - tar = TarFile.open(fileobj = debdata, mode = 'r|') + dpkg = Popen(['dpkg-deb', '--fsys-tarfile', fullpath], stdout = PIPE) + tar = TarFile.open(fileobj = dpkg.stdout, mode = 'r|') for member in tar.getmembers(): - if member.isfile(): - yield normpath(member.name.decode('iso8859-1')) + if not member.isdir(): + name = normpath(member.name) + # enforce proper utf-8 encoding + try: + name.decode('utf-8') + except UnicodeDecodeError: + name = name.decode('iso8859-1').encode('utf-8') + yield name tar.close() - debdata.close() + dpkg.stdout.close() + dpkg.wait() __all__.append('DBBinary') @@ -2997,8 +3004,9 @@ 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 + # bin_contents needs special attention until the SERIAL type is + # correctly detected and the workaround has been removed; see comment + # above self.tbl_bin_contents = Table('bin_contents', self.db_meta, \ Column('file', Text, primary_key = True), Column('binary_id', Integer, ForeignKey('binaries.id'), \ @@ -3284,7 +3292,7 @@ class DBConn(object): mapper(BinContents, self.tbl_bin_contents, properties = dict( binary = relation(DBBinary, - backref=backref('contents', lazy='dynamic')), + backref=backref('contents', lazy='dynamic', cascade='all')), file = self.tbl_bin_contents.c.file)) ## Connection functions @@ -3303,7 +3311,16 @@ class DBConn(object): if cnf["DB::Port"] and cnf["DB::Port"] != "-1": connstr += "?port=%s" % cnf["DB::Port"] - self.db_pg = create_engine(connstr, echo=self.debug) + engine_args = { 'echo': self.debug } + if cnf.has_key('DB::PoolSize'): + engine_args['pool_size'] = int(cnf['DB::PoolSize']) + if cnf.has_key('DB::MaxOverflow'): + engine_args['max_overflow'] = int(cnf['DB::MaxOverflow']) + if sa_major_version == '0.6' and cnf.has_key('DB::Unicode') and \ + cnf['DB::Unicode'] == 'false': + engine_args['use_native_unicode'] = False + + self.db_pg = create_engine(connstr, **engine_args) self.db_meta = MetaData() self.db_meta.bind = self.db_pg self.db_smaker = sessionmaker(bind=self.db_pg,