################################################################################
import os
+from os.path import normpath
import re
import psycopg2
import traceback
from datetime import datetime, timedelta
from errno import ENOENT
from tempfile import mkstemp, mkdtemp
+from subprocess import Popen, PIPE
+from tarfile import TarFile
from inspect import getargspec
def get_component_name(self):
return self.poolfile.location.component.component_name
+ 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 either utf-8 or
+ iso8859-1 encoding.
+ '''
+ fullpath = self.poolfile.fullpath
+ 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():
+ try:
+ name = member.name.decode('utf-8')
+ except UnicodeDecodeError:
+ name = member.name.decode('iso8859-1')
+ yield normpath(name)
+ tar.close()
+ dpkg.stdout.close()
+ dpkg.wait()
+
__all__.append('DBBinary')
@session_wrapper
return NotImplemented
def properties(self):
- return ['component_name', 'component_id', 'description', 'location', \
- 'meets_dfsg']
+ return ['component_name', 'component_id', 'description', \
+ 'location_count', 'meets_dfsg', 'overrides_count']
def not_null_constraints(self):
return ['component_name']
################################################################################
-class Override(object):
- def __init__(self, *args, **kwargs):
- pass
+class Override(ORMObject):
+ def __init__(self, package = None, suite = None, component = None, overridetype = None, \
+ section = None, priority = None):
+ self.package = package
+ self.suite = suite
+ self.component = component
+ self.overridetype = overridetype
+ self.section = section
+ self.priority = priority
- def __repr__(self):
- return '<Override %s (%s)>' % (self.package, self.suite_id)
+ def properties(self):
+ return ['package', 'suite', 'component', 'overridetype', 'section', \
+ 'priority']
+
+ def not_null_constraints(self):
+ return ['package', 'suite', 'component', 'overridetype', 'section']
__all__.append('Override')
maps = [ (x[1], x[2]) for x in maps
if x[0] == "map" or x[0] == "silent-map" ]
s = [suite]
- for x in maps:
- if x[1] in s and x[0] not in s:
- s.append(x[0])
+ for (from_, to) in maps:
+ if from_ in s and to not in s:
+ s.append(to)
q = q.filter(DBSource.suites.any(Suite.suite_name.in_(s)))
self.version = version
def properties(self):
- return ['suite_name', 'version', 'sources_count', 'binaries_count']
+ return ['suite_name', 'version', 'sources_count', 'binaries_count', \
+ 'overrides_count']
def not_null_constraints(self):
return ['suite_name', 'version']
'changes_pending_source_files',
'changes_pool_files',
'deb_contents',
+ # TODO: the maintainer column in table override should be removed.
'override',
'suite_architectures',
'suite_src_formats',
mapper(Location, self.tbl_location,
properties = dict(location_id = self.tbl_location.c.id,
component_id = self.tbl_location.c.component,
- component = relation(Component, \
- backref=backref('location', uselist = False)),
+ component = relation(Component, backref='location'),
archive_id = self.tbl_location.c.archive,
archive = relation(Archive),
# FIXME: the 'type' column is old cruft and
mapper(Override, self.tbl_override,
properties = dict(suite_id = self.tbl_override.c.suite,
- suite = relation(Suite),
+ suite = relation(Suite, \
+ backref=backref('overrides', lazy='dynamic')),
package = self.tbl_override.c.package,
component_id = self.tbl_override.c.component,
- component = relation(Component),
+ component = relation(Component, \
+ backref=backref('overrides', lazy='dynamic')),
priority_id = self.tbl_override.c.priority,
priority = relation(Priority, \
backref=backref('overrides', lazy='dynamic')),
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
connstr = "postgres:///%s" % cnf["DB::Name"]
if cnf["DB::Port"] and cnf["DB::Port"] != "-1":
connstr += "?port=%s" % cnf["DB::Port"]
-
- self.db_pg = create_engine(connstr, echo=self.debug)
+ if not cnf.has_key('DB::PoolSize'):
+ cnf['DB::PoolSize'] = '5'
+ if not cnf.has_key('DB::MaxOverflow'):
+ cnf['DB::MaxOverflow'] = '10'
+
+ self.db_pg = create_engine(connstr, echo=self.debug,
+ pool_size=int(cnf['DB::PoolSize']),
+ max_overflow=int(cnf['DB::MaxOverflow']))
self.db_meta = MetaData()
self.db_meta.bind = self.db_pg
self.db_smaker = sessionmaker(bind=self.db_pg,