[rtems-source-builder commit] sb: Fix the interface to all path function to be shell paths.

Chris Johns chrisj at rtems.org
Sat Oct 14 14:37:22 UTC 2017


Module:    rtems-source-builder
Branch:    master
Commit:    4021c28ed0cccb0a096b290c2cd67b27a0b1cda5
Changeset: http://git.rtems.org/rtems-source-builder/commit/?id=4021c28ed0cccb0a096b290c2cd67b27a0b1cda5

Author:    Chris Johns <chrisj at rtems.org>
Date:      Sun Oct 15 01:18:44 2017 +1100

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.

---

 source-builder/sb/path.py | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/source-builder/sb/path.py b/source-builder/sb/path.py
index e3be0ce..3bf4e0c 100644
--- a/source-builder/sb/path.py
+++ b/source-builder/sb/path.py
@@ -53,6 +53,11 @@ def host(path):
                 path = u'\\'.join([u'\\\\?', path])
     return path
 
+def is_abspath(path):
+    if path is not None:
+        return '/' == path[0]
+    return False
+
 def shell(path):
     if path is not None:
         if windows:
@@ -67,9 +72,11 @@ def shell(path):
     return path
 
 def basename(path):
-    return shell(os.path.basename(path))
+    path = shell(path)
+    return shell(os.path.basename(host(path)))
 
 def dirname(path):
+    path = shell(path)
     return shell(os.path.dirname(path))
 
 def join(path, *args):
@@ -82,13 +89,16 @@ def join(path, *args):
     return shell(path)
 
 def abspath(path):
+    path = shell(path)
     return shell(os.path.abspath(host(path)))
 
 def splitext(path):
+    path = shell(path)
     root, ext = os.path.splitext(host(path))
     return shell(root), ext
 
 def listdir(path):
+    path = shell(path)
     hp = host(path)
     if not os.path.exists(hp):
         return []
@@ -96,39 +106,43 @@ def listdir(path):
 
 def exists(paths):
     def _exists(p):
-        if '/' not in host(p):
+        if not is_abspath(p):
             p = shell(join(os.getcwd(), host(p)))
         return basename(p) in ['.'] + listdir(dirname(p))
 
     if type(paths) == list:
         results = []
         for p in paths:
-            results += [_exists(p)]
+            results += [_exists(shell(p))]
         return results
-    return _exists(paths)
+    return _exists(shell(paths))
 
 def isdir(path):
+    path = shell(path)
     return os.path.isdir(host(path))
 
 def isfile(path):
+    path = shell(path)
     return os.path.isfile(host(path))
 
 def isabspath(path):
+    path = shell(path)
     return path[0] == '/'
 
 def iswritable(path):
+    path = shell(path)
     return os.access(host(path), os.W_OK)
 
 def ispathwritable(path):
-    path = host(path)
+    path = shell(path)
     while len(path) != 0:
         if exists(path):
             return iswritable(path)
-        path = os.path.dirname(path)
+        path = dirname(path)
     return False
 
 def mkdir(path):
-    path = host(path)
+    path = shell(path)
     if exists(path):
         if not isdir(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))
 
 def chdir(path):
+    path = shell(path)
     os.chdir(host(path))
 
 def removeall(path):
@@ -187,6 +202,7 @@ def removeall(path):
             _remove(dir)
             _remove_node(dir)
 
+    path = shell(path)
     hpath = host(path)
 
     if os.path.exists(hpath):
@@ -194,12 +210,15 @@ def removeall(path):
         _remove_node(path)
 
 def expand(name, paths):
+    path = shell(path)
     l = []
     for p in paths:
-        l += [join(p, name)]
+        l += [join(shell(p), name)]
     return l
 
 def copy(src, dst):
+    src = shell(src)
+    dst = shell(dst)
     hsrc = host(src)
     hdst = host(dst)
     try:
@@ -217,8 +236,8 @@ def copy_tree(src, dst):
     hsrc = host(src)
     hdst = host(dst)
 
-    if exists(hsrc):
-        names = listdir(hsrc)
+    if exists(src):
+        names = listdir(src)
     else:
         names = []
 
@@ -245,7 +264,7 @@ def copy_tree(src, dst):
         try:
             if os.path.islink(srcname):
                 linkto = os.readlink(srcname)
-                if exists(dstname):
+                if exists(shell(dstname)):
                     if os.path.islink(dstname):
                         dstlinkto = os.readlink(dstname)
                         if linkto != dstlinkto:



More information about the vc mailing list