]> git.decadent.org.uk Git - dak.git/blob - ziyi
sync
[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.7 2001-08-21 15:40:10 troup 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 compressnames (tree,type,file):
38     compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
39     result = []
40     for mode in string.split(compress):
41         if mode == ".":
42             result.append(file)
43         elif mode == "gzip":
44             result.append(file + ".gz")
45         elif mode == "bzip2":
46             result.append(file + ".bz2")
47     return result
48
49 def print_md5_files (tree, files):
50     path = Cnf["Dir::RootDir"] + tree + "/"
51     for name in files:
52         try:
53             file_handle = utils.open_file(path + name, "r")
54         except utils.cant_open_exc:
55             print "ALERT: Couldn't open " + path + name
56         else:
57             md5 = apt_pkg.md5sum(file_handle)
58             file_handle.close()
59
60         size = os.stat(path + name)[stat.ST_SIZE]
61         out.write(" %s         %8d %s\n" % (md5, size, name))
62
63 def print_sha1_files (tree, files):
64     path = Cnf["Dir::RootDir"] + tree + "/"
65     for name in files:
66         try:
67             file_handle = utils.open_file(path + name, "r")
68         except utils.cant_open_exc:
69             print "ALERT: Couldn't open " + path + name
70         else:
71             sha1 = apt_pkg.sha1sum(file_handle)
72             file_handle.close()
73
74         size = os.stat(path + name)[stat.ST_SIZE]
75         out.write(" %s %8d %s\n" % (sha1, size, name))
76
77 ################################################################################
78
79 def main ():
80     global Cnf, AptCnf, projectB, out
81     out = sys.stdout;
82
83
84     apt_pkg.init()
85
86     Cnf = apt_pkg.newConfiguration()
87     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file())
88
89     AptCnf = apt_pkg.newConfiguration()
90     apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
91
92     Arguments = [('d',"debug","Ziyi::Options::Debug", "IntVal"),
93                  ('h',"help","Ziyi::Options::Help"),
94                  ('v',"version","Ziyi::Options::Version")]
95
96     suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
97
98     if suites == []:
99         suites = Cnf.SubTree("Suite").List()
100
101     def real_arch(x):
102         return x != "source" and x != "all"
103
104     for suite in suites:
105         print "Processing: " + suite
106         SuiteBlock = Cnf.SubTree("Suite::" + suite)
107
108         if SuiteBlock.has_key("Untouchable"):
109             print "Skipping: " + suite + " (untouchable)"
110             continue
111
112         suite = string.lower(suite)
113
114         origin = SuiteBlock["Origin"]
115         label = SuiteBlock.get("Label", origin)
116         version = SuiteBlock.get("Version", "")
117         codename = SuiteBlock.get("CodeName", "")
118
119         if SuiteBlock.has_key("NotAutomatic"):
120             notautomatic = "yes"
121         else:
122             notautomatic = ""
123
124         if SuiteBlock.has_key("Components"):
125             components = SuiteBlock.SubTree("Components").List()
126         else:
127             components = []
128
129         nonus = 1
130         if components != []:
131             for c in components:
132                 if c[:7] != "non-US/":
133                     nonus = 0
134         else:
135             nonus = 0
136         if nonus:
137             longsuite = suite + "/non-US"
138         else:
139             longsuite = suite
140
141         tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
142
143         print Cnf["Dir::RootDir"] + tree + "/Release"
144         out = open(Cnf["Dir::RootDir"] + tree + "/Release", "w")
145
146         out.write("Origin: %s\n" % (origin))
147         out.write("Label: %s\n" % (label))
148         out.write("Suite: %s\n" % (suite))
149         if version != "":
150             out.write("Version: %s\n" % (version))
151         if codename != "":
152             out.write("Codename: %s\n" % (codename))
153         out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
154         if notautomatic != "":
155             out.write("NotAutomatic: %s\n" % (notautomatic))
156         out.write("Architectures: %s\n" % (string.join(filter(real_arch, SuiteBlock.SubTree("Architectures").List()))))
157         if components != []:
158             out.write("Components: %s\n" % (string.join(components)))
159
160         out.write("Description: %s\n" % (SuiteBlock["Description"]))
161
162         files = []
163
164         if AptCnf.has_key("tree::%s" % (tree)):
165             for sec in string.split(AptCnf["tree::%s::Sections" % (tree)]):
166                 for arch in string.split(AptCnf["tree::%s::Architectures" % (tree)]):
167                     if arch == "source":
168                         for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
169                             files.append(file)
170                     else:
171                         rel = "%s/binary-%s/Release" % (sec, arch)
172                         relpath = Cnf["Dir::RootDir"]+tree+"/"+rel
173                         if os.path.exists(relpath):
174                             try:
175                                 release = open(relpath, "w")
176                                 #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
177                             except IOError:
178                                 print "Couldn't write to " + relpath
179                             else:
180                                 release.write("Archive: %s\n" % (suite))
181                                 if version != "":
182                                     release.write("Version: %s\n" % (version))
183                                 if nonus:
184                                     release.write("Component: non-US/%s\n" % (sec))
185                                 else:
186                                     release.write("Component: %s\n" % (sec))
187                                 release.write("Origin: %s\n" % (origin))
188                                 release.write("Label: %s\n" % (label))
189                                 if notautomatic != "":
190                                     release.write("NotAutomatic: %s\n" % (notautomatic))
191                                 release.write("Architecture: %s\n" % (arch))
192                                 release.close()
193                             files.append("%s/binary-%s/Release" % (sec,arch))
194
195                         disks = "%s/disks-%s" % (sec, arch)
196                         diskspath = Cnf["Dir::RootDir"]+tree+"/"+disks
197                         if os.path.exists(diskspath):
198                             for dir in os.listdir(diskspath):
199                                 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
200                                     files.append("%s/%s/md5sum.txt" % (disks, dir))
201
202                         for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
203                             files.append(file)
204
205             if AptCnf.has_key("tree::%s/main" % (tree)):
206                 sec = string.split(AptCnf["tree::%s/main::Sections" % (tree)])[0]
207                 if sec != "debian-installer":
208                     print "ALERT: weird non debian-installer section in %s" % (tree)
209
210                 for arch in string.split(AptCnf["tree::%s/main::Architectures" % (tree)]):
211                     if arch != "source":  # always true
212                         for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
213                             files.append(file)
214
215         elif AptCnf.has_key("bindirectory::%s" % (tree)):
216             for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
217                 files.append(string.replace(file,tree+"/","",1))
218             for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
219                 files.append(string.replace(file,tree+"/","",1))
220         else:
221             print "ALERT: no tree/bindirectory for %s" % (tree)
222
223         out.write("MD5Sum:\n")
224         print_md5_files(tree, files)
225         out.write("SHA1:\n")
226         print_sha1_files(tree, files)
227
228         out.close()
229         if Cnf.has_key("Dinstall::SigningKeyring"):
230             dest = Cnf["Dir::RootDir"] + tree + "/Release.gpg"
231             if os.path.exists(dest):
232                  os.unlink(dest)
233             os.system("gpg --secret-keyring \"%s\" --no-options --batch --no-tty --armour --detach-sign <%s --output=%s" % (Cnf["Dinstall::SigningKeyring"],
234                 Cnf["Dir::RootDir"] + tree + "/Release", dest))
235
236 #######################################################################################
237
238 if __name__ == '__main__':
239     main()
240