X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fgenerate_filelist.py;h=faf08bd7a8680e59802d4bdf8c12d4ec0a68a21b;hb=b3d7c0ea3704fa38d91b47023e232b94ce05735d;hp=a668622183dbf72763de328614976d4074f1de21;hpb=30177206e6e4fed04e77e2f4996e491cab2f9ce5;p=dak.git diff --git a/dak/generate_filelist.py b/dak/generate_filelist.py index a6686221..faf08bd7 100755 --- a/dak/generate_filelist.py +++ b/dak/generate_filelist.py @@ -5,6 +5,7 @@ Generate file lists for apt-ftparchive. @contact: Debian FTP Master @copyright: 2009 Torsten Werner +@copyright: 2011 Ansgar Burchardt @license: GNU General Public License version 2 or later """ @@ -37,74 +38,14 @@ Generate file lists for apt-ftparchive. from daklib.dbconn import * from daklib.config import Config -from daklib import utils -import apt_pkg, os, sys - -def fetch(query, args, session): - return [path + filename for (path, filename) in \ - session.execute(query, args).fetchall()] - -def getSources(suite, component, session): - query = """ - SELECT path, filename - FROM srcfiles_suite_component - WHERE suite = :suite AND component = :component - ORDER BY filename - """ - args = { 'suite': suite.suite_id, - 'component': component.component_id } - return fetch(query, args, session) - -def getBinaries(suite, component, architecture, type, session): - query = """ -CREATE TEMP TABLE gf_candidates ( - filename text, - path text, - architecture integer, - src integer, - source text); - -INSERT INTO gf_candidates (filename, path, architecture, src, source) - SELECT f.filename, l.path, b.architecture, b.source as src, s.source - FROM binaries b - JOIN bin_associations ba ON b.id = ba.bin - JOIN source s ON b.source = s.id - JOIN files f ON b.file = f.id - JOIN location l ON f.location = l.id - WHERE ba.suite = :suite AND b.type = :type AND - l.component = :component AND b.architecture IN (2, :architecture); - -WITH arch_any AS - - (SELECT path, filename FROM gf_candidates - WHERE architecture > 2), - - arch_all_with_any AS - (SELECT path, filename FROM gf_candidates - WHERE architecture = 2 AND - src IN (SELECT src FROM gf_candidates WHERE architecture > 2)), - - arch_all_without_any AS - (SELECT path, filename FROM gf_candidates - WHERE architecture = 2 AND - source NOT IN (SELECT DISTINCT source FROM gf_candidates WHERE architecture > 2)), - - filelist AS - (SELECT * FROM arch_any - UNION - SELECT * FROM arch_all_with_any - UNION - SELECT * FROM arch_all_without_any) - - SELECT * FROM filelist ORDER BY filename - """ - args = { 'suite': suite.suite_id, - 'component': component.component_id, - 'architecture': architecture.arch_id, - 'type': type } - return fetch(query, args, session) - -def listPath(suite, component, architecture = None, type = None): +from daklib import utils, daklog +from daklib.dakmultiprocessing import DakProcessPool, PROC_STATUS_SUCCESS, PROC_STATUS_SIGNALRAISED +import apt_pkg, os, stat, sys + +from daklib.lists import getSources, getBinaries, getArchAll + +def listPath(suite, component, architecture = None, type = None, + incremental_mode = False): """returns full path to the list file""" suffixMap = { 'deb': "binary-", 'udeb': "debian-installer_binary-" } @@ -115,23 +56,63 @@ def listPath(suite, component, architecture = None, type = None): filename = "%s_%s_%s.list" % \ (suite.suite_name, component.component_name, suffix) pathname = os.path.join(Config()["Dir::Lists"], filename) - return utils.open_file(pathname, "w") + file = utils.open_file(pathname, "a") + timestamp = None + if incremental_mode: + timestamp = os.fstat(file.fileno())[stat.ST_MTIME] + else: + file.seek(0) + file.truncate() + return (file, timestamp) -def writeSourceList(suite, component): - file = listPath(suite, component) +def writeSourceList(suite_id, component_id, incremental_mode): session = DBConn().session() - for filename in getSources(suite, component, session): + suite = Suite.get(suite_id, session) + component = Component.get(component_id, session) + (file, timestamp) = listPath(suite, component, + incremental_mode = incremental_mode) + + message = "sources list for %s %s" % (suite.suite_name, component.component_name) + + for _, filename in getSources(suite, component, session, timestamp): file.write(filename + '\n') - session.close() + session.rollback() file.close() + return (PROC_STATUS_SUCCESS, message) -def writeBinaryList(suite, component, architecture, type): - file = listPath(suite, component, architecture, type) +def writeAllList(suite_id, component_id, architecture_id, type, incremental_mode): session = DBConn().session() - for filename in getBinaries(suite, component, architecture, type, session): + suite = Suite.get(suite_id, session) + component = Component.get(component_id, session) + architecture = Architecture.get(architecture_id, session) + (file, timestamp) = listPath(suite, component, architecture, type, + incremental_mode) + + message = "all list for %s %s (arch=%s, type=%s)" % (suite.suite_name, component.component_name, architecture.arch_string, type) + + for _, filename in getArchAll(suite, component, architecture, type, + session, timestamp): file.write(filename + '\n') - session.close() + session.rollback() file.close() + return (PROC_STATUS_SUCCESS, message) + +def writeBinaryList(suite_id, component_id, architecture_id, type, incremental_mode): + session = DBConn().session() + suite = Suite.get(suite_id, session) + component = Component.get(component_id, session) + architecture = Architecture.get(architecture_id, session) + (file, timestamp) = listPath(suite, component, architecture, type, + incremental_mode) + + message = "binary list for %s %s (arch=%s, type=%s)" % (suite.suite_name, component.component_name, architecture.arch_string, type) + + for _, filename in getBinaries(suite, component, architecture, type, + session, timestamp): + file.write(filename + '\n') + session.rollback() + file.close() + return (PROC_STATUS_SUCCESS, message) def usage(): print """Usage: dak generate_filelist [OPTIONS] @@ -141,57 +122,96 @@ Create filename lists for apt-ftparchive. -c, --component=COMPONENT act on this component -a, --architecture=ARCH act on this architecture -h, --help show this help and exit + -i, --incremental activate incremental mode ARCH, COMPONENT and SUITE can be comma (or space) separated list, e.g. - --suite=testing,unstable""" + --suite=testing,unstable + +Incremental mode appends only newer files to existing lists.""" sys.exit() def main(): cnf = Config() + Logger = daklog.Logger('generate-filelist') Arguments = [('h', "help", "Filelist::Options::Help"), ('s', "suite", "Filelist::Options::Suite", "HasArg"), ('c', "component", "Filelist::Options::Component", "HasArg"), - ('a', "architecture", "Filelist::Options::Architecture", "HasArg")] - query_suites = DBConn().session().query(Suite) - suites = [suite.suite_name for suite in query_suites.all()] + ('a', "architecture", "Filelist::Options::Architecture", "HasArg"), + ('i', "incremental", "Filelist::Options::Incremental")] + session = DBConn().session() + query_suites = session.query(Suite) + suites = [suite.suite_name for suite in query_suites] if not cnf.has_key('Filelist::Options::Suite'): - cnf['Filelist::Options::Suite'] = ','.join(suites) - # we can ask the database for components if 'mixed' is gone + cnf['Filelist::Options::Suite'] = ','.join(suites).encode() + query_components = session.query(Component) + components = \ + [component.component_name for component in query_components] if not cnf.has_key('Filelist::Options::Component'): - cnf['Filelist::Options::Component'] = 'main,contrib,non-free' - query_architectures = DBConn().session().query(Architecture) + cnf['Filelist::Options::Component'] = ','.join(components).encode() + query_architectures = session.query(Architecture) architectures = \ - [architecture.arch_string for architecture in query_architectures.all()] + [architecture.arch_string for architecture in query_architectures] if not cnf.has_key('Filelist::Options::Architecture'): - cnf['Filelist::Options::Architecture'] = ','.join(architectures) + cnf['Filelist::Options::Architecture'] = ','.join(architectures).encode() cnf['Filelist::Options::Help'] = '' - apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv) - Options = cnf.SubTree("Filelist::Options") + cnf['Filelist::Options::Incremental'] = '' + apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) + Options = cnf.subtree("Filelist::Options") if Options['Help']: usage() - session = DBConn().session() - suite_arch = session.query(SuiteArchitecture) - for suite_name in utils.split_args(Options['Suite']): - suite = query_suites.filter_by(suite_name = suite_name).one() - join = suite_arch.filter_by(suite_id = suite.suite_id) - for component_name in utils.split_args(Options['Component']): - component = session.query(Component).\ - filter_by(component_name = component_name).one() - for architecture_name in utils.split_args(Options['Architecture']): - architecture = query_architectures.\ - filter_by(arch_string = architecture_name).one() - try: - join.filter_by(arch_id = architecture.arch_id).one() - if architecture_name == 'source': - writeSourceList(suite, component) - elif architecture_name != 'all': - writeBinaryList(suite, component, architecture, 'deb') - writeBinaryList(suite, component, architecture, 'udeb') - except: + pool = DakProcessPool() + query_suites = query_suites. \ + filter(Suite.suite_name.in_(utils.split_args(Options['Suite']))) + query_components = query_components. \ + filter(Component.component_name.in_(utils.split_args(Options['Component']))) + query_architectures = query_architectures. \ + filter(Architecture.arch_string.in_(utils.split_args(Options['Architecture']))) + + def parse_results(message): + # Split out into (code, msg) + code, msg = message + if code == PROC_STATUS_SUCCESS: + Logger.log([msg]) + elif code == PROC_STATUS_SIGNALRAISED: + Logger.log(['E: Subprocess recieved signal ', msg]) + else: + Logger.log(['E: ', msg]) + + for suite in query_suites: + suite_id = suite.suite_id + for component in query_components: + component_id = component.component_id + for architecture in query_architectures: + architecture_id = architecture.arch_id + if architecture not in suite.architectures: pass + elif architecture.arch_string == 'source': + pool.apply_async(writeSourceList, + (suite_id, component_id, Options['Incremental']), callback=parse_results) + elif architecture.arch_string == 'all': + pool.apply_async(writeAllList, + (suite_id, component_id, architecture_id, 'deb', + Options['Incremental']), callback=parse_results) + pool.apply_async(writeAllList, + (suite_id, component_id, architecture_id, 'udeb', + Options['Incremental']), callback=parse_results) + else: # arch any + pool.apply_async(writeBinaryList, + (suite_id, component_id, architecture_id, 'deb', + Options['Incremental']), callback=parse_results) + pool.apply_async(writeBinaryList, + (suite_id, component_id, architecture_id, 'udeb', + Options['Incremental']), callback=parse_results) + pool.close() + pool.join() + # this script doesn't change the database session.close() + Logger.close() + + sys.exit(pool.overall_status()) + if __name__ == '__main__': main()