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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Apr 1 15:27:22 CEST 2008


Author: bh
Date: 2008-04-01 15:27:21 +0200 (Tue, 01 Apr 2008)
New Revision: 39

Added:
   trunk/test/test_readconfig.py
Modified:
   trunk/treepkg/readconfig.py
Log:
Extend treepkg.readconfig.read_config:

 - use import_packager_module

 - allow %(name)s substitutions in packager_class values in the pkg_*
   sections


Added: trunk/test/test_readconfig.py
===================================================================
--- trunk/test/test_readconfig.py	2008-04-01 12:30:39 UTC (rev 38)
+++ trunk/test/test_readconfig.py	2008-04-01 13:27:21 UTC (rev 39)
@@ -0,0 +1,98 @@
+# 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 the treepkg.readconfig module"""
+
+import sys
+import os
+import operator
+import unittest
+
+from filesupport import FileTestMixin
+
+from treepkg.readconfig import read_config
+
+
+class TestReadConfig(unittest.TestCase, FileTestMixin):
+
+    config_contents = """\
+[DEFAULT]
+treepkg_dir: /home/builder/mill
+tracks_dir: %(treepkg_dir)s/tracks
+root_cmd: sudo
+pbuilder_dir: %(treepkg_dir)s/pbuilder
+pbuilderrc: %(pbuilder_dir)s/pbuilderrc
+deb_email: treepkg at example.com
+deb_fullname: TreePKG
+debrevision_prefix: treepkg
+
+[treepkg]
+instructions_file: %(treepkg_dir)s/instructions
+check_interval: 3600
+
+[pkg_simple]
+svn_url: svn://example.com/%(name)s/trunk
+base_dir: %(tracks_dir)s/%(name)s
+packager_class: readconfig_test.%(name)s
+
+[pkg_extraargs]
+svn_url: svn://example.com/%(name)s/trunk
+base_dir: %(tracks_dir)s/%(name)s
+packager_class: readconfig_test.extraargs
+orig_tarball: %(base_dir)s/mytarball.tgz
+"""
+
+    files = [("treepkg.cfg", config_contents),
+             ("readconfig_test",
+              [("__init__.py", ""),
+               ("simple.py",
+                "\n".join(["class SourcePackager:",
+                           "    pass",
+                           ""])),
+               ("extraargs.py",
+                "\n".join(["class PackageTrack:",
+                           "    extra_config_desc=['orig_tarball']",
+                           ""]))])]
+
+    def setUp(self):
+        self.directory = self.create_temp_dir(self.id())
+        self.create_files(self.directory, self.files)
+        self.old_path = sys.path
+        sys.path = [self.directory] + sys.path
+
+    def tearDown(self):
+        sys.path = self.old_path
+
+    def test_readconfig(self):
+        config_file = os.path.join(self.directory, "treepkg.cfg")
+        treepkg_opts, packager_opts = read_config(config_file)
+        self.assertEquals(treepkg_opts,
+                    dict(instructions_file="/home/builder/mill/instructions",
+                         check_interval=3600))
+        self.assertEquals(sorted(packager_opts,
+                                 key=operator.itemgetter("name")),
+                          [
+            dict(name="extraargs",
+                 base_dir="/home/builder/mill/tracks/extraargs",
+                 deb_email="treepkg at example.com",
+                 deb_fullname="TreePKG",
+                 debrevision_prefix="treepkg",
+                 packager_class="readconfig_test.extraargs",
+                 pbuilderrc="/home/builder/mill/pbuilder/pbuilderrc",
+                 root_cmd=['sudo'],
+                 svn_url="svn://example.com/extraargs/trunk",
+                 orig_tarball=("/home/builder/mill/"
+                               "tracks/extraargs/mytarball.tgz")),
+            dict(name="simple",
+                 base_dir="/home/builder/mill/tracks/simple",
+                 deb_email="treepkg at example.com",
+                 deb_fullname="TreePKG",
+                 debrevision_prefix="treepkg",
+                 packager_class="readconfig_test.simple",
+                 pbuilderrc="/home/builder/mill/pbuilder/pbuilderrc",
+                 root_cmd=['sudo'],
+                 svn_url="svn://example.com/simple/trunk")])


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

Modified: trunk/treepkg/readconfig.py
===================================================================
--- trunk/treepkg/readconfig.py	2008-04-01 12:30:39 UTC (rev 38)
+++ trunk/treepkg/readconfig.py	2008-04-01 13:27:21 UTC (rev 39)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 by Intevation GmbH
+# Copyright (C) 2007, 2008 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh at intevation.de>
 #
@@ -12,6 +12,7 @@
 from ConfigParser import SafeConfigParser, NoOptionError
 
 import util
+import packager
 
 defaults = dict(root_cmd="sudo")
 
@@ -62,11 +63,12 @@
     packagers = []
     for section in parser.sections():
         if section.startswith("pkg_"):
-            packager_class = parser.get(section, "packager_class")
-            module = util.import_dotted_name(packager_class)
+            vars = dict(name=section[4:])
+            packager_class = parser.get(section, "packager_class", vars=vars)
+            module = packager.import_packager_module(packager_class)
             desc = packager_desc + module.PackageTrack.extra_config_desc
             packagers.append(read_config_section(parser, section, desc,
-                                                 dict(name=section[4:])))
+                                                 defaults=vars))
 
     # main config
     treepkg = read_config_section(parser, "treepkg", treepkg_desc)



More information about the Treepkg-commits mailing list