X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fgenerate_filelist.py;h=dcf6864ff72412e98b3797b908eb49213e70de74;hb=3342185a1c804f3fe03822c21bad57ce9db009ed;hp=43a76054fefe2a3d21543e5b41a1a13251093ed0;hpb=fc35ff4d09d4c622b21dabdc10afbb09c78d1d02;p=dak.git diff --git a/dak/generate_filelist.py b/dak/generate_filelist.py index 43a76054..dcf6864f 100755 --- a/dak/generate_filelist.py +++ b/dak/generate_filelist.py @@ -22,41 +22,29 @@ Generate file lists for apt-ftparchive. # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +################################################################################ + +# Ganneff> Please go and try to lock mhy now. After than try to lock NEW. +# twerner> !lock mhy +# dak> twerner: You suck, this is already locked by Ganneff +# Ganneff> now try with NEW +# twerner> !lock NEW +# dak> twerner: also locked NEW +# mhy> Ganneff: oy, stop using me for locks and highlighting me you tall muppet +# Ganneff> hehe :) + +################################################################################ + from daklib.dbconn import * from daklib.config import Config +from daklib.threadpool import ThreadPool 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 = """ - SELECT path, filename - FROM binfiles_suite_component_arch - WHERE suite = :suite AND component = :component AND type = :type AND - (architecture = :architecture OR architecture = 2) - 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): +import apt_pkg, os, stat, sys + +from daklib.lists import getSources, getBinaries + +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-" } @@ -67,18 +55,34 @@ 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") - -def writeSourceList(suite, component, session): - file = listPath(suite, component) - for filename in getSources(suite, component, session): + 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(args): + (suite, component, incremental_mode) = args + (file, timestamp) = listPath(suite, component, + incremental_mode = incremental_mode) + session = DBConn().session() + for _, filename in getSources(suite, component, session, timestamp): file.write(filename + '\n') + session.close() file.close() -def writeBinaryList(suite, component, architecture, type, session): - file = listPath(suite, component, architecture, type) - for filename in getBinaries(suite, component, architecture, type, session): +def writeBinaryList(args): + (suite, component, architecture, type, incremental_mode) = args + (file, timestamp) = listPath(suite, component, architecture, type, + incremental_mode) + session = DBConn().session() + for _, filename in getBinaries(suite, component, architecture, type, + session, timestamp): file.write(filename + '\n') + session.close() file.close() def usage(): @@ -89,9 +93,12 @@ 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(): @@ -99,46 +106,54 @@ def main(): 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'] = '' + cnf['Filelist::Options::Incremental'] = '' apt_pkg.ParseCommandLine(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, session) - elif architecture_name != 'all': - writeBinaryList(suite, component, architecture, 'deb', session) - writeBinaryList(suite, component, architecture, 'udeb', session) - except: + threadpool = ThreadPool() + 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']))) + for suite in query_suites: + for component in query_components: + for architecture in query_architectures: + if architecture not in suite.architectures: pass + elif architecture.arch_string == 'source': + threadpool.queueTask(writeSourceList, + (suite, component, Options['Incremental'])) + elif architecture.arch_string != 'all': + threadpool.queueTask(writeBinaryList, + (suite, component, architecture, 'deb', + Options['Incremental'])) + threadpool.queueTask(writeBinaryList, + (suite, component, architecture, 'udeb', + Options['Incremental'])) + threadpool.joinAll() # this script doesn't change the database - session.rollback() + session.close() if __name__ == '__main__': main()