From: Joerg Jaspert Date: Tue, 8 Mar 2011 21:35:50 +0000 (+0100) Subject: Merge branch 'master' of ssh://franck.debian.org/srv/ftp.debian.org/git/dak X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=dfa2f059b345fcd07a64f19659ab2c459e960ce1;hp=75273f99660e2830e39fad3e12140b7b4e2b0833;p=dak.git Merge branch 'master' of ssh://franck.debian.org/srv/ftp.debian.org/git/dak * 'master' of ssh://franck.debian.org/srv/ftp.debian.org/git/dak: Use 'dak contents generate_helper'. bugfixes Add a new subcommand 'generate_helper' to 'dak contents'. Switch to multiprocessing module and reap child gzips. --- diff --git a/dak/contents.py b/dak/contents.py index a8578ae3..5c33afa2 100755 --- a/dak/contents.py +++ b/dak/contents.py @@ -82,6 +82,21 @@ def write_all(cnf, suite_names = [], force = None): ################################################################################ +def write_helper(suite_name, argv): + session = DBConn().session() + suite = get_suite(suite_name, session) + architecture = get_architecture(argv[0], session) + debtype = get_override_type(argv[1], session) + if len(argv) == 3: + component = get_component(argv[2], session) + else: + component = None + session.rollback() + ContentsWriter(suite, architecture, debtype, component).write_file() + session.close() + +################################################################################ + def scan_all(cnf, limit): Logger = daklog.Logger(cnf.Cnf, 'contents scan') result = ContentsScanner.scan_all(limit) @@ -106,7 +121,7 @@ def main(): args = apt_pkg.ParseCommandLine(cnf.Cnf, arguments, sys.argv) options = cnf.SubTree('Contents::Options') - if (len(args) != 1) or options['Help']: + if (len(args) < 1) or options['Help']: usage() limit = None @@ -125,6 +140,10 @@ def main(): write_all(cnf, suite_names, force) return + if args[0] == 'generate_helper': + write_helper(suite_names[0], args[1:]) + return + usage() diff --git a/daklib/contents.py b/daklib/contents.py index 6b3b8153..1148758c 100755 --- a/daklib/contents.py +++ b/daklib/contents.py @@ -28,9 +28,10 @@ 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 +from subprocess import Popen, PIPE, call import os.path @@ -44,14 +45,11 @@ class ContentsWriter(object): sure that the new ContentsWriter object can be executed in a different thread. ''' - self.suite = suite.clone() - self.session = self.suite.session() - self.architecture = architecture.clone(self.session) - self.overridetype = overridetype.clone(self.session) - if component is not None: - self.component = component.clone(self.session) - else: - self.component = None + self.suite = suite + self.architecture = architecture + self.overridetype = overridetype + self.component = component + self.session = suite.session() def query(self): ''' @@ -183,19 +181,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): @@ -210,22 +208,22 @@ select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' 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.get_architectures(skipsrc = True, skipall = True): # handle 'deb' packages - writer = ContentsWriter(suite, architecture, deb) - threadpool.queueTask(writer.write_file) + command = ['dak', 'contents', '-s', suite.suite_name, \ + 'generate_helper', architecture.arch_string, 'deb'] + pool.apply_async(call, (command, )) # 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() + command = ['dak', 'contents', '-s', suite.suite_name, \ + 'generate_helper', architecture.arch_string, 'udeb', 'main'] + pool.apply_async(call, (command, )) + command = ['dak', 'contents', '-s', suite.suite_name, \ + 'generate_helper', architecture.arch_string, 'udeb', 'non-free'] + pool.apply_async(call, (command, )) + pool.close() + pool.join() session.close() diff --git a/tests/dbtest_contents.py b/tests/dbtest_contents.py index 7f9aa57f..43cf838c 100755 --- a/tests/dbtest_contents.py +++ b/tests/dbtest_contents.py @@ -5,6 +5,7 @@ from db_test import DBDakTestCase from daklib.dbconn import * from daklib.contents import ContentsWriter, ContentsScanner +from os.path import normpath from sqlalchemy.exc import FlushError, IntegrityError import unittest @@ -148,12 +149,12 @@ class ContentsTestCase(DBDakTestCase): self.assertEqual('/usr/bin/hello editors/emacs,python/hello,utils/sl\n', \ cw.formatline('/usr/bin/hello', ['editors/emacs', 'python/hello', 'utils/sl'])) # test output_filename - self.assertEqual('tests/fixtures/ftp/squeeze/Contents-i386.gz', \ - cw.output_filename()) + self.assertEqual('tests/fixtures/ftp/dists/squeeze/Contents-i386.gz', \ + normpath(cw.output_filename())) cw = ContentsWriter(self.suite['squeeze'], self.arch['i386'], \ self.otype['udeb'], self.comp['main']) - self.assertEqual('tests/fixtures/ftp/squeeze/main/Contents-i386.gz', \ - cw.output_filename()) + self.assertEqual('tests/fixtures/ftp/dists/squeeze/main/Contents-i386.gz', \ + normpath(cw.output_filename())) # test unicode support self.binary['hello_2.2-1_i386'].contents.append(BinContents(file = '\xc3\xb6')) self.session.commit()