]> git.decadent.org.uk Git - dak.git/blob - ziyi
add SigningPubKeyring option
[dak.git] / ziyi
1 #!/usr/bin/env python
2
3 # Create all the Release files
4
5 # Copyright (C) 2001  Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.12 2001-11-27 04:13:43 rmurray Exp $
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
22 #   ``Bored now''
23
24 ################################################################################
25
26 import pg, sys, os, stat, string, time
27 import utils, db_access
28 import apt_pkg
29
30 ################################################################################
31
32 Cnf = None
33 projectB = None
34
35 ################################################################################
36
37 def usage (exit_code=0):
38     print """Usage: ziyi [OPTION]
39 Generate Release files.
40
41   -h, --help                 show this help and exit"""
42
43     sys.exit(exit_code)
44
45 ################################################################################
46
47 def compressnames (tree,type,file):
48     compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
49     result = []
50     for mode in string.split(compress):
51         if mode == ".":
52             result.append(file)
53         elif mode == "gzip":
54             result.append(file + ".gz")
55         elif mode == "bzip2":
56             result.append(file + ".bz2")
57     return result
58
59 def print_md5_files (tree, files):
60     path = Cnf["Dir::RootDir"] + tree + "/"
61     for name in files:
62         try:
63             file_handle = utils.open_file(path + name)
64         except utils.cant_open_exc:
65             print "ALERT: Couldn't open " + path + name
66         else:
67             md5 = apt_pkg.md5sum(file_handle)
68             file_handle.close()
69
70         size = os.stat(path + name)[stat.ST_SIZE]
71         out.write(" %s         %8d %s\n" % (md5, size, name))
72
73 def print_sha1_files (tree, files):
74     path = Cnf["Dir::RootDir"] + tree + "/"
75     for name in files:
76         try:
77             file_handle = utils.open_file(path + name)
78         except utils.cant_open_exc:
79             print "ALERT: Couldn't open " + path + name
80         else:
81             sha1 = apt_pkg.sha1sum(file_handle)
82             file_handle.close()
83
84         size = os.stat(path + name)[stat.ST_SIZE]
85         out.write(" %s %8d %s\n" % (sha1, size, name))
86
87 ################################################################################
88
89 def main ():
90     global Cnf, AptCnf, projectB, out
91     out = sys.stdout;
92
93     Cnf = utils.get_conf()
94
95     AptCnf = apt_pkg.newConfiguration()
96     apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
97
98     Arguments = [('h',"help","Ziyi::Options::Help")];
99     for i in [ "help" ]:
100         if not Cnf.has_key("Ziyi::Options::%s" % (i)):
101             Cnf["Ziyi::Options::%s" % (i)] = "";
102
103     suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
104     Options = Cnf.SubTree("Ziyi::Options")
105
106     if Options["Help"]:
107         usage();
108
109     if not suites:
110         suites = Cnf.SubTree("Suite").List()
111
112     def real_arch(x):
113         return x != "source" and x != "all"
114
115     for suite in suites:
116         print "Processing: " + suite
117         SuiteBlock = Cnf.SubTree("Suite::" + suite)
118
119         if SuiteBlock.has_key("Untouchable"):
120             print "Skipping: " + suite + " (untouchable)"
121             continue
122
123         suite = string.lower(suite)
124
125         origin = SuiteBlock["Origin"]
126         label = SuiteBlock.get("Label", origin)
127         version = SuiteBlock.get("Version", "")
128         codename = SuiteBlock.get("CodeName", "")
129
130         if SuiteBlock.has_key("NotAutomatic"):
131             notautomatic = "yes"
132         else:
133             notautomatic = ""
134
135         if SuiteBlock.has_key("Components"):
136             components = SuiteBlock.SubTree("Components").List()
137         else:
138             components = []
139
140         nonus = 1
141         if components != []:
142             for c in components:
143                 if string.find(c, "non-US/") != 0:
144                     nonus = 0
145         else:
146             nonus = 0
147         if nonus:
148             longsuite = suite + "/non-US"
149         else:
150             longsuite = suite
151
152         tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
153
154         if AptCnf.has_key("tree::%s" % (tree)):
155             pass
156         elif AptCnf.has_key("bindirectory::%s" % (tree)):
157             pass
158         else:
159             print "ALERT: suite %s not in apt.conf, nor untouchable!" % (suite)
160             continue
161
162         print Cnf["Dir::RootDir"] + tree + "/Release"
163         out = open(Cnf["Dir::RootDir"] + tree + "/Release", "w")
164
165         out.write("Origin: %s\n" % (origin))
166         out.write("Label: %s\n" % (label))
167         out.write("Suite: %s\n" % (suite))
168         if version != "":
169             out.write("Version: %s\n" % (version))
170         if codename != "":
171             out.write("Codename: %s\n" % (codename))
172         out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
173         if notautomatic != "":
174             out.write("NotAutomatic: %s\n" % (notautomatic))
175         out.write("Architectures: %s\n" % (string.join(filter(real_arch, SuiteBlock.SubTree("Architectures").List()))))
176         if components != []:
177             out.write("Components: %s\n" % (string.join(components)))
178
179         out.write("Description: %s\n" % (SuiteBlock["Description"]))
180
181         files = []
182
183         if AptCnf.has_key("tree::%s" % (tree)):
184             for sec in string.split(AptCnf["tree::%s::Sections" % (tree)]):
185                 for arch in string.split(AptCnf["tree::%s::Architectures" % (tree)]):
186                     if arch == "source":
187                         for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
188                             files.append(file)
189                     else:
190                         disks = "%s/disks-%s" % (sec, arch)
191                         diskspath = Cnf["Dir::RootDir"]+tree+"/"+disks
192                         if os.path.exists(diskspath):
193                             for dir in os.listdir(diskspath):
194                                 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
195                                     files.append("%s/%s/md5sum.txt" % (disks, dir))
196
197                         for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
198                             files.append(file)
199
200                     if arch == "source":
201                         rel = "%s/%s/Release" % (sec, arch)
202                     else:
203                         rel = "%s/binary-%s/Release" % (sec, arch)
204                     relpath = Cnf["Dir::RootDir"]+tree+"/"+rel
205
206                     if os.path.exists(relpath):
207                         try:
208                             release = open(relpath, "w")
209                             #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
210                         except IOError:
211                             print "Couldn't write to " + relpath
212                         else:
213                             release.write("Archive: %s\n" % (suite))
214                             if version != "":
215                                 release.write("Version: %s\n" % (version))
216                             if nonus:
217                                 release.write("Component: non-US/%s\n" % (sec))
218                             else:
219                                 release.write("Component: %s\n" % (sec))
220                             release.write("Origin: %s\n" % (origin))
221                             release.write("Label: %s\n" % (label))
222                             if notautomatic != "":
223                                 release.write("NotAutomatic: %s\n" % (notautomatic))
224                             release.write("Architecture: %s\n" % (arch))
225                             release.close()
226                             files.append(rel)
227
228             if AptCnf.has_key("tree::%s/main" % (tree)):
229                 sec = string.split(AptCnf["tree::%s/main::Sections" % (tree)])[0]
230                 if sec != "debian-installer":
231                     print "ALERT: weird non debian-installer section in %s" % (tree)
232
233                 for arch in string.split(AptCnf["tree::%s/main::Architectures" % (tree)]):
234                     if arch != "source":  # always true
235                         for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
236                             files.append(file)
237
238         elif AptCnf.has_key("bindirectory::%s" % (tree)):
239             for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
240                 files.append(string.replace(file,tree+"/","",1))
241             for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
242                 files.append(string.replace(file,tree+"/","",1))
243         else:
244             print "ALERT: no tree/bindirectory for %s" % (tree)
245
246         out.write("MD5Sum:\n")
247         print_md5_files(tree, files)
248         out.write("SHA1:\n")
249         print_sha1_files(tree, files)
250
251         out.close()
252         if Cnf.has_key("Dinstall::SigningKeyring"):
253             dest = Cnf["Dir::RootDir"] + tree + "/Release.gpg"
254             if os.path.exists(dest):
255                 os.unlink(dest)
256             keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
257             if Cnf.has_key("Dinstall::SigningPubKeyring"):
258                 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"])
259
260             os.system("gpg %s --no-options --batch --no-tty --armour --detach-sign <%s --output=%s" % (keyring,
261                 Cnf["Dir::RootDir"] + tree + "/Release", dest))
262
263 #######################################################################################
264
265 if __name__ == '__main__':
266     main()
267