mirror of
https://git.rtems.org/rtems-source-builder
synced 2024-10-09 07:15:10 +08:00
sb: Fix the interface to all path function to be shell paths.
- Add an is_abspath call. - Convert the path or paths to shell paths on entry to all path calls. This is safe to do for a path that is already a shell path. - Fix exists to use shell paths.
This commit is contained in:
parent
7c0c0ba16c
commit
4021c28ed0
@ -53,6 +53,11 @@ def host(path):
|
|||||||
path = u'\\'.join([u'\\\\?', path])
|
path = u'\\'.join([u'\\\\?', path])
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
def is_abspath(path):
|
||||||
|
if path is not None:
|
||||||
|
return '/' == path[0]
|
||||||
|
return False
|
||||||
|
|
||||||
def shell(path):
|
def shell(path):
|
||||||
if path is not None:
|
if path is not None:
|
||||||
if windows:
|
if windows:
|
||||||
@ -67,9 +72,11 @@ def shell(path):
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
def basename(path):
|
def basename(path):
|
||||||
return shell(os.path.basename(path))
|
path = shell(path)
|
||||||
|
return shell(os.path.basename(host(path)))
|
||||||
|
|
||||||
def dirname(path):
|
def dirname(path):
|
||||||
|
path = shell(path)
|
||||||
return shell(os.path.dirname(path))
|
return shell(os.path.dirname(path))
|
||||||
|
|
||||||
def join(path, *args):
|
def join(path, *args):
|
||||||
@ -82,13 +89,16 @@ def join(path, *args):
|
|||||||
return shell(path)
|
return shell(path)
|
||||||
|
|
||||||
def abspath(path):
|
def abspath(path):
|
||||||
|
path = shell(path)
|
||||||
return shell(os.path.abspath(host(path)))
|
return shell(os.path.abspath(host(path)))
|
||||||
|
|
||||||
def splitext(path):
|
def splitext(path):
|
||||||
|
path = shell(path)
|
||||||
root, ext = os.path.splitext(host(path))
|
root, ext = os.path.splitext(host(path))
|
||||||
return shell(root), ext
|
return shell(root), ext
|
||||||
|
|
||||||
def listdir(path):
|
def listdir(path):
|
||||||
|
path = shell(path)
|
||||||
hp = host(path)
|
hp = host(path)
|
||||||
if not os.path.exists(hp):
|
if not os.path.exists(hp):
|
||||||
return []
|
return []
|
||||||
@ -96,39 +106,43 @@ def listdir(path):
|
|||||||
|
|
||||||
def exists(paths):
|
def exists(paths):
|
||||||
def _exists(p):
|
def _exists(p):
|
||||||
if '/' not in host(p):
|
if not is_abspath(p):
|
||||||
p = shell(join(os.getcwd(), host(p)))
|
p = shell(join(os.getcwd(), host(p)))
|
||||||
return basename(p) in ['.'] + listdir(dirname(p))
|
return basename(p) in ['.'] + listdir(dirname(p))
|
||||||
|
|
||||||
if type(paths) == list:
|
if type(paths) == list:
|
||||||
results = []
|
results = []
|
||||||
for p in paths:
|
for p in paths:
|
||||||
results += [_exists(p)]
|
results += [_exists(shell(p))]
|
||||||
return results
|
return results
|
||||||
return _exists(paths)
|
return _exists(shell(paths))
|
||||||
|
|
||||||
def isdir(path):
|
def isdir(path):
|
||||||
|
path = shell(path)
|
||||||
return os.path.isdir(host(path))
|
return os.path.isdir(host(path))
|
||||||
|
|
||||||
def isfile(path):
|
def isfile(path):
|
||||||
|
path = shell(path)
|
||||||
return os.path.isfile(host(path))
|
return os.path.isfile(host(path))
|
||||||
|
|
||||||
def isabspath(path):
|
def isabspath(path):
|
||||||
|
path = shell(path)
|
||||||
return path[0] == '/'
|
return path[0] == '/'
|
||||||
|
|
||||||
def iswritable(path):
|
def iswritable(path):
|
||||||
|
path = shell(path)
|
||||||
return os.access(host(path), os.W_OK)
|
return os.access(host(path), os.W_OK)
|
||||||
|
|
||||||
def ispathwritable(path):
|
def ispathwritable(path):
|
||||||
path = host(path)
|
path = shell(path)
|
||||||
while len(path) != 0:
|
while len(path) != 0:
|
||||||
if exists(path):
|
if exists(path):
|
||||||
return iswritable(path)
|
return iswritable(path)
|
||||||
path = os.path.dirname(path)
|
path = dirname(path)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def mkdir(path):
|
def mkdir(path):
|
||||||
path = host(path)
|
path = shell(path)
|
||||||
if exists(path):
|
if exists(path):
|
||||||
if not isdir(path):
|
if not isdir(path):
|
||||||
raise error.general('path exists and is not a directory: %s' % (path))
|
raise error.general('path exists and is not a directory: %s' % (path))
|
||||||
@ -151,6 +165,7 @@ def mkdir(path):
|
|||||||
raise error.general('cannot make directory: %s' % (path))
|
raise error.general('cannot make directory: %s' % (path))
|
||||||
|
|
||||||
def chdir(path):
|
def chdir(path):
|
||||||
|
path = shell(path)
|
||||||
os.chdir(host(path))
|
os.chdir(host(path))
|
||||||
|
|
||||||
def removeall(path):
|
def removeall(path):
|
||||||
@ -187,6 +202,7 @@ def removeall(path):
|
|||||||
_remove(dir)
|
_remove(dir)
|
||||||
_remove_node(dir)
|
_remove_node(dir)
|
||||||
|
|
||||||
|
path = shell(path)
|
||||||
hpath = host(path)
|
hpath = host(path)
|
||||||
|
|
||||||
if os.path.exists(hpath):
|
if os.path.exists(hpath):
|
||||||
@ -194,12 +210,15 @@ def removeall(path):
|
|||||||
_remove_node(path)
|
_remove_node(path)
|
||||||
|
|
||||||
def expand(name, paths):
|
def expand(name, paths):
|
||||||
|
path = shell(path)
|
||||||
l = []
|
l = []
|
||||||
for p in paths:
|
for p in paths:
|
||||||
l += [join(p, name)]
|
l += [join(shell(p), name)]
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def copy(src, dst):
|
def copy(src, dst):
|
||||||
|
src = shell(src)
|
||||||
|
dst = shell(dst)
|
||||||
hsrc = host(src)
|
hsrc = host(src)
|
||||||
hdst = host(dst)
|
hdst = host(dst)
|
||||||
try:
|
try:
|
||||||
@ -217,8 +236,8 @@ def copy_tree(src, dst):
|
|||||||
hsrc = host(src)
|
hsrc = host(src)
|
||||||
hdst = host(dst)
|
hdst = host(dst)
|
||||||
|
|
||||||
if exists(hsrc):
|
if exists(src):
|
||||||
names = listdir(hsrc)
|
names = listdir(src)
|
||||||
else:
|
else:
|
||||||
names = []
|
names = []
|
||||||
|
|
||||||
@ -245,7 +264,7 @@ def copy_tree(src, dst):
|
|||||||
try:
|
try:
|
||||||
if os.path.islink(srcname):
|
if os.path.islink(srcname):
|
||||||
linkto = os.readlink(srcname)
|
linkto = os.readlink(srcname)
|
||||||
if exists(dstname):
|
if exists(shell(dstname)):
|
||||||
if os.path.islink(dstname):
|
if os.path.islink(dstname):
|
||||||
dstlinkto = os.readlink(dstname)
|
dstlinkto = os.readlink(dstname)
|
||||||
if linkto != dstlinkto:
|
if linkto != dstlinkto:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user