[Treepkg-commits] r52 - in trunk: test treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu May 22 21:13:13 CEST 2008


Author: bh
Date: 2008-05-22 21:13:12 +0200 (Thu, 22 May 2008)
New Revision: 52

Added:
   trunk/test/test_debian.py
   trunk/treepkg/debian.py
Log:
Add treepkg/debian.py and test/test_debian.py with code and tests to
extract soem information from debian/control files


Added: trunk/test/test_debian.py
===================================================================
--- trunk/test/test_debian.py	2008-05-22 18:53:14 UTC (rev 51)
+++ trunk/test/test_debian.py	2008-05-22 19:13:12 UTC (rev 52)
@@ -0,0 +1,56 @@
+# Copyright (C) 2008 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Tests for treepkg.debian"""
+
+import unittest
+
+from filesupport import FileTestMixin
+
+from treepkg.debian import DebianControlFile
+
+
+class TestDebianControlFile(unittest.TestCase, FileTestMixin):
+
+    control_contents = """\
+Source: libksba
+Section: libs
+Priority: optional
+Maintainer: Kolab-Konsortium Packager <packaging at kolab-konsortium.de>
+Uploaders: Removed for the test
+Build-Depends: debhelper (>= 4.2), libgpg-error-dev (>= 1.2), bison, autotools-dev, cdbs
+Standards-Version: 3.7.2
+
+Package: libksba-dev
+Section: libdevel
+Architecture: any
+Depends: libksba8 (>= ${Source-Version})
+Replaces: libksba0
+Description: Test description
+ Some more text.
+ .
+ Development library files.
+
+Package: libksba8
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Test description
+ Some more text.
+ .
+ Runtime library files.
+"""
+
+    def test(self):
+        filename = self.create_temp_file(self.id() + "-control",
+                                         self.control_contents)
+        parsed = DebianControlFile(filename)
+        self.assertEquals(parsed.packages,
+                          [('libksba-dev', 'any'), ('libksba8', 'any')])
+        self.assertEquals(parsed.build_depends,
+                          ['debhelper', 'libgpg-error-dev', 'bison',
+                           'autotools-dev', 'cdbs'])


Property changes on: trunk/test/test_debian.py
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: trunk/treepkg/debian.py
===================================================================
--- trunk/treepkg/debian.py	2008-05-22 18:53:14 UTC (rev 51)
+++ trunk/treepkg/debian.py	2008-05-22 19:13:12 UTC (rev 52)
@@ -0,0 +1,56 @@
+# Copyright (C) 2007, 2008 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""Support code for debian packages"""
+
+from treepkg.util import extract_value_for_key
+
+
+class DebianControlFile(object):
+
+    """Parses a debian/control file and makes some of it available.
+
+    Instances have the following instance variables:
+
+      packages -- A list of the names of all packages defined in the
+                  control file
+
+      build_depends -- A list with the names of all package listed as
+                       Build-Depends.
+    """
+
+    def __init__(self, filename):
+        """Initialize the instance from a file given by filename"""
+        self.packages = []
+        self.build_depends = []
+        self.parse(filename)
+
+    def parse(self, filename):
+        lines = [line.strip() for line in open(filename).readlines()]
+        paragraphs = []
+        while lines:
+            try:
+                empty_line = lines.index("")
+            except ValueError:
+                empty_line = len(lines)
+            paragraphs.append(lines[:empty_line])
+            lines = lines[empty_line + 1:]
+
+        self.handle_souce_paragraph(paragraphs[0])
+        for paragraph in paragraphs[1:]:
+            self.handle_package_paragraph(paragraph)
+
+    def handle_souce_paragraph(self, paragraph):
+        raw_deps = extract_value_for_key(paragraph, "Build-Depends:")
+        for dep in raw_deps.split(","):
+            self.build_depends.append(dep.split()[0])
+
+    def handle_package_paragraph(self, paragraph):
+        package_name = extract_value_for_key(paragraph, "Package:")
+        arch = extract_value_for_key(paragraph, "Architecture:")
+        self.packages.append((package_name, arch))
+


Property changes on: trunk/treepkg/debian.py
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native



More information about the Treepkg-commits mailing list