def toRelativePath(path, prefix):
from tounixpath import toUnixPath
from todospath import toDosPath
path = toUnixPath(path)
prefix = toUnixPath(prefix)
if not prefix.endswith('/'): prefix = prefix + '/'
path = path.replace(prefix, '')
return toDosPath(path)
#-- unit tests
def test_torelativepath():
ut.utassert(toRelativePath("c:/bin/bob", "c:/bin"), 'bob');
ut.utassert(toRelativePath("c:/bin/bob", "c:/bin/"), 'bob');
ut.utassert(toRelativePath("c:/bin/bob", "c:\\bin\\"), 'bob');
ut.utassert(toRelativePath("c:/bin/bob/", "c:/bin"), 'bob\\');
ut.utassert(toRelativePath("c:/bin/bob/", "c:/bin/"), 'bob\\');
ut.utassert(toRelativePath("c:/bin/bob/", "c:\\bin\\"), 'bob\\');
ut.utassert(toRelativePath("c:/bin/billy/bob", "c:\\bin\\"), 'billy\\bob');
ut.utassert(toRelativePath("c:/bin/billy/bob/", "c:\\bin\\"), 'billy\\bob\\');
ut.utassert(toRelativePath("c:/bin/billy/bob", "c:\\"), 'bin\\billy\\bob');
ut.utassert(toRelativePath("c:/bin/billy/bob/", "c:/"), 'bin\\billy\\bob\\');
ut.utassert(toRelativePath("c:\\bin/billy/bob", "c:\\"), 'bin\\billy\\bob');
ut.utassert(toRelativePath("c:\\bin/billy/bob/", "c:/"), 'bin\\billy\\bob\\');
|