[Treepkg-commits] r506 - trunk/contrib/bin

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jan 12 17:26:29 CET 2011


Author: teichmann
Date: 2011-01-12 17:26:29 +0100 (Wed, 12 Jan 2011)
New Revision: 506

Modified:
   trunk/contrib/bin/copy-latest-pkgs.py
Log:
contrib: copy-latest-pkgs.py copies now sources, too.


Modified: trunk/contrib/bin/copy-latest-pkgs.py
===================================================================
--- trunk/contrib/bin/copy-latest-pkgs.py	2011-01-11 17:20:02 UTC (rev 505)
+++ trunk/contrib/bin/copy-latest-pkgs.py	2011-01-12 16:26:29 UTC (rev 506)
@@ -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,36 +96,84 @@
 
                 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)
         for track, debs in tracks.iteritems():
             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():
     usage = "usage: %prog [options] src-dir dst-dir"
     parser = OptionParser(usage=usage)
@@ -164,5 +215,6 @@
 
     copy_pkgs(src, dst, options)
 
+
 if __name__ == '__main__':
     main()



More information about the Treepkg-commits mailing list