Mercurial > treepkg
comparison bin/publishdebianpackages.py @ 438:3a3cad8f6f60 treepkg-status
review changes
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Thu, 05 Aug 2010 16:21:47 +0000 |
parents | eab777e1bafd |
children | 8e0c81870e5e |
comparison
equal
deleted
inserted
replaced
437:48577b11375f | 438:3a3cad8f6f60 |
---|---|
8 # Read the file COPYING coming with the software for details. | 8 # Read the file COPYING coming with the software for details. |
9 | 9 |
10 """Publishes selected packages created by treepkg""" | 10 """Publishes selected packages created by treepkg""" |
11 | 11 |
12 import os | 12 import os |
13 import os.path | |
14 import sys | 13 import sys |
15 import shlex | 14 import shlex |
16 | 15 |
17 from optparse import OptionParser | 16 from optparse import OptionParser |
18 from ConfigParser import SafeConfigParser | 17 from ConfigParser import SafeConfigParser |
19 | 18 |
20 import treepkgcmd | 19 import treepkgcmd |
21 from treepkg.readconfig import read_config_section, convert_bool | 20 from treepkg.readconfig import read_config_section, convert_bool |
22 from treepkg.run import call, capture_output | 21 from treepkg.run import call, capture_output |
23 from treepkg.cmdexpand import cmdexpand | 22 from treepkg.cmdexpand import cmdexpand |
24 from treepkg.publish import * | 23 from treepkg.publish import copy_arch_to_publishdir, expand_filename, \ |
24 prefix_for_remote_command, remove_trailing_slashes | |
25 | |
25 from treepkg.util import md5sum | 26 from treepkg.util import md5sum |
26 from treepkg.info.status import TreepkgInfo | 27 from treepkg.info.status import TreepkgInfo |
27 from treepkg.info.data import Package | 28 from treepkg.info.data import Package |
28 from treepkg.info.data import CacheDb | 29 from treepkg.info.data import CacheDb |
29 | 30 |
30 config_desc = ["distribution", "section", "num_newest", | 31 config_desc = ["distribution", "section", "num_newest", |
31 "build_user", "build_host", "build_listpackages", | 32 "build_user", "build_host", "build_listpackages", |
32 "publish_user", "publish_host", | 33 "publish_user", "publish_host", |
33 ("architectures", shlex.split, "armel i386 source"), | 34 ("architectures", shlex.split, "armel i386 source"), |
34 ("after_upload_hook", shlex.split), | 35 ("after_upload_hook", shlex.split, ""), |
35 ("after_copy_hook", shlex.split), | 36 ("after_copy_hook", shlex.split, ""), |
36 ("publish_packages", convert_bool, "True"), | 37 ("publish_packages", convert_bool, "True"), |
37 ("publish_remove_old_packages", convert_bool), | 38 ("publish_remove_old_packages", convert_bool), |
38 ("publish_dir", remove_trailing_slashes), | 39 ("publish_dir", remove_trailing_slashes), |
39 ("cachedb", | 40 ("cachedb", lambda s: expand_filename(s)), |
40 lambda s: expand_filename(remove_trailing_slashes(s))), | |
41 ("cachedir", | 41 ("cachedir", |
42 lambda s: expand_filename(remove_trailing_slashes(s)))] | 42 lambda s: expand_filename(remove_trailing_slashes(s)))] |
43 | 43 |
44 | 44 |
45 def read_config(filename): | 45 def read_config(filename): |
75 | 75 |
76 def get_treepkg_info(variables): | 76 def get_treepkg_info(variables): |
77 runremote = prefix_for_remote_command(variables["build_user"], | 77 runremote = prefix_for_remote_command(variables["build_user"], |
78 variables["build_host"]) | 78 variables["build_host"]) |
79 xml = capture_output(cmdexpand("@runremote $build_listpackages" | 79 xml = capture_output(cmdexpand("@runremote $build_listpackages" |
80 " --newest=$num_newest" | 80 " --newest=$num_newest" |
81 " --only-successful", | 81 " --only-successful", |
82 runremote=runremote, | 82 runremote=runremote, |
83 **variables)) | 83 **variables)) |
84 return TreepkgInfo.fromxml(xml) | 84 return TreepkgInfo.fromxml(xml) |
85 | 85 |
86 def get_binary_arch(arch): | 86 def get_binary_arch(arch): |
87 if not arch is None and not arch.startswith("binary") and \ | 87 if not arch is None and not arch.startswith("binary") and arch != "source": |
88 not arch == "source": | 88 arch = "binary-" + arch |
89 arch = "binary-" + arch | |
90 return arch | 89 return arch |
91 | 90 |
92 def check_package_is_new(packagename, destdir, packagemd5sum): | 91 def check_package_is_new(packagename, destdir, packagemd5sum): |
93 destpackage = os.path.join(destdir, packagename) | 92 destpackage = os.path.join(destdir, packagename) |
94 if not os.path.isfile(destpackage): | 93 if not os.path.isfile(destpackage): |
104 md5sum = checksum.checksum | 103 md5sum = checksum.checksum |
105 break | 104 break |
106 return md5sum | 105 return md5sum |
107 | 106 |
108 def sort_trackname_arch(a, b): | 107 def sort_trackname_arch(a, b): |
109 if a.trackname < b.trackname: return -1 | 108 if a.trackname < b.trackname: |
110 if a.trackname > b.trackname: return +1 | 109 return -1 |
110 if a.trackname > b.trackname: | |
111 return +1 | |
111 return cmp(a.arch, b.arch) | 112 return cmp(a.arch, b.arch) |
112 | 113 |
113 def copy_files_to_destdir(destdir, files, variables, quiet = False): | 114 def copy_files_to_destdir(destdir, files, variables, quiet=False): |
114 scp_flags = [] | 115 scp_flags = [] |
115 if quiet: | 116 if quiet: |
116 scp_flags.append("-q") | 117 scp_flags.append("-q") |
117 | 118 |
118 if not os.path.exists(destdir): | 119 if not os.path.exists(destdir): |
134 if not quiet: | 135 if not quiet: |
135 print "removing file %s" % package.filename | 136 print "removing file %s" % package.filename |
136 os.remove(package.filename) | 137 os.remove(package.filename) |
137 cachedb.remove_packages(oldpackages) | 138 cachedb.remove_packages(oldpackages) |
138 | 139 |
139 def copy_packages_to_destdir(cachedb, dir, packages, variables, quiet = False): | 140 def copy_packages_to_destdir(cachedb, dir, packages, variables, quiet=False): |
140 packages.sort(cmp=sort_trackname_arch) | 141 packages.sort(cmp=sort_trackname_arch) |
141 package = packages[0] | 142 package = packages[0] |
142 trackname = package.trackname | 143 trackname = package.trackname |
143 arch = package.arch | 144 arch = package.arch |
144 destdir = os.path.join(dir, arch, trackname) | 145 destdir = os.path.join(dir, arch, trackname) |
145 files = [] | 146 files = [] |
146 for package in packages: | 147 for package in packages: |
147 cachedb.add_package(package) | 148 cachedb.add_package(package) |
148 if package.trackname != trackname or \ | 149 if package.trackname != trackname or package.arch != arch: |
149 package.arch != arch: | |
150 copy_files_to_destdir(destdir, files, variables, quiet) | 150 copy_files_to_destdir(destdir, files, variables, quiet) |
151 trackname = package.trackname | 151 trackname = package.trackname |
152 arch = package.arch | 152 arch = package.arch |
153 destdir = os.path.join(dir, arch, trackname) | 153 destdir = os.path.join(dir, arch, trackname) |
154 files = [] | 154 files = [] |
157 files.append(package.sourcepath) | 157 files.append(package.sourcepath) |
158 if not quiet: | 158 if not quiet: |
159 print "copy new file: %s" % package.name | 159 print "copy new file: %s" % package.name |
160 copy_files_to_destdir(destdir, files, variables, quiet) | 160 copy_files_to_destdir(destdir, files, variables, quiet) |
161 | 161 |
162 def copy_to_cachedir(variables, track, revision, quiet = False, architectures=None): | 162 def copy_to_cachedir(variables, track, revision, quiet=False, |
163 architectures=()): | |
163 cachedir = variables["cachedir"] | 164 cachedir = variables["cachedir"] |
164 cachdebfilename = variables["cachedb"] | 165 cachdebfilename = variables["cachedb"] |
165 if not quiet: | 166 if not quiet: |
166 print "using cachedb: %s" % cachdebfilename | 167 print "using cachedb: %s" % cachdebfilename |
167 cachedb = CacheDb(cachdebfilename) | 168 cachedb = CacheDb(cachdebfilename) |
168 newpackages = [] | 169 newpackages = [] |
169 treepkginfo = get_treepkg_info(variables) | 170 treepkginfo = get_treepkg_info(variables) |
170 #allowedarchs = set([]) # contains all wanted architectures (incl. source) | 171 allarchs = set() # contains all present architectures (incl. source) |
171 allarchs = set([]) # contains all present architectures (incl. source) | |
172 binaryallpackages = [] | 172 binaryallpackages = [] |
173 # change e.g. armel in binary-armel | 173 # change e.g. armel in binary-armel |
174 if not architectures is None: | 174 allowedarchs = set([get_binary_arch(a) for a in architectures]) |
175 allowedarchs = set([get_binary_arch(a) for a in architectures]) | |
176 else: | |
177 allowedarchs = set([]) | |
178 for track in treepkginfo.tracks: | 175 for track in treepkginfo.tracks: |
179 for rev in track.revisions: | 176 for rev in track.revisions: |
180 for packageinfo in rev.packages: | 177 for packageinfo in rev.packages: |
181 arch = get_binary_arch(packageinfo.arch) | 178 arch = get_binary_arch(packageinfo.arch) |
182 if packageinfo.type == "binary": | 179 if packageinfo.type == "binary": |
201 packageinfo.path, arch, | 198 packageinfo.path, arch, |
202 get_md5sum(packageinfo)) | 199 get_md5sum(packageinfo)) |
203 newpackages.append(newpackage) | 200 newpackages.append(newpackage) |
204 # copy binary-all packages | 201 # copy binary-all packages |
205 sourcearch = set(["source"]) | 202 sourcearch = set(["source"]) |
206 if len(allowedarchs) == 0: | 203 if not allowedarchs: |
207 binallarchs = allarchs - sourcearch | 204 binallarchs = allarchs - sourcearch |
208 elif len(allarchs) == 0: | 205 elif allarchs: |
209 binallarchs = allowedarchs - sourcearch | 206 binallarchs = allowedarchs - sourcearch |
210 else: | 207 else: |
211 binallarchs = (allowedarchs & allarchs) - sourcearch | 208 binallarchs = (allowedarchs & allarchs) - sourcearch |
212 for packageinfo in binaryallpackages: | 209 for packageinfo in binaryallpackages: |
213 for arch in binallarchs: | 210 for arch in binallarchs: |
214 filename = os.path.join(cachedir, arch, packageinfo.trackname, | 211 filename = os.path.join(cachedir, arch, packageinfo.trackname, |
215 packageinfo.name) | 212 packageinfo.name) |
216 newpackage = Package(filename, packageinfo.trackname, packageinfo.name, | 213 newpackage = Package(filename, packageinfo.trackname, |
217 packageinfo.path, arch, get_md5sum(packageinfo)) | 214 packageinfo.name, packageinfo.path, arch, |
215 get_md5sum(packageinfo)) | |
218 newpackages.append(newpackage) | 216 newpackages.append(newpackage) |
219 copy_packages_to_destdir(cachedb, cachedir, newpackages, variables, quiet) | 217 copy_packages_to_destdir(cachedb, cachedir, newpackages, variables, quiet) |
220 remove_old_packages(cachedb, newpackages, quiet) | 218 remove_old_packages(cachedb, newpackages, quiet) |
221 return binallarchs | 219 return binallarchs |
222 | 220 |
229 section = config["section"] | 227 section = config["section"] |
230 | 228 |
231 architectures = config["architectures"] | 229 architectures = config["architectures"] |
232 copy_to_cachedir(config, track, revision, quiet, architectures) | 230 copy_to_cachedir(config, track, revision, quiet, architectures) |
233 | 231 |
234 if config["after_copy_hook"] and \ | 232 if config["after_copy_hook"]: |
235 len((config["after_copy_hook"][0]).strip()) > 0: | 233 if not quiet: |
236 if not quiet: | 234 print "running after copy hook" |
237 print "running after copy hook" | 235 call(config["after_copy_hook"]) |
238 call(config["after_copy_hook"]) | |
239 | 236 |
240 if config["publish_packages"]: | 237 if config["publish_packages"]: |
241 for arch in architectures: | 238 for arch in architectures: |
242 if not quiet: | 239 if not quiet: |
243 print "publish packages for architecture %s" % arch | 240 print "publish packages for architecture %s" % arch |
244 copy_arch_to_publishdir(config, dist, section, get_binary_arch(arch), | 241 copy_arch_to_publishdir(config, dist, section, |
245 quiet) | 242 get_binary_arch(arch), quiet) |
246 | 243 |
247 # update apt archive | 244 # update apt archive |
248 if config["after_upload_hook"] and \ | 245 if config["after_upload_hook"]: |
249 len((config["after_upload_hook"][0]).strip()) > 0: | |
250 if not quiet: | 246 if not quiet: |
251 print "running after upload hook" | 247 print "running after upload hook" |
252 call(config["after_upload_hook"]) | 248 call(config["after_upload_hook"]) |
253 | 249 |
254 def main(): | 250 def main(): |