comparison contrib/bin/copy-latest-pkgs.py @ 543:247a10201cdd

contrib: copy-latest-pkgs.py copies now sources, too.
author Sascha Teichmann <teichmann@intevation.de>
date Wed, 12 Jan 2011 16:26:29 +0000
parents dc17b62d3cdd
children
comparison
equal deleted inserted replaced
542:dc17b62d3cdd 543:247a10201cdd
22 log.setLevel(logging.WARNING) 22 log.setLevel(logging.WARNING)
23 log.addHandler(logging.StreamHandler(sys.stderr)) 23 log.addHandler(logging.StreamHandler(sys.stderr))
24 24
25 SAEGEWERKER = "saegewerker" 25 SAEGEWERKER = "saegewerker"
26 26
27 FIELD = re.compile("([a-zA-Z]+):\s*(.+)") 27 FIELD = re.compile("([a-zA-Z]+):\s*(.+)")
28 EPOCH = re.compile("(?:\d+:)(.+)")
29 UNSHARP = re.compile("([^-]+)")
28 30
29 31
30 class DebCmp(object): 32 class DebCmp(object):
31 """Helper class to make deb files comparable 33 """Helper class to make deb files comparable
32 by there versions. 34 by there versions.
52 def __str__(self): 54 def __str__(self):
53 return "version: %s / path: %s" % ( 55 return "version: %s / path: %s" % (
54 self.version, 56 self.version,
55 self.path) 57 self.path)
56 58
59
57 def deb_info(deb, fields=["Package", "Version"]): 60 def deb_info(deb, fields=["Package", "Version"]):
58 """Extract some meta info from a deb file.""" 61 """Extract some meta info from a deb file."""
59 po = subprocess.Popen( 62 po = subprocess.Popen(
60 ["dpkg-deb", "-f", deb] + fields, 63 ["dpkg-deb", "-f", deb] + fields,
61 stdout=subprocess.PIPE) 64 stdout=subprocess.PIPE)
70 73
71 for arch in os.listdir(src): 74 for arch in os.listdir(src):
72 if arch == 'source': continue 75 if arch == 'source': continue
73 arch_dir = os.path.join(src, arch) 76 arch_dir = os.path.join(src, arch)
74 if not os.path.isdir(arch_dir): continue 77 if not os.path.isdir(arch_dir): continue
75 log.debug("found arch: '%s'" % arch) 78 log.info("found arch: '%s'" % arch)
76 79
77 tracks = {} 80 tracks = {}
78 81
79 for track in os.listdir(arch_dir): 82 for track in os.listdir(arch_dir):
80 track_dir = os.path.join(arch_dir, track) 83 track_dir = os.path.join(arch_dir, track)
81 if not os.path.isdir(track_dir): continue 84 if not os.path.isdir(track_dir): continue
82 85
83 packages = {} 86 packages = {}
84 87
85 log.debug("track dir: '%s'" % track_dir) 88 log.info("track dir: '%s'" % track_dir)
86 for f in os.listdir(track_dir): 89 for f in os.listdir(track_dir):
87 if not f.endswith(".deb"): continue 90 if not f.endswith(".deb"): continue
88 deb_path = os.path.join(track_dir, f) 91 deb_path = os.path.join(track_dir, f)
89 if not os.path.isfile(deb_path): continue 92 if not os.path.isfile(deb_path): continue
90 93
91 info = deb_info(deb_path) 94 info = deb_info(deb_path)
92 deb_cmp = DebCmp(info['Version'], deb_path) 95 deb_cmp = DebCmp(info['Version'], deb_path)
93 96
94 packages.setdefault(info['Package'], []).append(deb_cmp) 97 packages.setdefault(info['Package'], []).append(deb_cmp)
95 98
96 tracks[track] =[max(debs) for debs in packages.itervalues()] 99 if packages:
100 tracks[track] = [max(debs) for debs in packages.itervalues()]
97 101
98 archs[arch] = tracks 102 archs[arch] = tracks
99 103
100 copy = options.no_hardlinks and copyfile or os.link 104 copy = options.no_hardlinks and copyfile or os.link
101 action = options.no_hardlinks and "copy" or "link" 105 action = "%s %%s -> %%s" % (options.no_hardlinks and "copy" or "link")
106
107 track_versions = {}
102 108
103 for arch, tracks in archs.iteritems(): 109 for arch, tracks in archs.iteritems():
104 log.debug("writing arch '%s'" % arch) 110 log.debug("writing arch '%s'" % arch)
105 for track, debs in tracks.iteritems(): 111 for track, debs in tracks.iteritems():
106 log.debug(" writing track '%s'" % track) 112 log.debug(" writing track '%s'" % track)
107 dst_dir = os.path.join(dst, arch, track) 113 dst_dir = os.path.join(dst, arch, track)
108 if not os.path.exists(dst_dir): 114 if not os.path.exists(dst_dir):
109 try: 115 try: os.makedirs(dst_dir)
110 os.makedirs(dst_dir) 116 except: log.warn(traceback.format_exc()); continue
111 except: 117
112 log.warn(traceback.format_exc()) 118 track_ver = track_versions.setdefault(track, set())
113 continue
114 119
115 for deb in debs: 120 for deb in debs:
116 src_path = deb.path 121 src_path = deb.path
117 dst_path = os.path.join(dst_dir, os.path.basename(src_path)) 122 dst_path = os.path.join(dst_dir, os.path.basename(src_path))
118 log.info(" %s '%s' -> '%s'" % (action, src_path, dst_path)) 123 log.info(action % (src_path, dst_path))
119 if os.path.isfile(dst_path): 124 if os.path.isfile(dst_path):
120 try: os.remove(dst_path) 125 try: os.remove(dst_path)
121 except: log.warn(traceback.format_exc()); continue 126 except: log.warn(traceback.format_exc()); continue
122 try: copy(src_path, dst_path) 127 try: copy(src_path, dst_path)
123 except: log.warn(traceback.format_exc()) 128 except: log.error(traceback.format_exc()); continue
129
130 ver = deb.version
131 m = EPOCH.match(ver)
132 if m: ver = m.group(1)
133
134 track_ver.add(ver)
135
136 src_source_dir = os.path.join(src, "source")
137 if not os.path.isdir(src_source_dir):
138 log.info("no source dir found")
139 return
140
141 dst_source_dir = os.path.join(dst, "source")
142
143 for track in os.listdir(src_source_dir):
144 try: versions = track_versions[track]
145 except KeyError: continue
146 track_path = os.path.join(src_source_dir, track)
147 if not os.path.isdir(track_path): continue
148 log.info("found source track: %s" % track)
149 unsharp = [UNSHARP.match(x).group(1) for x in versions]
150 for f in os.listdir(track_path):
151 f_path = os.path.join(track_path, f)
152 if not os.path.isfile(f_path): continue
153 cand = f.split("_", 1)
154 if len(cand) < 2: continue
155 cand = cand[1]
156 for version in f.endswith(".tar.gz") and unsharp or versions:
157 if cand.startswith(version): break
158 else:
159 continue
160
161 dst_track_dir = os.path.join(dst_source_dir, track)
162
163 if not os.path.exists(dst_track_dir):
164 try: os.makedirs(dst_track_dir)
165 except: log.error(traceback.format_exc()); continue
166
167 dst_f = os.path.join(dst_track_dir, f)
168
169 log.info(action % (f_path, dst_f))
170 if os.path.isfile(dst_f):
171 try: os.remove(dst_f)
172 except: log.warn(traceback.format_exc()); continue
173 try: copy(f_path, dst_f)
174 except: log.error(traceback.format_exc()); continue
124 175
125 176
126 def main(): 177 def main():
127 usage = "usage: %prog [options] src-dir dst-dir" 178 usage = "usage: %prog [options] src-dir dst-dir"
128 parser = OptionParser(usage=usage) 179 parser = OptionParser(usage=usage)
162 log.error("Need to run as '%s'" % SAEGEWERKER) 213 log.error("Need to run as '%s'" % SAEGEWERKER)
163 sys.exit(1) 214 sys.exit(1)
164 215
165 copy_pkgs(src, dst, options) 216 copy_pkgs(src, dst, options)
166 217
218
167 if __name__ == '__main__': 219 if __name__ == '__main__':
168 main() 220 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)