From: Torsten Werner Date: Tue, 22 Mar 2011 13:18:55 +0000 (+0000) Subject: Contents: use the new string_agg() function of Pg9. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8df34db4cc473d53136905027307484400fdf0d;p=dak Contents: use the new string_agg() function of Pg9. Signed-off-by: Torsten Werner --- diff --git a/daklib/contents.py b/daklib/contents.py index 27ffdda6..5bf94d9a 100755 --- a/daklib/contents.py +++ b/daklib/contents.py @@ -92,10 +92,10 @@ unique_override as where o.suite = :overridesuite and o.type = :type_id and o.section = s.id and o.component = :component) -select bc.file, o.section || '/' || b.package as package +select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package) as pkglist from newest_binaries b, bin_contents bc, unique_override o where b.id = bc.binary_id and o.package = b.package - order by bc.file, b.package''' + group by bc.file''' else: sql = ''' @@ -120,36 +120,26 @@ unique_override as where o.suite = :overridesuite and o.type = :type_id and o.section = s.id order by o.package, s.section, o.modified desc) -select bc.file, o.section || '/' || b.package as package +select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package) as pkglist from newest_binaries b, bin_contents bc, unique_override o where b.id = bc.binary_id and o.package = b.package - order by bc.file, b.package''' + group by bc.file''' - return self.session.query("file", "package").from_statement(sql). \ + return self.session.query("file", "pkglist").from_statement(sql). \ params(params) def formatline(self, filename, package_list): ''' Returns a formatted string for the filename argument. ''' - package_list = ','.join(package_list) return "%-55s %s\n" % (filename, package_list) def fetch(self): ''' Yields a new line of the Contents-$arch.gz file in filename order. ''' - last_filename = None - package_list = [] - for filename, package in self.query().yield_per(100): - if filename != last_filename: - if last_filename is not None: - yield self.formatline(last_filename, package_list) - last_filename = filename - package_list = [] - package_list.append(package) - if last_filename is not None: - yield self.formatline(last_filename, package_list) + for filename, package_list in self.query().yield_per(100): + yield self.formatline(filename, package_list) # end transaction to return connection to pool self.session.rollback() diff --git a/tests/dbtest_contents.py b/tests/dbtest_contents.py index 43cf838c..622e4aaf 100755 --- a/tests/dbtest_contents.py +++ b/tests/dbtest_contents.py @@ -145,9 +145,7 @@ class ContentsTestCase(DBDakTestCase): cw.get_list()) # test formatline and sort order self.assertEqual('/usr/bin/hello python/hello\n', \ - cw.formatline('/usr/bin/hello', ['python/hello'])) - self.assertEqual('/usr/bin/hello editors/emacs,python/hello,utils/sl\n', \ - cw.formatline('/usr/bin/hello', ['editors/emacs', 'python/hello', 'utils/sl'])) + cw.formatline('/usr/bin/hello', 'python/hello')) # test output_filename self.assertEqual('tests/fixtures/ftp/dists/squeeze/Contents-i386.gz', \ normpath(cw.output_filename())) diff --git a/tests/fixtures/dak.conf b/tests/fixtures/dak.conf index abfa2511..6f68238d 100644 --- a/tests/fixtures/dak.conf +++ b/tests/fixtures/dak.conf @@ -29,5 +29,6 @@ DB Name "test_projectb"; Host ""; Port -1; + Unicode false; };