Update of /cvsroot/pythoncard/PythonCard
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12833
Modified Files:
util.py
Log Message:
added relativePath function, used by resourceEditor
added File... button to Property Editor
Index: util.py
===================================================================
RCS file: /cvsroot/pythoncard/PythonCard/util.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** util.py 22 Aug 2004 18:44:53 -0000 1.30
--- util.py 24 Aug 2004 19:01:16 -0000 1.31
***************
*** 362,363 ****
--- 362,391 ----
color = s
return color
+
+ # compute relative path
+ # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/208993
+
+ def pathsplit(p, rest=[]):
+ (h,t) = os.path.split(p)
+ if len(h) < 1: return [t]+rest
+ if len(t) < 1: return [h]+rest
+ return pathsplit(h,[t]+rest)
+
+ def commonpath(l1, l2, common=[]):
+ if len(l1) < 1: return (common, l1, l2)
+ if len(l2) < 1: return (common, l1, l2)
+ if l1[0] != l2[0]: return (common, l1, l2)
+ return commonpath(l1[1:], l2[1:], common+[l1[0]])
+
+ # KEA 2004-08-24
+ # I made a few changes below to get rid of redundant leading ..
+ def relativePath(p1, p2):
+ (common,l1,l2) = commonpath(pathsplit(p1), pathsplit(p2))
+ p = []
+ if len(l1) > 0:
+ p = ['../' * len(l1)]
+ p = p + l2
+ path = os.path.join(*p)
+ if path.startswith('../'):
+ path = path[3:]
+ return path
|