X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fcontents.py;h=a158e8fcd4bb7d2ed27e8547b79b03d1cbd84b8a;hb=b8690d6b1256a4a95198b874d9eb1aab62a825fb;hp=b56a9c6ce322a5913c7d767b3b13ced8aae820ad;hpb=8ba1b12293e55da930cc0be48c1616723ec59088;p=dak.git diff --git a/daklib/contents.py b/daklib/contents.py index b56a9c6c..a158e8fc 100755 --- a/daklib/contents.py +++ b/daklib/contents.py @@ -29,7 +29,9 @@ from daklib.dbconn import * from daklib.config import Config from multiprocessing import Pool -from subprocess import Popen, PIPE +from shutil import rmtree +from subprocess import Popen, PIPE, check_call +from tempfile import mkdtemp import os.path @@ -241,7 +243,6 @@ def generate_helper(suite_id, arch_id, overridetype_id, component_id = None): ''' This function is called in a new subprocess. ''' - DBConn().reset() session = DBConn().session() suite = Suite.get(suite_id, session) architecture = Architecture.get(arch_id, session) @@ -308,15 +309,70 @@ class ContentsScanner(object): session.close() return { 'processed': processed, 'remaining': remaining } -reset = False - def scan_helper(binary_id): ''' This function runs in a subprocess. ''' - global reset - if not reset: - DBConn().reset() - reset = True scanner = ContentsScanner(binary_id) scanner.scan() + + +class UnpackedSource(object): + ''' + UnpackedSource extracts a source package into a temporary location and + gives you some convinient function for accessing it. + ''' + def __init__(self, dscfilename): + ''' + The dscfilename is a name of a DSC file that will be extracted. + ''' + self.root_directory = os.path.join(mkdtemp(), 'root') + command = ('dpkg-source', '--no-copy', '--no-check', '-x', dscfilename, + self.root_directory) + # dpkg-source does not have a --quiet option + devnull = open(os.devnull, 'w') + check_call(command, stdout = devnull, stderr = devnull) + devnull.close() + + def get_root_directory(self): + ''' + Returns the name of the package's root directory which is the directory + where the debian subdirectory is located. + ''' + return self.root_directory + + def get_changelog_file(self): + ''' + Returns a file object for debian/changelog or None if no such file exists. + ''' + changelog_name = os.path.join(self.root_directory, 'debian', 'changelog') + try: + return open(changelog_name) + except IOError: + return None + + def get_all_filenames(self): + ''' + Returns an iterator over all filenames. The filenames will be relative + to the root directory. + ''' + skip = len(self.root_directory) + 1 + for root, _, files in os.walk(self.root_directory): + for name in files: + yield os.path.join(root[skip:], name) + + def cleanup(self): + ''' + Removes all temporary files. + ''' + if self.root_directory is None: + return + parent_directory = os.path.dirname(self.root_directory) + rmtree(parent_directory) + self.root_directory = None + + def __del__(self): + ''' + Enforce cleanup. + ''' + self.cleanup()