Esempio n. 1
0
def linkdir(src_path, dst_path):
    rel_src_path, _ = path_diff(dst_path, src_path)

    for root, dirs, files in os.walk(src_path):
        rel_path, rel_parents = path_diff(src_path, root)

        for d in dirs:
            dpath = os.path.join(dst_path, rel_path, d)
            if not os.path.exists(dpath):
                os.makedirs(dpath)
            else:
                assert os.path.isdir(
                    dpath
                ), '%d is a directory in package and a non-directory in destination' % dpath

        for f in files:
            spath = os.path.join(rel_parents, rel_src_path, rel_path, f)
            dpath = os.path.join(dst_path, rel_path, f)
            if os.path.lexists(dpath):
                if os.path.islink(dpath):
                    os.unlink(dpath)
                else:
                    log.warn('Existing file (not a symlink): %s' % dpath)
                    continue

            os.symlink(spath, dpath)
Esempio n. 2
0
def linkdir(src_path, dst_path):
    rel_src_path, _ = path_diff(dst_path, src_path)

    for root, dirs, files in os.walk(src_path):
        rel_path, rel_parents = path_diff(src_path, root)

        for d in dirs:
            dpath = os.path.join(dst_path, rel_path, d)
            if not os.path.exists(dpath):
                os.makedirs(dpath)
            else:
                assert os.path.isdir(dpath), "%d is a directory in package and a non-directory in destination" % dpath

        for f in files:
            spath = os.path.join(rel_parents, rel_src_path, rel_path, f)
            dpath = os.path.join(dst_path, rel_path, f)
            if os.path.lexists(dpath):
                if os.path.islink(dpath):
                    os.unlink(dpath)
                else:
                    log.warn("Existing file (not a symlink): %s" % dpath)
                    continue

            os.symlink(spath, dpath)
Esempio n. 3
0
def unlinkdir(src_path, dst_path):
    for root, dirs, files in os.walk(src_path, topdown=False):
        rel_path, rel_parents = path_diff(src_path, root)

        for d in dirs:
            dpath = os.path.join(dst_path, rel_path, d)
            try:
                os.rmdir(dpath)
            except OSError:
                # Directory not empty, leaving it
                pass

        for f in files:
            dpath = os.path.join(dst_path, rel_path, f)
            if not os.path.exists(dpath):
                continue

            if os.path.islink(dpath):
                if os.path.samefile(dpath, os.path.join(root, f)):
                    os.unlink(dpath)
            else:
                log.warn("%s not a symlink, not removing", dpath)
Esempio n. 4
0
def unlinkdir(src_path, dst_path):
    for root, dirs, files in os.walk(src_path, topdown=False):
        rel_path, rel_parents = path_diff(src_path, root)

        for d in dirs:
            dpath = os.path.join(dst_path, rel_path, d)
            try:
                os.rmdir(dpath)
            except OSError:
                # Directory not empty, leaving it
                pass

        for f in files:
            dpath = os.path.join(dst_path, rel_path, f)
            if not os.path.exists(dpath):
                continue

            if os.path.islink(dpath):
                if os.path.samefile(dpath, os.path.join(root, f)):
                    os.unlink(dpath)
            else:
                log.warn('%s not a symlink, not removing', dpath)