Python os.path 模块,samefile() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用os.path.samefile()

项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:SwiftKitten    作者:johncsnyder    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:aws-cfn-plex    作者:lordmuffin    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:git_intgrtn_aws_s3    作者:droidlabour    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:bawk    作者:jttwnsnd    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:aws-lambda-python-codecommit-s3-deliver    作者:0xlen    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:OneClickDTU    作者:satwikkansal    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:slack_scholar    作者:xLeitix    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:ropi    作者:ThumbGen    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:RemoteTree    作者:deNULL    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:quickstart-git2s3    作者:aws-quickstart    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:quickstart-git2s3    作者:aws-quickstart    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:PyQYT    作者:collinsctk    | 项目源码 | 文件源码
def maybe_relative_path(path):
    if not os.path.isabs(path):
        return path      # already relative
    dir = path
    names = []
    while True:
        prevdir = dir
        dir, name = os.path.split(prevdir)
        if dir == prevdir or not dir:
            return path     # failed to make it relative
        names.append(name)
        try:
            if samefile(dir, os.curdir):
                names.reverse()
                return os.path.join(*names)
        except OSError:
            pass

# ____________________________________________________________
项目:PyPPL    作者:pwwang    | 项目源码 | 文件源码
def _samefile(f1, f2, callback = None):
    """
    Tell whether two paths pointing to the same file
    @params:
        `f1`: the first path
        `f2`: the second path
        `callback`: the callback
    @returns:
        True if yes, otherwise False
        If any of the path does not exist, return False
    """
    if not path.exists (f1) or not path.exists(f2):
        ret = False
    else:
        ret = path.samefile (f1, f2)
    if callback: # pragma: no cover
        callback(ret, f1, f2)
    return ret
项目:PyPPL    作者:pwwang    | 项目源码 | 文件源码
def samefile (f1, f2, callback = None):
    """
    Tell whether two paths pointing to the same file under locks
    @params:
        `f1`: the first path
        `f2`: the second path
        `callback`: the callback
    @returns:
        True if yes, otherwise False
        If any of the path does not exist, return False
    """
    if f1 == f2:
        if callable(callback): callback(True, f1, f2)
        return True

    f1lock = _lockfile(f1)
    f2lock = _lockfile(f2)
    with filelock.FileLock(f1lock), filelock.FileLock(f2lock):
        ret = _samefile(f1, f2, callback)
    return ret
项目:PyPPL    作者:pwwang    | 项目源码 | 文件源码
def _safeMove(src, dst, overwrite = True):
    """
    Move a file/dir
    @params:
        `src`: The source file
        `dst`: The destination
        `overwrite`: Whether overwrite the destination
    @return:
        True if succeed else False
    """
    if not path.exists(src):
        return False

    if path.exists(dst) and not path.samefile(src, dst) and overwrite:
        if path.isdir(dst) and not path.islink(dst):
            rmtree(dst)
        else:
            remove(dst)
    elif not path.exists(dst) and path.islink(dst):
        remove(dst)

    if not path.exists(dst):
        move (src, dst)
    return True
项目:PyPPL    作者:pwwang    | 项目源码 | 文件源码
def _safeCopy(src, dst, overwrite = True):
    """
    Copy a file/dir
    @params:
        `src`: The source file
        `dst`: The destination
        `overwrite`: Whether overwrite the destination
    @return:
        True if succeed else False
    """
    if not path.exists(src):
        return False

    if path.exists(dst) and not path.samefile(src, dst) and overwrite:
        if path.isdir(dst) and not path.islink(dst):
            rmtree(dst)
        else:
            remove(dst)

    if not path.exists(dst):
        if path.isdir(src):
            copytree(src, dst)
        else:
            copyfile(src, dst)
    return True
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:SwiftKitten    作者:johncsnyder    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:aws-cfn-plex    作者:lordmuffin    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:hdlcc    作者:suoto    | 项目源码 | 文件源码
def samefile(file1, file2):
        """
        Emulated version of os.path.samefile. This is needed for Python
        2.7 running on Windows (at least on Appveyor CI)
        """
        return os.stat(file1) == os.stat(file2)
项目:git_intgrtn_aws_s3    作者:droidlabour    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:bawk    作者:jttwnsnd    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:aws-lambda-python-codecommit-s3-deliver    作者:0xlen    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:OneClickDTU    作者:satwikkansal    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:spyder-reports    作者:spyder-ide    | 项目源码 | 文件源码
def test_render_tmp_dir(qtbot, setup_reports, report_file):
    """Test that rendered files are created in spyder's tempdir."""
    reports = setup_reports
    output_file = reports._render_report(report_file)

    # Test that outfile is in spyder tmp dir
    assert osp.samefile(osp.commonprefix([output_file, TEMPDIR]), TEMPDIR)
项目:spyder-reports    作者:spyder-ide    | 项目源码 | 文件源码
def test_render_same_file(qtbot, setup_reports, report_file):
    """Test that re-rendered files are created in the same tempdir."""
    reports = setup_reports

    output_file1 = reports._render_report(report_file)
    output_file2 = reports._render_report(report_file)

    assert osp.exists(output_file2)
    # Assert that file has been re-rendered in the same path
    assert osp.samefile(output_file1, output_file2)
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:slack_scholar    作者:xLeitix    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:ropi    作者:ThumbGen    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:RemoteTree    作者:deNULL    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:ansible-provider-docs    作者:alibaba    | 项目源码 | 文件源码
def tests(self):
        return {
            # file testing
            'is_dir': isdir,
            'is_file': isfile,
            'is_link': islink,
            'exists': exists,
            'link_exists': lexists,

            # path testing
            'is_abs': isabs,
            'is_same_file': samefile,
            'is_mount': ismount,
        }
项目:quickstart-git2s3    作者:aws-quickstart    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:quickstart-git2s3    作者:aws-quickstart    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)