]> git.decadent.org.uk Git - dak.git/blob - ziyi
[aj] script to create Release files.
[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.1 2001-03-02 02:25:15 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_file (tree, name):
50     path = Cnf["Dir::RootDir"] + tree + "/"
51     try:
52         file_handle = utils.open_file(path + name, "r")
53     except utils.cant_open.exc:
54         print "ALERT: Couldn't open " + path + name
55     else:
56         md5 = apt_pkg.md5sum(file_handle)
57         file_handle.close()
58
59     size = os.stat(path + name)[stat.ST_SIZE]
60
61     out.write(" %s %8d %s\n" % (md5, size, name))
62
63 ################################################################################
64
65 def main ():
66     global Cnf, AptCnf, projectB, out
67     out = sys.stdout;
68
69
70     apt_pkg.init()
71     
72     Cnf = apt_pkg.newConfiguration()
73     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file())
74
75     AptCnf = apt_pkg.newConfiguration()
76     apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
77     print "APT.CONF IS: " + utils.which_apt_conf_file()
78
79     Arguments = [('d',"debug","Ziyi::Options::Debug", "IntVal"),
80                  ('h',"help","Ziyi::Options::Help"),
81                  ('v',"version","Ziyi::Options::Version")]
82
83     suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
84
85     if suites == []:
86         suites = Cnf.SubTree("Suite").List()
87
88     def real_arch(x):
89         return x != "source" and x != "all"
90
91     for suite in suites:
92         print "Processing: " + suite
93         SuiteBlock = Cnf.SubTree("Suite::" + suite)
94
95         if SuiteBlock.has_key("Untouchable"):
96             print "Skipping: " + suite + " (untouchable)"
97             continue
98
99         suite = string.lower(suite)
100
101         origin = SuiteBlock["Origin"]
102         label = SuiteBlock.get("Label", origin)
103         version = SuiteBlock.get("Version", "")
104         codename = SuiteBlock.get("CodeName", "")
105         if SuiteBlock.has_key("Components"):
106             components = SuiteBlock.SubTree("Components").List()
107         else:
108             components = []
109
110         nonus = 1
111         if components != []:
112             for c in components:
113                 if c[:7] != "non-US/":
114                     nonus = 0
115         else:
116             nonus = 0
117         if nonus:
118             longsuite = suite + "/non-US"
119         else:
120             longsuite = suite
121
122         tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
123
124         print Cnf["Dir::RootDir"] + tree + "/Release"
125         out = open(Cnf["Dir::RootDir"] + tree + "/Release", "w")
126
127         out.write("Origin: %s\n" % (origin))
128         out.write("Label: %s\n" % (label))
129         out.write("Suite: %s\n" % (suite))
130         if version != "":
131             out.write("Version: %s\n" % (version))
132         if codename != "":
133             out.write("Codename: %s\n" % (codename))
134         out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
135         out.write("Architectures: %s\n" % (string.join(filter(real_arch, SuiteBlock.SubTree("Architectures").List()))))
136         if components != []:
137             out.write("Components: %s\n" % (string.join(components)))
138
139         out.write("Description: %s\n" % (SuiteBlock["Description"]))
140         out.write("MD5Sum:\n")
141         if AptCnf.has_key("tree::%s" % (tree)):
142             for sec in string.split(AptCnf["tree::%s::Sections" % (tree)]):
143                 for arch in string.split(AptCnf["tree::%s::Architectures" % (tree)]):
144                     if arch == "source":
145                         for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
146                             print_file(tree,file)
147                     else:
148                         rel = "%s/binary-%s/Release" % (sec, arch)
149                         relpath = Cnf["Dir::RootDir"]+tree+"/"+rel
150                         if os.path.exists(relpath):
151                             try:
152                                 release = open(relpath, "w")
153                                 #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
154                             except IOError:
155                                 print "Couldn't write to " + relpath
156                             else:
157                                 release.write("Archive: %s\n" % (suite))
158                                 if version != "":
159                                     release.write("Version: %s\n" % (version))
160                                 if nonus:
161                                     release.write("Component: non-US/%s\n" % (sec))
162                                 else:
163                                     release.write("Component: %s\n" % (sec))
164                                 release.write("Origin: %s\n" % (origin))
165                                 release.write("Label: %s\n" % (label))
166                                 release.write("Architecture: %s\n" % (arch))
167                                 release.close()
168                             print_file(tree,"%s/binary-%s/Release" % (sec,arch))
169                         for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
170                             print_file(tree,file)
171         elif AptCnf.has_key("bindirectory::%s" % (tree)):
172             for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
173                 print_file(tree,string.replace(file,tree+"/","",1))
174             for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
175                 print_file(tree,string.replace(file,tree+"/","",1))
176         else:
177             print "ALERT: no tree/bindirectory for %s" % (tree)
178
179 #######################################################################################
180
181 if __name__ == '__main__':
182     main()
183