diff bin/publishdebianpackages.py @ 441:eadcb1bb54e2

Merged revisions 388-399 via svnmerge from svn+ssh://svn.wald.intevation.org/treepkg/branches/treepkg-status ........ r388 | bricks | 2010-07-28 10:38:50 +0200 (Mi, 28 Jul 2010) | 3 lines fix if statement upload hook should be called if it's not empty ........ r389 | bricks | 2010-07-28 13:38:00 +0200 (Mi, 28 Jul 2010) | 2 lines only rsync specified architectures from cachedir to publishdir ........ r390 | bricks | 2010-07-29 14:07:57 +0200 (Do, 29 Jul 2010) | 2 lines introduced after_copy_hook and made rsync upload to publishdir optional ........ r391 | bricks | 2010-07-29 15:43:39 +0200 (Do, 29 Jul 2010) | 3 lines publish package must be default to get original behaviour be more verbose at publishing ........ r392 | bricks | 2010-07-29 16:50:53 +0200 (Do, 29 Jul 2010) | 2 lines fix handling of showing only successfull builds together with num packages ........ r393 | bricks | 2010-07-29 16:52:42 +0200 (Do, 29 Jul 2010) | 2 lines fixed typo ........ r394 | bricks | 2010-07-29 16:59:10 +0200 (Do, 29 Jul 2010) | 2 lines fixed another typo ........ r395 | bricks | 2010-07-29 18:05:54 +0200 (Do, 29 Jul 2010) | 3 lines fixed another typo treepkg is really slow with many revisions ........ r396 | bricks | 2010-08-02 12:41:55 +0200 (Mo, 02 Aug 2010) | 2 lines fixed typos ........ r397 | bricks | 2010-08-02 17:36:12 +0200 (Mo, 02 Aug 2010) | 3 lines be more error prone in listing different files not checking if a dir exists caused several errors if a build wasn't successful ........ r398 | bricks | 2010-08-05 18:21:47 +0200 (Do, 05 Aug 2010) | 2 lines review changes ........ r399 | bricks | 2010-08-06 13:06:08 +0200 (Fr, 06 Aug 2010) | 4 lines cleanup modules fix test_info testcases added testcases for remove_trailingslashes and expand_filename ........
author Bjoern Ricks <bricks@intevation.de>
date Fri, 06 Aug 2010 13:41:54 +0000
parents 8e0c81870e5e
children 12f3642e1756
line wrap: on
line diff
--- a/bin/publishdebianpackages.py	Fri Aug 06 13:28:47 2010 +0000
+++ b/bin/publishdebianpackages.py	Fri Aug 06 13:41:54 2010 +0000
@@ -10,8 +10,6 @@
 """Publishes selected packages created by treepkg"""
 
 import os
-import os.path
-import re
 import sys
 import shlex
 
@@ -22,23 +20,23 @@
 from treepkg.readconfig import read_config_section, convert_bool
 from treepkg.run import call, capture_output
 from treepkg.cmdexpand import cmdexpand
-from treepkg.publish import *
-from treepkg.util import md5sum
+from treepkg.publish import copy_arch_to_publishdir, prefix_for_remote_command
+
+from treepkg.util import md5sum, expand_filename, remove_trailing_slashes
 from treepkg.info.status import TreepkgInfo
 from treepkg.info.data import Package
 from treepkg.info.data import CacheDb
 
-EMPTY = re.compile(r'\s*')
-
 config_desc = ["distribution", "section", "num_newest",
                "build_user", "build_host", "build_listpackages",
                "publish_user", "publish_host", 
                ("architectures", shlex.split, "armel i386 source"),
-               ("after_upload_hook", shlex.split),
+               ("after_upload_hook", shlex.split, ""),
+               ("after_copy_hook", shlex.split, ""),
+               ("publish_packages", convert_bool, "True"),
                ("publish_remove_old_packages", convert_bool),
                ("publish_dir", remove_trailing_slashes),
-               ("cachedb",
-                lambda s: expand_filename(remove_trailing_slashes(s))),
+               ("cachedb", lambda s: expand_filename(s)),
                ("cachedir",
                 lambda s: expand_filename(remove_trailing_slashes(s)))]
 
@@ -78,18 +76,12 @@
     runremote = prefix_for_remote_command(variables["build_user"],
                                           variables["build_host"])
     xml = capture_output(cmdexpand("@runremote $build_listpackages"
-                                     " --newest=$num_newest"
-                                     " --only-successful",
-                                     runremote=runremote,
-                                     **variables))
+                                   " --newest=$num_newest"
+                                   " --only-successful",
+                                   runremote=runremote,
+                                   **variables))
     return TreepkgInfo.fromxml(xml)
 
-def get_binary_arch(arch): 
-    if not arch is None and not arch.startswith("binary") and \
-            not arch == "source":
-            arch = "binary-" + arch
-    return arch
-
 def check_package_is_new(packagename, destdir, packagemd5sum):
     destpackage = os.path.join(destdir, packagename)
     if not os.path.isfile(destpackage):
@@ -107,11 +99,13 @@
     return md5sum
 
 def sort_trackname_arch(a, b):
-    if a.trackname < b.trackname: return -1
-    if a.trackname > b.trackname: return +1
+    if a.trackname < b.trackname:
+        return -1
+    if a.trackname > b.trackname:
+        return +1
     return cmp(a.arch, b.arch)
 
-def copy_files_to_destdir(destdir, files, variables, quiet = False):
+def copy_files_to_destdir(destdir, files, variables, quiet=False):
     scp_flags = []
     if quiet:
         scp_flags.append("-q")
@@ -137,7 +131,7 @@
             os.remove(package.filename)
     cachedb.remove_packages(oldpackages)
 
-def copy_packages_to_destdir(cachedb, dir, packages, variables, quiet = False):
+def copy_packages_to_destdir(cachedb, dir, packages, variables, quiet=False):
     packages.sort(cmp=sort_trackname_arch)
     package = packages[0]
     trackname = package.trackname
@@ -146,8 +140,7 @@
     files = []
     for package in packages:
         cachedb.add_package(package)
-        if package.trackname != trackname or \
-           package.arch != arch:
+        if package.trackname != trackname or package.arch != arch:
             copy_files_to_destdir(destdir, files, variables, quiet)
             trackname = package.trackname
             arch = package.arch
@@ -160,7 +153,8 @@
                 print "copy new file: %s" % package.name
     copy_files_to_destdir(destdir, files, variables, quiet)
            
-def copy_to_cachedir(variables, track, revision, quiet = False, architectures=None):
+def copy_to_cachedir(variables, track, revision, quiet=False,
+                     architectures=()):
     cachedir = variables["cachedir"]
     cachdebfilename = variables["cachedb"]
     if not quiet:
@@ -168,14 +162,10 @@
     cachedb = CacheDb(cachdebfilename)
     newpackages = []
     treepkginfo = get_treepkg_info(variables)
-    #allowedarchs = set([]) # contains all wanted architectures (incl. source)
-    allarchs = set([]) # contains all present architectures (incl. source)
+    allarchs = set() # contains all present architectures (incl. source)
     binaryallpackages = []
     # change e.g. armel in binary-armel
-    if not architectures is None:
-        allowedarchs = set([get_binary_arch(a) for a in architectures])
-    else:
-        allowedarchs = set([])
+    allowedarchs = set([get_binary_arch(a) for a in architectures])
     for track in treepkginfo.tracks:
         for rev in track.revisions:
             for packageinfo in rev.packages:
@@ -204,9 +194,9 @@
                     newpackages.append(newpackage)
     # copy binary-all packages
     sourcearch = set(["source"])
-    if len(allowedarchs) == 0:
+    if not allowedarchs:
         binallarchs = allarchs - sourcearch 
-    elif len(allarchs) == 0:
+    elif allarchs:
         binallarchs = allowedarchs - sourcearch
     else:
         binallarchs = (allowedarchs & allarchs) - sourcearch
@@ -214,8 +204,9 @@
         for arch in binallarchs:
             filename = os.path.join(cachedir, arch, packageinfo.trackname,
                                     packageinfo.name)
-            newpackage = Package(filename, packageinfo.trackname, packageinfo.name,
-                                 packageinfo.path, arch, get_md5sum(packageinfo))
+            newpackage = Package(filename, packageinfo.trackname,
+                                 packageinfo.name, packageinfo.path, arch,
+                                 get_md5sum(packageinfo))
             newpackages.append(newpackage)
     copy_packages_to_destdir(cachedb, cachedir, newpackages, variables, quiet)
     remove_old_packages(cachedb, newpackages, quiet)
@@ -230,13 +221,22 @@
         section = config["section"]
 
     architectures = config["architectures"]
-    allarchs = copy_to_cachedir(config, track, revision, quiet, architectures)
-    for arch in allarchs:
-        copy_to_publishdir(config, dist, section, arch, quiet)
+    copy_to_cachedir(config, track, revision, quiet, architectures)
+
+    if config["after_copy_hook"]:
+        if not quiet:
+            print "running after copy hook"
+        call(config["after_copy_hook"])
+
+    if config["publish_packages"]:
+        for arch in architectures:
+            if not quiet:
+                print "publish packages for architecture %s" % arch
+            copy_arch_to_publishdir(config, dist, section,
+                                    get_binary_arch(arch), quiet)
 
     # update apt archive
-    if not config["after_upload_hook"] or \
-        not EMPTY.match(config["after_upload_hook"]):
+    if config["after_upload_hook"]:
         if not quiet:
             print "running after upload hook"
         call(config["after_upload_hook"])
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)