# HG changeset patch # User Sascha Teichmann # Date 1294849589 0 # Node ID 247a10201cddf96caef913760782bd8252f952a4 # Parent dc17b62d3cddb86ff3800a452e31b44b2a6a4b45 contrib: copy-latest-pkgs.py copies now sources, too. diff -r dc17b62d3cdd -r 247a10201cdd contrib/bin/copy-latest-pkgs.py --- a/contrib/bin/copy-latest-pkgs.py Tue Jan 11 17:20:02 2011 +0000 +++ b/contrib/bin/copy-latest-pkgs.py Wed Jan 12 16:26:29 2011 +0000 @@ -24,7 +24,9 @@ SAEGEWERKER = "saegewerker" -FIELD = re.compile("([a-zA-Z]+):\s*(.+)") +FIELD = re.compile("([a-zA-Z]+):\s*(.+)") +EPOCH = re.compile("(?:\d+:)(.+)") +UNSHARP = re.compile("([^-]+)") class DebCmp(object): @@ -54,6 +56,7 @@ self.version, self.path) + def deb_info(deb, fields=["Package", "Version"]): """Extract some meta info from a deb file.""" po = subprocess.Popen( @@ -72,7 +75,7 @@ if arch == 'source': continue arch_dir = os.path.join(src, arch) if not os.path.isdir(arch_dir): continue - log.debug("found arch: '%s'" % arch) + log.info("found arch: '%s'" % arch) tracks = {} @@ -82,7 +85,7 @@ packages = {} - log.debug("track dir: '%s'" % track_dir) + log.info("track dir: '%s'" % track_dir) for f in os.listdir(track_dir): if not f.endswith(".deb"): continue deb_path = os.path.join(track_dir, f) @@ -93,12 +96,15 @@ packages.setdefault(info['Package'], []).append(deb_cmp) - tracks[track] =[max(debs) for debs in packages.itervalues()] + if packages: + tracks[track] = [max(debs) for debs in packages.itervalues()] archs[arch] = tracks copy = options.no_hardlinks and copyfile or os.link - action = options.no_hardlinks and "copy" or "link" + action = "%s %%s -> %%s" % (options.no_hardlinks and "copy" or "link") + + track_versions = {} for arch, tracks in archs.iteritems(): log.debug("writing arch '%s'" % arch) @@ -106,21 +112,66 @@ log.debug(" writing track '%s'" % track) dst_dir = os.path.join(dst, arch, track) if not os.path.exists(dst_dir): - try: - os.makedirs(dst_dir) - except: - log.warn(traceback.format_exc()) - continue + try: os.makedirs(dst_dir) + except: log.warn(traceback.format_exc()); continue + + track_ver = track_versions.setdefault(track, set()) for deb in debs: src_path = deb.path dst_path = os.path.join(dst_dir, os.path.basename(src_path)) - log.info(" %s '%s' -> '%s'" % (action, src_path, dst_path)) + log.info(action % (src_path, dst_path)) if os.path.isfile(dst_path): try: os.remove(dst_path) except: log.warn(traceback.format_exc()); continue try: copy(src_path, dst_path) - except: log.warn(traceback.format_exc()) + except: log.error(traceback.format_exc()); continue + + ver = deb.version + m = EPOCH.match(ver) + if m: ver = m.group(1) + + track_ver.add(ver) + + src_source_dir = os.path.join(src, "source") + if not os.path.isdir(src_source_dir): + log.info("no source dir found") + return + + dst_source_dir = os.path.join(dst, "source") + + for track in os.listdir(src_source_dir): + try: versions = track_versions[track] + except KeyError: continue + track_path = os.path.join(src_source_dir, track) + if not os.path.isdir(track_path): continue + log.info("found source track: %s" % track) + unsharp = [UNSHARP.match(x).group(1) for x in versions] + for f in os.listdir(track_path): + f_path = os.path.join(track_path, f) + if not os.path.isfile(f_path): continue + cand = f.split("_", 1) + if len(cand) < 2: continue + cand = cand[1] + for version in f.endswith(".tar.gz") and unsharp or versions: + if cand.startswith(version): break + else: + continue + + dst_track_dir = os.path.join(dst_source_dir, track) + + if not os.path.exists(dst_track_dir): + try: os.makedirs(dst_track_dir) + except: log.error(traceback.format_exc()); continue + + dst_f = os.path.join(dst_track_dir, f) + + log.info(action % (f_path, dst_f)) + if os.path.isfile(dst_f): + try: os.remove(dst_f) + except: log.warn(traceback.format_exc()); continue + try: copy(f_path, dst_f) + except: log.error(traceback.format_exc()); continue def main(): @@ -164,5 +215,6 @@ copy_pkgs(src, dst, options) + if __name__ == '__main__': main()