]> git.decadent.org.uk Git - dak.git/commitdiff
Add method scan_contents() to class DBBinary.
authorTorsten Werner <twerner@debian.org>
Mon, 28 Feb 2011 20:51:48 +0000 (21:51 +0100)
committerTorsten Werner <twerner@debian.org>
Mon, 28 Feb 2011 20:57:06 +0000 (21:57 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py
tests/dbtest_contents.py

index 3b60ae65808d9aba8587647d0d85b32702ce2576..bdb223e23cb148429b505da228ecb14a61a52496 100755 (executable)
@@ -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
index 9b33c04be9655497b132ea6393cf288afb0930ae..575facdd5dc9b4f29d86e6af657d6041404f29a5 100755 (executable)
@@ -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]