[Treepkg-commits] r398 - in branches/treepkg-status: bin test treepkg/info

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Aug 5 18:21:48 CEST 2010


Author: bricks
Date: 2010-08-05 18:21:47 +0200 (Thu, 05 Aug 2010)
New Revision: 398

Modified:
   branches/treepkg-status/bin/publishdebianpackages.py
   branches/treepkg-status/test/test_info.py
   branches/treepkg-status/treepkg/info/data.py
   branches/treepkg-status/treepkg/info/status.py
   branches/treepkg-status/treepkg/info/status.xsd
Log:
review changes


Modified: branches/treepkg-status/bin/publishdebianpackages.py
===================================================================
--- branches/treepkg-status/bin/publishdebianpackages.py	2010-08-02 15:36:12 UTC (rev 397)
+++ branches/treepkg-status/bin/publishdebianpackages.py	2010-08-05 16:21:47 UTC (rev 398)
@@ -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"])

Modified: branches/treepkg-status/test/test_info.py
===================================================================
--- branches/treepkg-status/test/test_info.py	2010-08-02 15:36:12 UTC (rev 397)
+++ branches/treepkg-status/test/test_info.py	2010-08-05 16:21:47 UTC (rev 398)
@@ -8,14 +8,14 @@
 """Tests for treepkg.status.status"""
 
 import unittest
-import os.path
+import os
 import sys
 
 test_dir = os.path.dirname(__file__)
 sys.path.append(os.path.join(test_dir, os.pardir))
 
-from treepkg.info.status import *
-from treepkg.report import get_packager_group
+from treepkg.info.status import TreepkgInfo, TreepkgRootInfo
+
 from filesupport import FileTestMixin
 
 from publishdebianpackages import get_binary_arch

Modified: branches/treepkg-status/treepkg/info/data.py
===================================================================
--- branches/treepkg-status/treepkg/info/data.py	2010-08-02 15:36:12 UTC (rev 397)
+++ branches/treepkg-status/treepkg/info/data.py	2010-08-05 16:21:47 UTC (rev 398)
@@ -15,7 +15,7 @@
 class Package:
     
     def __init__(self, filename, trackname, packagename, packagepath,
-                    arch, md5sum):
+                 arch, md5sum):
         self.filename = filename
         self.trackname = trackname
         self.name = packagename
@@ -26,7 +26,6 @@
 
 class CacheDb:
 
-
     def __init__(self, file):
         self.SELECT_PACKAGE_TMPL = """SELECT * FROM packages 
                                    WHERE filename = ?"""
@@ -77,7 +76,7 @@
         row = self.cursor.fetchone()
         if not row:
             return None
-        return Package(row[0], row[1], row[2], row[3], row[4], row[5]) 
+        return Package(*row) 
 
     def get_old_packages(self, newfiles):
         SELECT_TMPL = """SELECT * FROM packages 

Modified: branches/treepkg-status/treepkg/info/status.py
===================================================================
--- branches/treepkg-status/treepkg/info/status.py	2010-08-02 15:36:12 UTC (rev 397)
+++ branches/treepkg-status/treepkg/info/status.py	2010-08-05 16:21:47 UTC (rev 398)
@@ -45,13 +45,14 @@
     if not node:
         if required:
             raise TreepkgInfoException("Element %s is required as child. But"
-                                    "parent element is not available.")
+                                       "parent element is not available.")
         return None
     childs = node.getElementsByTagName(name)
     if not childs:
         if required:
             raise TreepkgInfoException("Element %s is required as child for %s."
-                        "The XML file must be invalid." % (name, node.nodeName))
+                                       "The XML file must be invalid."
+                                       % (name, node.nodeName))
         return None
     return childs
 
@@ -66,7 +67,7 @@
         self.success = success
         group = get_packager_group(config)
         treepkgrootinfo = TreepkgRootInfo(group.name, group.treepkg_dir, 
-                                        group.tracks_dir)
+                                          group.tracks_dir)
         version = "1.0"
         self.tpkgroot = TreepkgRoot(version, treepkgrootinfo)
         tracks = group.get_package_tracks()
@@ -134,8 +135,9 @@
         pkginfo.add_checksum(checksuminfo)
         revision.add_package(pkginfo)
 
+
 class TreepkgRoot:
-    
+
     def __init__(self, version, info):
         self.version = version
         self.info = info
@@ -311,8 +313,6 @@
         messageele = getChild(statusele, "message")
         message = getTextFromNode(messageele)
         treepkgrevisioninfo = TreepkgTrackRevisionInfo(number, rules, message)
-        treepkgrevisioninfo.packages = []
-        treepkgrevisioninfo.logs = []
         packagesele = getChild(node, "packages")
         packageeles = getChilds(packagesele, "package")
         for packageele in packageeles:
@@ -321,8 +321,7 @@
         logsele = getChild(node, "logs")
         logeles = getChilds(logsele, "log")
         for logele in logeles:
-            treepkgrevisioninfo.logs.append(
-                TreepkgLogInfo.fromxml(logele))
+            treepkgrevisioninfo.logs.append(TreepkgLogInfo.fromxml(logele))
         return treepkgrevisioninfo
 
 class TreepkgLogInfo:
@@ -394,12 +393,13 @@
         path = getTextFromNode(pathele)
         ptype = node.getAttribute("type")
         arch = node.getAttribute("arch")
-        if len(arch) == 0:
+        if not arch:
             arch = None
         packageinfo = TreepkgPackageInfo(name, path, ptype, arch)
         checksumeles = node.getElementsByTagName("checksum")
         for checksumele in checksumeles:
-            packageinfo.checksums.append(TreepkgChecksumInfo.fromxml(checksumele))
+            packageinfo.checksums.append(
+                TreepkgChecksumInfo.fromxml(checksumele))
         return packageinfo
 
 class TreepkgChecksumInfo:
@@ -421,6 +421,6 @@
     def fromxml(node):
         checksum = getTextFromNode(node)
         ctype = node.getAttribute("type")
-        if len(ctype) == 0:
+        if not ctype:
             return TreepkgChecksumInfo(checksum)
         return TreepkgChecksumInfo(checksum, ctype)

Modified: branches/treepkg-status/treepkg/info/status.xsd
===================================================================
--- branches/treepkg-status/treepkg/info/status.xsd	2010-08-02 15:36:12 UTC (rev 397)
+++ branches/treepkg-status/treepkg/info/status.xsd	2010-08-05 16:21:47 UTC (rev 398)
@@ -79,7 +79,7 @@
     <xsd:complexType name="package">
         <xsd:sequence>
             <xsd:element name="name" type="xsd:string" minOccurs="1"/>
-            <xsd:element name="path" type="xsd:string" minOccurs="1">
+            <xsd:element name="path" type="xsd:string" minOccurs="1"/>
             <xsd:element name="checksum" type="tpkg:checksum"
                          maxOccurs="unbounded" default="md5"/>
         </xsd:sequence>



More information about the Treepkg-commits mailing list