[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master 3/8] Add method scan_contents() to class DBBinary.



Signed-off-by: Torsten Werner <twerner@debian.org>
---
 daklib/dbconn.py         |   18 ++++++++++++++++++
 tests/dbtest_contents.py |    6 ++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/daklib/dbconn.py b/daklib/dbconn.py
index 3b60ae6..bdb223e 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 9b33c04..575facd 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]
-- 
1.7.2.3



Reply to: