[Zope-CVS] SVN: zpkgtools/trunk/zpkgtools/ make the configuration
loader determine the URLs for location maps,
Fred L. Drake, Jr.
fdrake at gmail.com
Thu Jun 9 10:35:17 EDT 2005
Log message for revision 30705:
make the configuration loader determine the URLs for location maps,
since it knows the location of the configuration file;
add specific test for Jim's use case
Changed:
U zpkgtools/trunk/zpkgtools/config.py
U zpkgtools/trunk/zpkgtools/locationmap.py
U zpkgtools/trunk/zpkgtools/tests/test_config.py
-=-
Modified: zpkgtools/trunk/zpkgtools/config.py
===================================================================
--- zpkgtools/trunk/zpkgtools/config.py 2005-06-09 13:20:59 UTC (rev 30704)
+++ zpkgtools/trunk/zpkgtools/config.py 2005-06-09 14:35:16 UTC (rev 30705)
@@ -25,8 +25,10 @@
import os
import urllib
+import urlparse
from zpkgsetup import cfgparser
+from zpkgsetup import urlutils
from zpkgtools import locationmap
@@ -107,12 +109,9 @@
"""
p = cfgparser.Parser(f, path, SCHEMA)
cf = p.load()
+ base = urlutils.file_url(os.path.abspath(basedir)) + "/"
for value in cf.resource_map:
- type, rest = urllib.splittype(value)
- if basedir and not type:
- # local path references are relative to the file
- # we're loading
- value = os.path.join(basedir, value)
+ value = urlparse.urljoin(base, value)
self.location_maps.append(value)
if len(cf.include_support_code) > 1:
raise cfgparser.ConfigurationError(
Modified: zpkgtools/trunk/zpkgtools/locationmap.py
===================================================================
--- zpkgtools/trunk/zpkgtools/locationmap.py 2005-06-09 13:20:59 UTC (rev 30704)
+++ zpkgtools/trunk/zpkgtools/locationmap.py 2005-06-09 14:35:16 UTC (rev 30705)
@@ -255,7 +255,7 @@
f = urllib2.urlopen(path, "rU")
else:
f = loader.open(path, "rU")
- base = loader.baseUrl(path)
+ base = path
if mapping is None:
mapping = LocationMap()
try:
Modified: zpkgtools/trunk/zpkgtools/tests/test_config.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_config.py 2005-06-09 13:20:59 UTC (rev 30704)
+++ zpkgtools/trunk/zpkgtools/tests/test_config.py 2005-06-09 14:35:16 UTC (rev 30705)
@@ -14,11 +14,14 @@
"""Tests for zpkgtools.config."""
import os
+import shutil
+import tempfile
import unittest
from StringIO import StringIO
from zpkgsetup import cfgparser
+from zpkgsetup import urlutils
from zpkgtools import config
@@ -46,7 +49,7 @@
self.assertEqual(
cf.location_maps,
["cvs://cvs.example.org/cvsroot:module/package/PACKAGES.txt",
- os.path.join(here, "relative/path.txt")])
+ urlutils.file_url(os.path.join(here, "relative/path.txt"))])
def test_constructor_bad_config_setting(self):
# unknown option:
@@ -78,10 +81,65 @@
sio = StringIO(text)
cf.loadStream(sio, path, basedir)
return cf
-
+
+class ConfigurationLocationMapIntegrationTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp()
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ def test_relative_paths_mapped(self):
+ os.mkdir(os.path.join(self.tmpdir, "releases"))
+ reldir = os.path.join(self.tmpdir, "releases", "Thing")
+ os.mkdir(reldir)
+ cfgpath = os.path.join(reldir, "zpkg.conf")
+ f = open(cfgpath, "w")
+ f.write("resource-map one.map\n")
+ #"resource-map two.map\n")
+ f.close()
+ mapfile = os.path.join(reldir, "one.map")
+ f = open(mapfile, "w")
+ f.write("pkg1 ../../src/pkg1\n"
+ "pkg2 ../Thong\n"
+ "pkg3 some/dir\n")
+ f.close()
+
+ cf = config.Configuration()
+ old_path = os.getcwd()
+ os.chdir(self.tmpdir)
+ try:
+ cf.loadPath("releases/Thing/zpkg.conf")
+ finally:
+ os.chdir(old_path)
+
+ # make sure we're looking at the right location map:
+ self.assertEqual(cf.location_maps, [urlutils.file_url(mapfile)])
+
+ # load the finished map and make sure we get the right values:
+ cf.finalize()
+ expected = urlutils.file_url(
+ os.path.join(self.tmpdir, "src", "pkg1"))
+ self.assertEqual(cf.locations["pkg1"], expected)
+
+ expected = urlutils.file_url(
+ os.path.join(self.tmpdir, "releases", "Thong"))
+ self.assertEqual(cf.locations["pkg2"], expected)
+
+ expected = urlutils.file_url(
+ os.path.join(self.tmpdir, "releases", "Thing", "some", "dir"))
+ self.assertEqual(cf.locations["pkg3"], expected)
+
+
def test_suite():
- return unittest.makeSuite(ConfigTestCase)
+ suite = unittest.TestSuite()
+ suite.addTest(
+ unittest.makeSuite(ConfigTestCase))
+ suite.addTest(
+ unittest.makeSuite(ConfigurationLocationMapIntegrationTestCase))
+ return suite
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
More information about the Zope-CVS
mailing list