Changeset 4021c28 in rtems-source-builder


Ignore:
Timestamp:
Oct 14, 2017, 2:18:44 PM (2 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
0dae1f6
Parents:
7c0c0ba
git-author:
Chris Johns <chrisj@…> (10/14/17 14:18:44)
git-committer:
Chris Johns <chrisj@…> (10/14/17 14:37:05)
Message:

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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • source-builder/sb/path.py

    r7c0c0ba r4021c28  
    5454    return path
    5555
     56def is_abspath(path):
     57    if path is not None:
     58        return '/' == path[0]
     59    return False
     60
    5661def shell(path):
    5762    if path is not None:
     
    6873
    6974def basename(path):
    70     return shell(os.path.basename(path))
     75    path = shell(path)
     76    return shell(os.path.basename(host(path)))
    7177
    7278def dirname(path):
     79    path = shell(path)
    7380    return shell(os.path.dirname(path))
    7481
     
    8390
    8491def abspath(path):
     92    path = shell(path)
    8593    return shell(os.path.abspath(host(path)))
    8694
    8795def splitext(path):
     96    path = shell(path)
    8897    root, ext = os.path.splitext(host(path))
    8998    return shell(root), ext
    9099
    91100def listdir(path):
     101    path = shell(path)
    92102    hp = host(path)
    93103    if not os.path.exists(hp):
     
    97107def exists(paths):
    98108    def _exists(p):
    99         if '/' not in host(p):
     109        if not is_abspath(p):
    100110            p = shell(join(os.getcwd(), host(p)))
    101111        return basename(p) in ['.'] + listdir(dirname(p))
     
    104114        results = []
    105115        for p in paths:
    106             results += [_exists(p)]
     116            results += [_exists(shell(p))]
    107117        return results
    108     return _exists(paths)
     118    return _exists(shell(paths))
    109119
    110120def isdir(path):
     121    path = shell(path)
    111122    return os.path.isdir(host(path))
    112123
    113124def isfile(path):
     125    path = shell(path)
    114126    return os.path.isfile(host(path))
    115127
    116128def isabspath(path):
     129    path = shell(path)
    117130    return path[0] == '/'
    118131
    119132def iswritable(path):
     133    path = shell(path)
    120134    return os.access(host(path), os.W_OK)
    121135
    122136def ispathwritable(path):
    123     path = host(path)
     137    path = shell(path)
    124138    while len(path) != 0:
    125139        if exists(path):
    126140            return iswritable(path)
    127         path = os.path.dirname(path)
     141        path = dirname(path)
    128142    return False
    129143
    130144def mkdir(path):
    131     path = host(path)
     145    path = shell(path)
    132146    if exists(path):
    133147        if not isdir(path):
     
    152166
    153167def chdir(path):
     168    path = shell(path)
    154169    os.chdir(host(path))
    155170
     
    188203            _remove_node(dir)
    189204
     205    path = shell(path)
    190206    hpath = host(path)
    191207
     
    195211
    196212def expand(name, paths):
     213    path = shell(path)
    197214    l = []
    198215    for p in paths:
    199         l += [join(p, name)]
     216        l += [join(shell(p), name)]
    200217    return l
    201218
    202219def copy(src, dst):
     220    src = shell(src)
     221    dst = shell(dst)
    203222    hsrc = host(src)
    204223    hdst = host(dst)
     
    218237    hdst = host(dst)
    219238
    220     if exists(hsrc):
    221         names = listdir(hsrc)
     239    if exists(src):
     240        names = listdir(src)
    222241    else:
    223242        names = []
     
    246265            if os.path.islink(srcname):
    247266                linkto = os.readlink(srcname)
    248                 if exists(dstname):
     267                if exists(shell(dstname)):
    249268                    if os.path.islink(dstname):
    250269                        dstlinkto = os.readlink(dstname)
Note: See TracChangeset for help on using the changeset viewer.