diff bin/publishdebianpackages.py @ 438:3a3cad8f6f60 treepkg-status

review changes
author Bjoern Ricks <bricks@intevation.de>
date Thu, 05 Aug 2010 16:21:47 +0000
parents eab777e1bafd
children 8e0c81870e5e
line wrap: on
line diff
--- a/bin/publishdebianpackages.py	Mon Aug 02 15:36:12 2010 +0000
+++ b/bin/publishdebianpackages.py	Thu Aug 05 16:21:47 2010 +0000
@@ -10,7 +10,6 @@
 """Publishes selected packages created by treepkg"""
 
 import os
-import os.path
 import sys
 import shlex
 
@@ -21,7 +20,9 @@
 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.publish import copy_arch_to_publishdir, expand_filename, \
+     prefix_for_remote_command, remove_trailing_slashes
+
 from treepkg.util import md5sum
 from treepkg.info.status import TreepkgInfo
 from treepkg.info.data import Package
@@ -31,13 +32,12 @@
                "build_user", "build_host", "build_listpackages",
                "publish_user", "publish_host", 
                ("architectures", shlex.split, "armel i386 source"),
-               ("after_upload_hook", shlex.split),
-               ("after_copy_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)))]
 
@@ -77,16 +77,15 @@
     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
+def get_binary_arch(arch):
+    if not arch is None and not arch.startswith("binary") and arch != "source":
+        arch = "binary-" + arch
     return arch
 
 def check_package_is_new(packagename, destdir, packagemd5sum):
@@ -106,11 +105,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")
@@ -136,7 +137,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
@@ -145,8 +146,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
@@ -159,7 +159,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:
@@ -167,14 +168,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:
@@ -203,9 +200,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
@@ -213,8 +210,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)
@@ -231,22 +229,20 @@
     architectures = config["architectures"]
     copy_to_cachedir(config, track, revision, quiet, architectures)
 
-    if config["after_copy_hook"] and \
-        len((config["after_copy_hook"][0]).strip()) > 0:
-            if not quiet:
-                print "running after copy hook"
-            call(config["after_copy_hook"])
+    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)
+            copy_arch_to_publishdir(config, dist, section,
+                                    get_binary_arch(arch), quiet)
 
     # update apt archive
-    if config["after_upload_hook"] and \
-        len((config["after_upload_hook"][0]).strip()) > 0:
+    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)