[Zope-CVS] SVN: zpkgtools/branches/jim-relpath/zpkgtools/ Adding
logic to convert base paths to file urls.
Jim Fulton
jim at zope.com
Wed Jun 8 07:44:56 EDT 2005
Log message for revision 30684:
Adding logic to convert base paths to file urls.
Changed:
U zpkgtools/branches/jim-relpath/zpkgtools/locationmap.py
U zpkgtools/branches/jim-relpath/zpkgtools/tests/test_locationmap.py
-=-
Modified: zpkgtools/branches/jim-relpath/zpkgtools/locationmap.py
===================================================================
--- zpkgtools/branches/jim-relpath/zpkgtools/locationmap.py 2005-06-08 11:42:34 UTC (rev 30683)
+++ zpkgtools/branches/jim-relpath/zpkgtools/locationmap.py 2005-06-08 11:44:56 UTC (rev 30684)
@@ -30,6 +30,7 @@
_logger = logging.getLogger(__name__)
+urlmatch = re.compile(r'[a-zA-Z]+://').match
class MapLoadingError(ValueError):
def __init__(self, message, filename, lineno):
@@ -168,6 +169,15 @@
except ValueError:
# conventional URL
if cvsbase is None:
+ if base is None:
+ base = ''
+
+ if not urlmatch(base):
+ base = ('file://' +
+ urllib.pathname2url(os.path.abspath(base))
+ + '/'
+ )
+
url = urlparse.urljoin(base, url)
else:
if isinstance(cvsurl, cvsloader.RepositoryUrl):
Modified: zpkgtools/branches/jim-relpath/zpkgtools/tests/test_locationmap.py
===================================================================
--- zpkgtools/branches/jim-relpath/zpkgtools/tests/test_locationmap.py 2005-06-08 11:42:34 UTC (rev 30683)
+++ zpkgtools/branches/jim-relpath/zpkgtools/tests/test_locationmap.py 2005-06-08 11:44:56 UTC (rev 30684)
@@ -165,14 +165,22 @@
sio = StringIO("foo.* cvs://cvs.example.org/cvsroot:foo\n"
"bar.* file:///some/path/\n"
"bat.* some/path\n")
+
+ old_getcwd = os.getcwd
+ os.getcwd = lambda : '/home/dudette/python/project'
+
map = locationmap.load(sio)
+
+ os.getcwd = old_getcwd
+
eq = self.assertEqual
self.assert_("foo.bar" in map)
self.assert_("bar.foo" in map)
self.assert_("bat.splat.funk" in map)
eq(map["foo.bar"], "cvs://cvs.example.org/cvsroot:foo/bar")
eq(map["bar.foo"], "file:///some/path/foo")
- eq(map["bat.splat.funk"], "some/path/splat/funk")
+ eq(map["bat.splat.funk"],
+ "file:///home/dudette/python/project/some/path/splat/funk")
def test_unmatched_wildcard(self):
sio = StringIO("foo.bar.* some/path\n")
@@ -326,7 +334,81 @@
self.assert_(m.has_key("bat"))
self.assertEqual(m["bat"], 3)
+ def test_load_w_relative_paths(self):
+ map_file = StringIO('''
+foo svn+ssh://svn.zope.org/repos/main/Foo/trunk/src/foo
+bar ../../bar
+baz baz
+spam file://spam.com/spam
+tools cvs://anonymous@cvs.sourceforge.net:pserver/'''
+ '''cvsroot/python:python/n\ondist/sandbox/setuptools/setuptools
+ ''')
+ old_getcwd = os.getcwd
+ os.getcwd = lambda : '/home/dudette/python/project'
+
+ mappingNone = locationmap.load(map_file)
+
+ map_file.seek(0)
+ mapping = locationmap.load(map_file, '')
+
+ map_file.seek(0)
+ mappingAbsBase = locationmap.load(map_file, '/projects/special/demo')
+
+ map_file.seek(0)
+ mappingRelBase = locationmap.load(map_file, 'special/demo')
+
+ map_file.seek(0)
+ mappingUrlBase = locationmap.load(map_file, 'http://acme.com/xxx')
+
+ os.getcwd = old_getcwd
+
+ # Several of the locations should be unaffected
+ for m in (mappingNone, mappingAbsBase, mappingRelBase,
+ mappingUrlBase):
+
+ self.assertEqual(
+ m['foo'],
+ 'svn+ssh://svn.zope.org/repos/main/Foo/trunk/src/foo',
+ )
+
+ self.assertEqual(
+ mappingNone['spam'],
+ 'file://spam.com/spam',
+ )
+
+ self.assertEqual(
+ mappingNone['tools'],
+ 'cvs://anonymous@cvs.sourceforge.net:pserver/'
+ 'cvsroot/python:python/n\ondist/sandbox/setuptools/setuptools'
+ )
+
+ self.assertEqual(
+ mappingNone['bar'],
+ 'file:///home/dudette/bar',
+ )
+ self.assertEqual(
+ mappingNone['baz'],
+ 'file:///home/dudette/python/project/baz',
+ )
+
+
+
+
+ """
+We often want to use relative file paths in location maps.
+
+We can currently use URL, including file URLs. But these must be absolute.
+
+Let's look at a sample map file that has several kinds of URLs and
+relative paths:
+
+
+Now, we'll load this map.
+
+
+"""
+
def test_suite():
suite = unittest.makeSuite(LoadTestCase)
suite.addTest(unittest.makeSuite(CvsWorkingDirectoryTestCase))
More information about the Zope-CVS
mailing list