]> git.decadent.org.uk Git - dak.git/blob - ziyi
Add new top level directories
[dak.git] / ziyi
1 #!/usr/bin/env python
2
3 # Create all the Release files
4
5 # Copyright (C) 2001, 2002  Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.27 2005-11-15 09:50:32 ajt 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 sys, os, popen2, tempfile, stat, time
27 import utils
28 import apt_pkg
29
30 ################################################################################
31
32 Cnf = None
33 projectB = None
34 out = None
35 AptCnf = None
36
37 ################################################################################
38
39 def usage (exit_code=0):
40     print """Usage: ziyi [OPTION]... [SUITE]...
41 Generate Release files (for SUITE).
42
43   -h, --help                 show this help and exit
44
45 If no SUITE is given Release files are generated for all suites."""
46
47     sys.exit(exit_code)
48
49 ################################################################################
50
51 def add_tiffani (files, path, indexstem):
52     index = "%s.diff/Index" % (indexstem)
53     filepath = "%s/%s" % (path, index)
54     if os.path.exists(filepath):
55         #print "ALERT: there was a tiffani file %s" % (filepath)
56         files.append(index)
57
58 def compressnames (tree,type,file):
59     compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
60     result = []
61     cl = compress.split()
62     uncompress = ("." not in cl)
63     for mode in compress.split():
64         if mode == ".":
65             result.append(file)
66         elif mode == "gzip":
67             if uncompress:
68                 result.append("<zcat/.gz>" + file)
69                 uncompress = 0
70             result.append(file + ".gz")
71         elif mode == "bzip2":
72             if uncompress:
73                 result.append("<bzcat/.bz2>" + file)
74                 uncompress = 0
75             result.append(file + ".bz2")
76     return result
77
78 def create_temp_file (cmd):
79     f = tempfile.TemporaryFile()
80     r = popen2.popen2(cmd)
81     r[1].close()
82     r = r[0]
83     size = 0
84     while 1:
85         x = r.readline()
86         if not x:
87             r.close()
88             del x,r
89             break
90         f.write(x)
91         size += len(x)
92     f.flush()
93     f.seek(0)
94     return (size, f)
95
96 def print_md5sha_files (tree, files, hashop):
97     path = Cnf["Dir::Root"] + tree + "/"
98     for name in files:
99         try:
100             if name[0] == "<":
101                 j = name.index("/")
102                 k = name.index(">")
103                 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
104                 (size, file_handle) = create_temp_file("%s %s%s%s" %
105                     (cat, path, name, ext))
106             else:
107                 size = os.stat(path + name)[stat.ST_SIZE]
108                 file_handle = utils.open_file(path + name)
109         except utils.cant_open_exc:
110             print "ALERT: Couldn't open " + path + name
111         else:
112             hash = hashop(file_handle)
113             file_handle.close()
114             out.write(" %s         %8d %s\n" % (hash, size, name))
115
116 def print_md5_files (tree, files):
117     print_md5sha_files (tree, files, apt_pkg.md5sum)
118
119 def print_sha1_files (tree, files):
120     print_md5sha_files (tree, files, apt_pkg.sha1sum)
121
122 ################################################################################
123
124 def main ():
125     global Cnf, AptCnf, projectB, out
126     out = sys.stdout;
127
128     Cnf = utils.get_conf()
129
130     Arguments = [('h',"help","Ziyi::Options::Help")];
131     for i in [ "help" ]:
132         if not Cnf.has_key("Ziyi::Options::%s" % (i)):
133             Cnf["Ziyi::Options::%s" % (i)] = "";
134
135     suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
136     Options = Cnf.SubTree("Ziyi::Options")
137
138     if Options["Help"]:
139         usage();
140
141     AptCnf = apt_pkg.newConfiguration()
142     apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
143
144     if not suites:
145         suites = Cnf.SubTree("Suite").List()
146
147     for suite in suites:
148         print "Processing: " + suite
149         SuiteBlock = Cnf.SubTree("Suite::" + suite)
150
151         if SuiteBlock.has_key("Untouchable"):
152             print "Skipping: " + suite + " (untouchable)"
153             continue
154
155         suite = suite.lower()
156
157         origin = SuiteBlock["Origin"]
158         label = SuiteBlock.get("Label", origin)
159         version = SuiteBlock.get("Version", "")
160         codename = SuiteBlock.get("CodeName", "")
161
162         if SuiteBlock.has_key("NotAutomatic"):
163             notautomatic = "yes"
164         else:
165             notautomatic = ""
166
167         if SuiteBlock.has_key("Components"):
168             components = SuiteBlock.ValueList("Components")
169         else:
170             components = []
171
172         suite_suffix = Cnf.Find("Dinstall::SuiteSuffix");
173         if components and suite_suffix:
174             longsuite = suite + "/" + suite_suffix;
175         else:
176             longsuite = suite;
177
178         tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
179
180         if AptCnf.has_key("tree::%s" % (tree)):
181             pass
182         elif AptCnf.has_key("bindirectory::%s" % (tree)):
183             pass
184         else:
185             aptcnf_filename = os.path.basename(utils.which_apt_conf_file());
186             print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename);
187             continue
188
189         print Cnf["Dir::Root"] + tree + "/Release"
190         out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
191
192         out.write("Origin: %s\n" % (origin))
193         out.write("Label: %s\n" % (label))
194         out.write("Suite: %s\n" % (suite))
195         if version != "":
196             out.write("Version: %s\n" % (version))
197         if codename != "":
198             out.write("Codename: %s\n" % (codename))
199         out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
200         if notautomatic != "":
201             out.write("NotAutomatic: %s\n" % (notautomatic))
202         out.write("Architectures: %s\n" % (" ".join(filter(utils.real_arch, SuiteBlock.ValueList("Architectures")))))
203         if components:
204             out.write("Components: %s\n" % (" ".join(components)))
205
206         out.write("Description: %s\n" % (SuiteBlock["Description"]))
207
208         files = []
209
210         if AptCnf.has_key("tree::%s" % (tree)):
211             for sec in AptCnf["tree::%s::Sections" % (tree)].split():
212                 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
213                     if arch == "source":
214                         filepath = "%s/%s/Sources" % (sec, arch)
215                         for file in compressnames("tree::%s" % (tree), "Sources", filepath):
216                             files.append(file)
217                         add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
218                     else:
219                         disks = "%s/disks-%s" % (sec, arch)
220                         diskspath = Cnf["Dir::Root"]+tree+"/"+disks
221                         if os.path.exists(diskspath):
222                             for dir in os.listdir(diskspath):
223                                 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
224                                     files.append("%s/%s/md5sum.txt" % (disks, dir))
225
226                         filepath = "%s/binary-%s/Packages" % (sec, arch)
227                         for file in compressnames("tree::%s" % (tree), "Packages", filepath):
228                             files.append(file)
229                         add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
230
231                     if arch == "source":
232                         rel = "%s/%s/Release" % (sec, arch)
233                     else:
234                         rel = "%s/binary-%s/Release" % (sec, arch)
235                     relpath = Cnf["Dir::Root"]+tree+"/"+rel
236
237                     try:
238                         release = open(relpath, "w")
239                         #release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w")
240                     except IOError:
241                         utils.fubar("Couldn't write to " + relpath);
242
243                     release.write("Archive: %s\n" % (suite))
244                     if version != "":
245                         release.write("Version: %s\n" % (version))
246                     if suite_suffix:
247                         release.write("Component: %s/%s\n" % (suite_suffix,sec));
248                     else:
249                         release.write("Component: %s\n" % (sec));
250                     release.write("Origin: %s\n" % (origin))
251                     release.write("Label: %s\n" % (label))
252                     if notautomatic != "":
253                         release.write("NotAutomatic: %s\n" % (notautomatic))
254                     release.write("Architecture: %s\n" % (arch))
255                     release.close()
256                     files.append(rel)
257
258             if AptCnf.has_key("tree::%s/main" % (tree)):
259                 sec = AptCnf["tree::%s/main::Sections" % (tree)].split()[0]
260                 if sec != "debian-installer":
261                     print "ALERT: weird non debian-installer section in %s" % (tree)
262
263                 for arch in AptCnf["tree::%s/main::Architectures" % (tree)].split():
264                     if arch != "source":  # always true
265                         for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
266                             files.append(file)
267             elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
268                 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
269                 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
270                 if sec != "debian-installer":
271                     print "ALERT: weird non debian-installer section in %s" % (usetree)
272  
273                 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
274                     if arch != "source":  # always true
275                         for file in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
276                             files.append(file)
277
278         elif AptCnf.has_key("bindirectory::%s" % (tree)):
279             for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
280                 files.append(file.replace(tree+"/","",1))
281             for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
282                 files.append(file.replace(tree+"/","",1))
283         else:
284             print "ALERT: no tree/bindirectory for %s" % (tree)
285
286         out.write("MD5Sum:\n")
287         print_md5_files(tree, files)
288         out.write("SHA1:\n")
289         print_sha1_files(tree, files)
290
291         out.close()
292         if Cnf.has_key("Dinstall::SigningKeyring"):
293             keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
294             if Cnf.has_key("Dinstall::SigningPubKeyring"):
295                 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
296
297             arguments = "--no-options --batch --no-tty --armour"
298             if Cnf.has_key("Dinstall::SigningKeyIds"):
299                 signkeyids = Cnf["Dinstall::SigningKeyIds"].split()
300             else:
301                 signkeyids = [""]
302
303             dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
304             if os.path.exists(dest):
305                 os.unlink(dest)
306
307             for keyid in signkeyids:
308                 if keyid != "": defkeyid = "--default-key %s" % keyid
309                 else: defkeyid = ""
310                 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
311                         (keyring, defkeyid, arguments,
312                         Cnf["Dir::Root"] + tree + "/Release", dest))
313
314 #######################################################################################
315
316 if __name__ == '__main__':
317     main()
318