changeset 402:01c059298906 treepkg-status

moved packages and logs to revision tag implemented os and arch info
author Bjoern Ricks <bricks@intevation.de>
date Mon, 12 Jul 2010 15:47:42 +0000
parents 2db42a2a9db9
children f9cd55aea87d
files treepkg/info/package.py treepkg/info/status.py treepkg/info/status.xsd
diffstat 3 files changed, 92 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/treepkg/info/package.py	Mon Jul 12 15:47:42 2010 +0000
@@ -0,0 +1,44 @@
+# Copyright (C) 2010 by Intevation GmbH
+# Authors:
+# Bjoern Ricks <bjoern.ricks@intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Classes to read information from binary packages """
+
+import os.path
+
+from treepkg import run
+
+from treepkg.cmdexpand import cmdexpand
+
+
+class DebianPackage:
+
+    def __init__(self, filename):
+        self.filename = filename
+
+    def is_package(self):
+        extension = os.path.splitext(self.filename)[1]
+        return extension.lower() == ".deb"
+
+    def get_architecture(self):
+        if not self.is_package():
+            return None
+        arch = run.capture_output(cmdexpand("dpkg-deb -f $debfile Architecture",
+                                  debfile=self.filename))
+        return arch.strip()
+
+class BinaryPackage:
+    
+    def __init__(self, filename):
+        self.filename = filename
+        self.packagetypes = []
+        self.packagetypes.append(DebianPackage(self.filename))
+
+    def get_architecture(self):
+        for packagetype in self.packagetypes:
+            retval = packagetype.get_architecture()
+            if not retval is None:
+                return retval
--- a/treepkg/info/status.py	Mon Jul 12 15:06:22 2010 +0000
+++ b/treepkg/info/status.py	Mon Jul 12 15:47:42 2010 +0000
@@ -12,6 +12,7 @@
 
 from treepkg.report import get_packager_group
 from treepkg.util import md5sum
+from treepkg.info.package import BinaryPackage
 
 TREEPKG_NAMESPACE_URI = "http://wald.intevation.org/projects/treepkg/"
 TREEPKG_NAMESPACE_PREFIX = "tpkg"
@@ -49,39 +50,42 @@
         if self.numnewestrev > 0:
             revisions = revisions[:self.numnewestrev]
 
+        os =  track.os
+        arch = None
+
         for rev in revisions:
             revision = rev.revision
             rules_revision = rev.rules_revision
             status  = rev.status.status.description  # extend status
-            platforminfo = self.get_platform(rev)
-            revinfo = TreepkgTrackRevisionInfo(revision, rules_revision, 
+            
+            sources = rev.list_source_files()
+            binaries = rev.list_binary_files()
+            for binary in binaries: # get arch
+                binpackage =  BinaryPackage(binary)
+                arch = binpackage.get_architecture()
+                if not arch is None:
+                    break;
+            platforminfo = TreepkgPlatformInfo(os, arch)
+            revinfo = TreepkgTrackRevisionInfo(revision, rules_revision,
                                                status, platforminfo)
+            logs = rev.get_log_files()
+            for (title, filename) in logs:
+                loginfo = TreepkgLogInfo(title, filename)
+                revinfo.add_log(loginfo)
+            for source in sources:
+                self.add_package(source, "source", revinfo)
+            for binary in binaries:
+                self.add_package(binary, "binary", revinfo)
+ 
             trackinfo.add_revision(revinfo)
 
-    def get_platform(self, revision):
-        # FIXME
-        os = "abc os"
-        arch = "def arch"
-        platforminfo = TreepkgPlatformInfo(os, arch)
-        logs = revision.get_log_files()
-        for (title, filename) in logs:
-            loginfo = TreepkgLogInfo(title, filename)
-            platforminfo.add_log(loginfo)
-        sources = revision.list_source_files()
-        for source in sources:
-            self.add_package(source, "source", platforminfo)
-        binaries = revision.list_binary_files()
-        for binary in binaries:
-            self.add_package(binary, "binary", platforminfo)
-        return platforminfo
-
-    def add_package(self, file, type, platform):
+    def add_package(self, file, type, revision):
         name = os.path.basename(file)
         checksum = md5sum(file)
         checksuminfo = TreepkgChecksumInfo(checksum, "md5")
         pkginfo = TreepkgPackageInfo(name, file, type)
         pkginfo.add_checksum(checksuminfo)
-        platform.add_package(pkginfo)
+        revision.add_package(pkginfo)
 
 class TreepkgRootInfo:
 
@@ -153,6 +157,14 @@
         self.rules = rules
         self.status = status
         self.platform = platform
+        self.packages = []
+        self.logs = []
+
+    def add_package(self, package):
+        self.packages.append(package)
+
+    def add_log(self, log):
+        self.logs.append(log)
 
     def toxml(self):
         (doc, root) = createTpkgRoot("revision")
@@ -175,6 +187,16 @@
         root.appendChild(statusele)
         # add <platform>
         root.appendChild(self.platform.toxml())
+        # add <packages>
+        packagesele = createTpkgElement(doc, "packages")
+        for package in self.packages:
+            packagesele.appendChild(package.toxml())
+        root.appendChild(packagesele)
+        # add <logs>
+        logsele = createTpkgElement(doc, "logs")
+        for log in self.logs:
+            logsele.appendChild(log.toxml())
+        root.appendChild(logsele)
         return root
 
 class TreepkgPlatformInfo:
@@ -182,14 +204,8 @@
     def __init__(self, os, arch):
         self.os = os
         self.arch = arch
-        self.packages = []
-        self.logs = []
-
-    def add_package(self, package):
-        self.packages.append(package)
-
-    def add_log(self, log):
-        self.logs.append(log)
+        if self.arch is None:
+            self.arch = "unkown"
 
     def toxml(self):
         (doc, root) = createTpkgRoot("platform")
@@ -203,16 +219,6 @@
         text = doc.createTextNode(self.arch)
         archele.appendChild(text)
         root.appendChild(archele)
-        # add <packages>
-        packagesele = createTpkgElement(doc, "packages")
-        for package in self.packages:
-            packagesele.appendChild(package.toxml())
-        root.appendChild(packagesele)
-        # add <logs>
-        logsele = createTpkgElement(doc, "logs")
-        for log in self.logs:
-            logsele.appendChild(log.toxml())
-        root.appendChild(logsele)
         return root
 
 class TreepkgLogInfo:
--- a/treepkg/info/status.xsd	Mon Jul 12 15:06:22 2010 +0000
+++ b/treepkg/info/status.xsd	Mon Jul 12 15:47:42 2010 +0000
@@ -44,6 +44,8 @@
             <xsd:element name="rules" type="xsd:string" minOccurs="1"/>
             <xsd:element name="status" type="tpkg:revisionstatus" minOccurs="1"/>
             <xsd:element name="platform" type="tpkg:platform" minOccurs="1"/>
+            <xsd:element name="packages" type="tpkg:packages"/>
+            <xsd:element name="logs" type="tpkg:logs"/>
         </xsd:sequence>
     </xsd:complexType>
 
@@ -57,9 +59,7 @@
         <xsd:sequence>
             <xsd:element name="os" type="xsd:string"/>
             <xsd:element name="arch" type="xsd:string"/>
-            <xsd:element name="packages" type="tpkg:packages"/>
-            <xsd:element name="logs" type="tpkg:logs"/>
-        </xsd:sequence>
+       </xsd:sequence>
     </xsd:complexType>
 
     <xsd:complexType name="logs">
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)