[csw-devel] SF.net SVN: gar:[12134] csw/mgar/gar/v2/lib/python
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Thu Dec 30 14:55:50 CET 2010
Revision: 12134
http://gar.svn.sourceforge.net/gar/?rev=12134&view=rev
Author: wahwah
Date: 2010-12-30 13:55:50 +0000 (Thu, 30 Dec 2010)
Log Message:
-----------
checkpkg: New function: ResolveSymlink
Plus a unit test for it.
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/struct_util.py
csw/mgar/gar/v2/lib/python/struct_util_test.py
Modified: csw/mgar/gar/v2/lib/python/struct_util.py
===================================================================
--- csw/mgar/gar/v2/lib/python/struct_util.py 2010-12-30 13:55:16 UTC (rev 12133)
+++ csw/mgar/gar/v2/lib/python/struct_util.py 2010-12-30 13:55:50 UTC (rev 12134)
@@ -1,6 +1,8 @@
"""A module for generic data structure processing functions.
"""
+import os
+
def IndexDictsBy(list_of_dicts, field_key):
"""Creates an index of list of dictionaries by a field name.
@@ -11,3 +13,9 @@
index.setdefault(d[field_key], [])
index[d[field_key]].append(d)
return index
+
+
+def ResolveSymlink(link_from, link_to):
+ target = os.path.normpath(
+ os.path.join(os.path.dirname(link_from), link_to))
+ return target
Modified: csw/mgar/gar/v2/lib/python/struct_util_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/struct_util_test.py 2010-12-30 13:55:16 UTC (rev 12133)
+++ csw/mgar/gar/v2/lib/python/struct_util_test.py 2010-12-30 13:55:50 UTC (rev 12134)
@@ -34,5 +34,18 @@
self.assertEquals(expected, struct_util.IndexDictsBy(list_of_dicts, "a"))
+class IndexByUnitTest(unittest.TestCase):
+
+ def testRelative(self):
+ self.assertEquals(
+ "/opt/csw/libexec/foo-exec",
+ struct_util.ResolveSymlink("/opt/csw/bin/foo", "../libexec/foo-exec"))
+
+ def testAsolute(self):
+ self.assertEquals(
+ "/libexec/foo-exec",
+ struct_util.ResolveSymlink("/opt/csw/bin/foo", "/libexec/foo-exec"))
+
+
if __name__ == '__main__':
unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list