changeset 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 822a4d31efda
files contrib/bin/copy-latest-pkgs.py
diffstat 1 files changed, 64 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)