X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fcontents.py;h=730d21488b27916a08f0e0771c7533904fe635b5;hb=7fb40b1f2657bdfbc27778da992e2460777b46ea;hp=ac934f16fbf07c931feaf328798eb3416995fe95;hpb=fcd20a76e3582e608e9b023cf0e2c8794e484bdf;p=dak.git diff --git a/daklib/contents.py b/daklib/contents.py index ac934f16..730d2148 100755 --- a/daklib/contents.py +++ b/daklib/contents.py @@ -28,6 +28,7 @@ Helper code for contents generation. from daklib.dbconn import * from daklib.config import Config from daklib.threadpool import ThreadPool +from multiprocessing import Pool from sqlalchemy import desc, or_ from subprocess import Popen, PIPE @@ -66,7 +67,7 @@ class ContentsWriter(object): } if self.component is not None: - params['component'] = component.component_id + params['component'] = self.component.component_id sql = ''' create temp table newest_binaries ( id integer primary key, @@ -145,7 +146,8 @@ select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' last_filename = filename package_list = [] package_list.append(package) - yield self.formatline(last_filename, package_list) + if last_filename is not None: + yield self.formatline(last_filename, package_list) # end transaction to return connection to pool self.session.rollback() @@ -165,9 +167,9 @@ select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' 'architecture': self.architecture.arch_string } if self.component is None: - return "%(root)s%(suite)s/Contents-%(architecture)s.gz" % values + return "%(root)s/dists/%(suite)s/Contents-%(architecture)s.gz" % values values['component'] = self.component.component_name - return "%(root)s%(suite)s/%(component)s/Contents-%(architecture)s.gz" % values + return "%(root)s/dists/%(suite)s/%(component)s/Contents-%(architecture)s.gz" % values def get_header(self): ''' @@ -182,19 +184,19 @@ select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' if header_file: header_file.close() - def write_file(self, dummy_arg = None): + def write_file(self): ''' - Write the output file. The argument dummy_arg is ignored but needed by - our threadpool implementation. + Write the output file. ''' command = ['gzip', '--rsyncable'] output_file = open(self.output_filename(), 'w') - pipe = Popen(command, stdin = PIPE, stdout = output_file).stdin - pipe.write(self.get_header()) + gzip = Popen(command, stdin = PIPE, stdout = output_file) + gzip.stdin.write(self.get_header()) for item in self.fetch(): - pipe.write(item) - pipe.close() + gzip.stdin.write(item) + gzip.stdin.close() output_file.close() + gzip.wait() @classmethod def write_all(class_, suite_names = [], force = False): @@ -204,27 +206,28 @@ select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' suites will be included if the force argument is set to True. ''' session = DBConn().session() - suite_query = session.query(Suites) + suite_query = session.query(Suite) if len(suite_names) > 0: - suite_query = suite_query.filter(Suite.suitename.in_(suite_names)) + suite_query = suite_query.filter(Suite.suite_name.in_(suite_names)) if not force: suite_query = suite_query.filter_by(untouchable = False) main = get_component('main', session) non_free = get_component('non-free', session) deb = get_override_type('deb', session) udeb = get_override_type('udeb', session) - threadpool = ThreadPool() + pool = Pool() for suite in suite_query: - for architecture in suite.architectures: + for architecture in suite.get_architectures(skipsrc = True, skipall = True): # handle 'deb' packages writer = ContentsWriter(suite, architecture, deb) - threadpool.queueTask(writer.write_file) + pool.apply(writer.write_file) # handle 'udeb' packages for 'main' and 'non-free' writer = ContentsWriter(suite, architecture, udeb, component = main) - threadpool.queueTask(writer.write_file) + pool.apply(writer.write_file) writer = ContentsWriter(suite, architecture, udeb, component = non_free) - threadpool.queueTask(writer.write_file) - threadpool.joinAll() + pool.apply(writer.write_file) + pool.close() + pool.join() session.close()