]> git.decadent.org.uk Git - dak.git/blob - dak/generate_filelist.py
add generate_filelist.py to maybe replace msfl.py
[dak.git] / dak / generate_filelist.py
1 #!/usr/bin/python
2
3 from daklib.dbconn import *
4 from daklib.config import Config
5 from daklib import utils
6 import apt_pkg, os, sys
7
8 def fetch(query, args, session):
9   return [path + filename for (path, filename) in \
10     session.execute(query, args).fetchall()]
11
12 def getSources(suite, component, session):
13   query = """
14     SELECT path, filename
15       FROM srcfiles_suite_component
16       WHERE suite = :suite AND component = :component
17   """
18   args = { 'suite': suite.suite_id,
19            'component': component.component_id }
20   return fetch(query, args, session)
21
22 def getBinaries(suite, component, architecture, type, session):
23   query = """
24     SELECT path, filename
25       FROM binfiles_suite_component_arch
26       WHERE suite = :suite AND component = :component AND type = :type AND
27             (architecture = :architecture OR architecture = 2)
28   """
29   args = { 'suite': suite.suite_id,
30            'component': component.component_id,
31            'architecture': architecture.arch_id,
32            'type': type }
33   return fetch(query, args, session)
34
35 def listPath(suite, component, architecture = None, type = None):
36   """returns full path to the list file"""
37   suffixMap = { 'deb': "binary-",
38                 'udeb': "debian-installer_binary-" }
39   if architecture:
40     suffix = suffixMap[type] + architecture.arch_string
41   else:
42     suffix = "source"
43   filename = "%s_%s_%s.list" % \
44     (suite.suite_name, component.component_name, suffix)
45   pathname = os.path.join(Config()["Dir::Lists"], filename)
46   return utils.open_file(pathname, "w")
47
48 def writeSourceList(suite, component, session):
49   file = listPath(suite, component)
50   for filename in getSources(suite, component, session):
51     file.write(filename + '\n')
52   file.close()
53
54 def writeBinaryList(suite, component, architecture, type, session):
55   file = listPath(suite, component, architecture, type)
56   for filename in getBinaries(suite, component, architecture, type, session):
57     file.write(filename + '\n')
58   file.close()
59
60 def usage():
61   print """Usage: dak generate_filelist [OPTIONS]
62 Create filename lists for apt-ftparchive.
63
64   -s, --suite=SUITE          act on this suite
65   -c, --component=COMPONENT  act on this component
66   -a, --architecture=ARCH    act on this architecture
67   -h, --help                 show this help and exit
68
69 ARCH, COMPONENT and SUITE can be comma (or space) separated list, e.g.
70     --suite=testing,unstable"""
71   sys.exit()
72
73 def main():
74   cnf = Config()
75   Arguments = [('h', "help",         "Filelist::Options::Help"),
76                ('s', "suite",        "Filelist::Options::Suite", "HasArg"),
77                ('c', "component",    "Filelist::Options::Component", "HasArg"),
78                ('a', "architecture", "Filelist::Options::Architecture", "HasArg")]
79   query_suites = DBConn().session().query(Suite)
80   suites = [suite.suite_name for suite in query_suites.all()]
81   if not cnf.has_key('Filelist::Options::Suite'):
82     cnf['Filelist::Options::Suite'] = ','.join(suites)
83   # we can ask the database for components if 'mixed' is gone
84   if not cnf.has_key('Filelist::Options::Component'):
85     cnf['Filelist::Options::Component'] = 'main,contrib,non-free'
86   query_architectures = DBConn().session().query(Architecture)
87   architectures = \
88     [architecture.arch_string for architecture in query_architectures.all()]
89   if not cnf.has_key('Filelist::Options::Architecture'):
90     cnf['Filelist::Options::Architecture'] = ','.join(architectures)
91   cnf['Filelist::Options::Help'] = ''
92   apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
93   Options = cnf.SubTree("Filelist::Options")
94   if Options['Help']:
95     usage()
96   session = DBConn().session()
97   suite_arch = session.query(SuiteArchitecture)
98   for suite_name in utils.split_args(Options['Suite']):
99     suite = query_suites.filter_by(suite_name = suite_name).one()
100     join = suite_arch.filter_by(suite_id = suite.suite_id)
101     for component_name in utils.split_args(Options['Component']):
102       component = session.query(Component).\
103         filter_by(component_name = component_name).one()
104       for architecture_name in utils.split_args(Options['Architecture']):
105         architecture = query_architectures.\
106           filter_by(arch_string = architecture_name).one()
107         try:
108           join.filter_by(arch_id = architecture.arch_id).one()
109           if architecture_name == 'source':
110             writeSourceList(suite, component, session)
111           elif architecture_name != 'all':
112             writeBinaryList(suite, component, architecture, 'deb', session)
113             writeBinaryList(suite, component, architecture, 'udeb', session)
114         except:
115           pass
116   # this script doesn't change the database
117   session.rollback()
118
119 if __name__ == '__main__':
120   main()
121