]> git.decadent.org.uk Git - dak.git/blob - dak/generate_packages_sources.py
generate-packages-sources
[dak.git] / dak / generate_packages_sources.py
1 #!/usr/bin/env python
2
3 """ Generate Packages/Sources files
4
5 @contact: Debian FTPMaster <ftpmaster@debian.org>
6 @copyright: 2000, 2001, 2002, 2006  James Troup <james@nocrew.org>
7 @copyright: 2009  Mark Hymers <mhy@debian.org>
8 @copyright: 2010  Joerg Jaspert <joerg@debian.org>
9
10 """
11
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26 ################################################################################
27
28 import os
29 import os.path
30 import stat
31 import sys
32 from datetime import datetime
33 import apt_pkg
34
35 from daklib import daklog
36 from daklib.dbconn import *
37 from daklib.config import Config
38 from daklib.threadpool import ThreadPool
39
40 ################################################################################
41
42 Options = None
43 Logger = None
44
45 ################################################################################
46
47 def usage (exit_code=0):
48     print """Usage: dak generate-packages-sources [OPTIONS]
49 Generate the Packages/Sources files
50
51   -s, --suite=SUITE(s)       process this suite
52                              Default: All suites not marked 'untouchable'
53   -f, --force                Allow processing of untouchable suites
54                              CAREFUL: Only to be used at point release time!
55   -h, --help                 show this help and exit
56
57 SUITE can be a space seperated list, e.g.
58    --suite=unstable testing
59   """
60
61     sys.exit(exit_code)
62
63 ################################################################################
64
65 def main ():
66     global Options, Logger
67
68     cnf = Config()
69
70     for i in ["Help", "Suite", "Force"]:
71         if not cnf.has_key("Generate-Packages-Sources::Options::%s" % (i)):
72             cnf["Generate-Packages-Sources::Options::%s" % (i)] = ""
73
74     Arguments = [('h',"help","Generate-Packages-Sources::Options::Help"),
75                  ('s',"suite","Generate-Packages-Sources::Options::Suite"),
76                  ('f',"force","Generate-Packages-Sources::Options::Force")]
77
78     suite_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
79     Options = cnf.SubTree("Generate-Packages-Sources::Options")
80
81     if Options["Help"]:
82         usage()
83
84     Logger = daklog.Logger(cnf, 'generate-packages-sources')
85
86     session = DBConn().session()
87
88     if Options["Suite"]:
89         # Something here
90         suites = []
91         for s in suite_names:
92             suite = get_suite(s.lower(), session)
93             if suite:
94                 suites.append(suite)
95             else:
96                 print "cannot find suite %s" % s
97                 Logger.log(['cannot find suite %s' % s])
98     else:
99         suites=session.query(Suite).filter(Suite.untouchable == False).all()
100
101     threadpool = ThreadPool()
102
103     startdir = os.getcwd()
104     os.chdir(cnf["Dir::TempPath"])
105
106     # For each given suite, each architecture, run one apt-ftparchive
107     for s in suites:
108         arch_list=get_suite_architectures(s.suite_name, skipsrc=False, skipall=True, session=session)
109         Logger.log(['generating output for Suite %s, Architectures %s' % (s.suite_name, arch_list)])
110         for a in arch_list:
111             threadpool.queueTask(s.generate_packages_sources, (a.arch_string))
112
113     threadpool.joinAll()
114     os.chdir(startdir)
115     # this script doesn't change the database
116     session.close()
117     Logger.close()
118
119 #######################################################################################
120
121 if __name__ == '__main__':
122     main()