Changeset e1346e2 in rtems-source-builder


Ignore:
Timestamp:
Jan 18, 2018, 3:35:31 AM (21 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.11
Children:
2ac145a
Parents:
f7c729e
Message:

sb: Back port the path module from master.

Update #3274

File:
1 edited

Legend:

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

    rf7c729e re1346e2  
    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
     95def relpath(path, start = None):
     96    path = shell(path)
     97    if start is None:
     98        path = os.path.relpath(host(path))
     99    else:
     100        path = os.path.relpath(host(path), start)
     101    return shell(path)
     102
    87103def splitext(path):
     104    path = shell(path)
    88105    root, ext = os.path.splitext(host(path))
    89106    return shell(root), ext
    90107
    91108def listdir(path):
     109    path = shell(path)
    92110    hp = host(path)
    93111    if not os.path.exists(hp):
     
    97115def exists(paths):
    98116    def _exists(p):
    99         return os.path.basename(p) in listdir(dirname(p))
     117        if not is_abspath(p):
     118            p = shell(join(os.getcwd(), host(p)))
     119        return basename(p) in ['.'] + listdir(dirname(p))
    100120
    101121    if type(paths) == list:
    102122        results = []
    103123        for p in paths:
    104             results += [_exists(p)]
     124            results += [_exists(shell(p))]
    105125        return results
    106     return _exists(paths)
     126    return _exists(shell(paths))
    107127
    108128def isdir(path):
     129    path = shell(path)
    109130    return os.path.isdir(host(path))
    110131
    111132def isfile(path):
     133    path = shell(path)
    112134    return os.path.isfile(host(path))
    113135
    114136def isabspath(path):
     137    path = shell(path)
    115138    return path[0] == '/'
    116139
    117140def iswritable(path):
     141    path = shell(path)
    118142    return os.access(host(path), os.W_OK)
    119143
    120144def ispathwritable(path):
    121     path = host(path)
     145    path = shell(path)
    122146    while len(path) != 0:
    123147        if exists(path):
    124148            return iswritable(path)
    125         path = os.path.dirname(path)
     149        path = dirname(path)
    126150    return False
    127151
    128152def mkdir(path):
    129     path = host(path)
     153    path = shell(path)
    130154    if exists(path):
    131155        if not isdir(path):
     
    150174
    151175def chdir(path):
     176    path = shell(path)
    152177    os.chdir(host(path))
    153178
     
    186211            _remove_node(dir)
    187212
     213    path = shell(path)
    188214    hpath = host(path)
    189215
     
    193219
    194220def expand(name, paths):
     221    path = shell(path)
    195222    l = []
    196223    for p in paths:
    197         l += [join(p, name)]
     224        l += [join(shell(p), name)]
    198225    return l
    199226
    200227def copy(src, dst):
     228    src = shell(src)
     229    dst = shell(dst)
    201230    hsrc = host(src)
    202231    hdst = host(dst)
     
    208237                pass
    209238        else:
    210             raise error.general('copying tree: %s -> %s: %s' % (hsrc, hdst, str(why)))
     239            raise error.general('copying tree (1): %s -> %s: %s' % (hsrc, hdst, str(why)))
    211240
    212241def copy_tree(src, dst):
     
    216245    hdst = host(dst)
    217246
    218     if exists(hsrc):
    219         names = listdir(hsrc)
     247    if exists(src):
     248        names = listdir(src)
    220249    else:
    221250        names = []
     
    244273            if os.path.islink(srcname):
    245274                linkto = os.readlink(srcname)
    246                 if exists(dstname):
     275                if exists(shell(dstname)):
    247276                    if os.path.islink(dstname):
    248277                        dstlinkto = os.readlink(dstname)
     
    263292                shutil.copystat(host(srcname), host(dstname))
    264293        except shutil.Error as err:
    265             raise error.general('copying tree: %s -> %s: %s' % \
     294            raise error.general('copying tree (2): %s -> %s: %s' % \
    266295                                (hsrc, hdst, str(err)))
    267296        except EnvironmentError as why:
    268             raise error.general('copying tree: %s -> %s: %s' % \
     297            raise error.general('copying tree (3): %s -> %s: %s' % \
    269298                                (srcname, dstname, str(why)))
    270299    try:
     
    275304                pass
    276305        else:
    277             raise error.general('copying tree: %s -> %s: %s' % (hsrc, hdst, str(why)))
     306            raise error.general('copying tree (4): %s -> %s: %s' % (hsrc, hdst, str(why)))
    278307
    279308if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.