From: Torsten Werner Date: Mon, 28 Feb 2011 20:51:48 +0000 (+0100) Subject: Add method scan_contents() to class DBBinary. X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=0d651b1c6eefaabfe8be90355ea181a5e275bd9d;p=dak.git Add method scan_contents() to class DBBinary. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 3b60ae65..bdb223e2 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -34,6 +34,7 @@ ################################################################################ import os +from os.path import normpath import re import psycopg2 import traceback @@ -49,6 +50,8 @@ except: 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 @@ -502,6 +505,21 @@ class DBBinary(ORMObject): 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. + ''' + fullpath = self.poolfile.fullpath + debdata = Popen(['dpkg-deb', '--fsys-tarfile', fullpath], + stdout = PIPE).stdout + tar = TarFile.open(fileobj = debdata, mode = 'r|') + for member in tar.getmembers(): + if member.isfile(): + yield normpath(member.name) + tar.close() + debdata.close() + __all__.append('DBBinary') @session_wrapper diff --git a/tests/dbtest_contents.py b/tests/dbtest_contents.py index 9b33c04b..575facdd 100755 --- a/tests/dbtest_contents.py +++ b/tests/dbtest_contents.py @@ -155,6 +155,12 @@ class ContentsTestCase(DBDakTestCase): self.assertEqual('tests/fixtures/ftp/squeeze/main/Contents-i386.gz', \ cw.output_filename()) + def test_scan_contents(self): + self.setup_binaries() + filelist = [f for f in self.binary['hello_2.2-1_i386'].scan_contents()] + self.assertEqual(['usr/bin/hello', 'usr/share/doc/hello/copyright'], + filelist) + def classes_to_clean(self): return [Override, Suite, BinContents, DBBinary, DBSource, Architecture, Section, \ OverrideType, Maintainer, Component, Priority, PoolFile]