1 |
# Copyright (c) 2001 by Intevation GmbH |
# Copyright (c) 2001, 2002 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
14 |
import os.path |
import os.path |
15 |
from string import split, join |
from string import split, join |
16 |
|
|
17 |
|
from Thuban import _ |
18 |
|
|
19 |
def relative_filename_common(dir, absname, sep): |
def relative_filename_common(dir, absname, sep): |
20 |
"""Return a filename relative to dir for the absolute file name absname. |
"""Return a filename relative to dir for the absolute file name absname. |
78 |
# for that to faciliate testing |
# for that to faciliate testing |
79 |
import posixpath |
import posixpath |
80 |
if not posixpath.isabs(absname): |
if not posixpath.isabs(absname): |
81 |
return absname |
return absname |
82 |
|
|
83 |
if not posixpath.isabs(dir): |
if not posixpath.isabs(dir): |
84 |
raise TypeError("first argument must be an absolute filename") |
raise TypeError(_("first argument must be an absolute filename")) |
85 |
|
|
86 |
dir = posixpath.normpath(dir) |
dir = posixpath.normpath(dir) |
87 |
absname = posixpath.normpath(absname) |
absname = posixpath.normpath(absname) |
132 |
#print dir_drive, dir_rest |
#print dir_drive, dir_rest |
133 |
#print absname_drive, absname_rest |
#print absname_drive, absname_rest |
134 |
if not dir_drive or not absname_drive: |
if not dir_drive or not absname_drive: |
135 |
raise TypeError("Both parameters must have a drive letter") |
raise TypeError(_("Both parameters must have a drive letter")) |
136 |
|
|
137 |
if not ntpath.isabs(dir_rest): |
if not ntpath.isabs(dir_rest): |
138 |
raise TypeError("first argument must be an absolute filename") |
raise TypeError(_("first argument must be an absolute filename")) |
139 |
|
|
140 |
# handle some special cases |
# handle some special cases |
141 |
if not ntpath.isabs(absname_rest): |
if not ntpath.isabs(absname_rest): |
142 |
return absname |
return absname |
143 |
|
|
144 |
if dir_drive != absname_drive: |
if dir_drive != absname_drive: |
145 |
return absname |
return absname |
150 |
return relative_filename_common(dir_rest, absname_rest, "\\") |
return relative_filename_common(dir_rest, absname_rest, "\\") |
151 |
|
|
152 |
|
|
153 |
# bind the appriate version of relative_filename for the platform we're |
# bind the appropriate version of relative_filename for the platform |
154 |
# currently running on. |
# we're currently running on. |
155 |
if os.name == "posix": |
if os.name == "posix": |
156 |
relative_filename = relative_filename_posix |
relative_filename = relative_filename_posix |
157 |
elif os.name == "nt": |
elif os.name == "nt": |
158 |
relative_filename = relative_filename_nt |
relative_filename = relative_filename_nt |
159 |
else: |
else: |
160 |
raise RuntimeError("No implementation of relative_filename" |
raise RuntimeError(_("No implementation of relative_filename" |
161 |
" available for platform" + os.name) |
" available for platform") + os.name) |
162 |
|
|
163 |
__test__ = {"relative_filename_posix": relative_filename_posix, |
__test__ = {"relative_filename_posix": relative_filename_posix, |
164 |
"relative_filename_nt": relative_filename_nt} |
"relative_filename_nt": relative_filename_nt} |