X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fcontents.py;h=6b3b81534d3862a296e58a00201abc431188654b;hb=f51a98511c1d7892ba85984058270dfc01d60db5;hp=6aadb66e38f6972b27d3826dc12b06e539eb000d;hpb=0ee1801ac80cfafc2b33ceb64fd2a43737b4fb1a;p=dak.git diff --git a/daklib/contents.py b/daklib/contents.py index 6aadb66e..6b3b8153 100755 --- a/daklib/contents.py +++ b/daklib/contents.py @@ -32,7 +32,7 @@ from daklib.threadpool import ThreadPool from sqlalchemy import desc, or_ from subprocess import Popen, PIPE -import os +import os.path class ContentsWriter(object): ''' @@ -66,7 +66,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, @@ -130,7 +130,7 @@ select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' Returns a formatted string for the filename argument. ''' package_list = ','.join(package_list) - return "%-60s%s\n" % (filename, package_list) + return "%-55s %s\n" % (filename, package_list) def fetch(self): ''' @@ -145,7 +145,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,25 +166,27 @@ 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): ''' Returns the header for the Contents files as a string. ''' + header_file = None try: - filename = os.join(Config()['Dir::Templates'], 'contents') + filename = os.path.join(Config()['Dir::Templates'], 'contents') header_file = open(filename) return header_file.read() finally: if header_file: header_file.close() - def write_file(self): + def write_file(self, dummy_arg = None): ''' - Write the output file. + Write the output file. The argument dummy_arg is ignored but needed by + our threadpool implementation. ''' command = ['gzip', '--rsyncable'] output_file = open(self.output_filename(), 'w') @@ -194,6 +197,37 @@ select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' pipe.close() output_file.close() + @classmethod + def write_all(class_, suite_names = [], force = False): + ''' + Writes all Contents files for suites in list suite_names which defaults + to all 'touchable' suites if not specified explicitely. Untouchable + suites will be included if the force argument is set to True. + ''' + session = DBConn().session() + suite_query = session.query(Suite) + if len(suite_names) > 0: + 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() + for suite in suite_query: + for architecture in suite.get_architectures(skipsrc = True, skipall = True): + # handle 'deb' packages + writer = ContentsWriter(suite, architecture, deb) + threadpool.queueTask(writer.write_file) + # handle 'udeb' packages for 'main' and 'non-free' + writer = ContentsWriter(suite, architecture, udeb, component = main) + threadpool.queueTask(writer.write_file) + writer = ContentsWriter(suite, architecture, udeb, component = non_free) + threadpool.queueTask(writer.write_file) + threadpool.joinAll() + session.close() + class ContentsScanner(object): '''