Python os.path.samefile() Examples

The following are code examples for showing how to use os.path.samefile(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: ffiplatform.py    (MIT License) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 2
Project: SwiftKitten   Author: johncsnyder   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 3
Project: aws-cfn-plex   Author: lordmuffin   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 4
Project: git_intgrtn_aws_s3   Author: droidlabour   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 5
Project: Intranet-Penetration   Author: yuxiaokui   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 6
Project: Intranet-Penetration   Author: yuxiaokui   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 7
Project: MKFQ   Author: maojingios   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 8
Project: MKFQ   Author: maojingios   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 9
Project: bawk   Author: jttwnsnd   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 10
Project: aws-lambda-python-codecommit-s3-deliver   Author: 0xlen   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 11
Project: OneClickDTU   Author: satwikkansal   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 12
Project: xxNet   Author: drzorm   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 13
Project: xxNet   Author: drzorm   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 14
Project: gardenbot   Author: GoestaO   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 15
Project: slack_scholar   Author: xLeitix   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 16
Project: ropi   Author: ThumbGen   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 17
Project: RemoteTree   Author: deNULL   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 18
Project: quickstart-git2s3   Author: aws-quickstart   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 19
Project: quickstart-git2s3   Author: aws-quickstart   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 20
Project: Docker-XX-Net   Author: kuanghy   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 21
Project: Docker-XX-Net   Author: kuanghy   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 22
Project: PyQYT   Author: collinsctk   File: ffiplatform.py    (license) View Source Project 6 votes vote down vote up
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

# ____________________________________________________________ 
Example 23
Project: PyPPL   Author: pwwang   File: utils.py    (license) View Source Project 6 votes vote down vote up
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 
Example 24
Project: PyPPL   Author: pwwang   File: utils.py    (license) View Source Project 6 votes vote down vote up
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 
Example 25
Project: PyPPL   Author: pwwang   File: utils.py    (license) View Source Project 6 votes vote down vote up
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 
Example 26
Project: PyPPL   Author: pwwang   File: utils.py    (license) View Source Project 6 votes vote down vote up
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 
Example 27
Project: noc-orchestrator   Author: DirceuSilvaLabs   File: ffiplatform.py    (MIT License) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 28
Project: SwiftKitten   Author: johncsnyder   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 29
Project: aws-cfn-plex   Author: lordmuffin   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 30
Project: hdlcc   Author: suoto   File: utils.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 31
Project: git_intgrtn_aws_s3   Author: droidlabour   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 32
Project: Intranet-Penetration   Author: yuxiaokui   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 33
Project: Intranet-Penetration   Author: yuxiaokui   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 34
Project: MKFQ   Author: maojingios   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 35
Project: MKFQ   Author: maojingios   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 36
Project: bawk   Author: jttwnsnd   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 37
Project: aws-lambda-python-codecommit-s3-deliver   Author: 0xlen   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 38
Project: OneClickDTU   Author: satwikkansal   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 39
Project: xxNet   Author: drzorm   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 40
Project: xxNet   Author: drzorm   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 41
Project: spyder-reports   Author: spyder-ide   File: test_plugin.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 42
Project: spyder-reports   Author: spyder-ide   File: test_plugin.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 43
Project: gardenbot   Author: GoestaO   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 44
Project: slack_scholar   Author: xLeitix   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 45
Project: ropi   Author: ThumbGen   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 46
Project: RemoteTree   Author: deNULL   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 47
Project: ansible-provider-docs   Author: alibaba   File: files.py    (license) View Source Project 5 votes vote down vote up
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,
        } 
Example 48
Project: quickstart-git2s3   Author: aws-quickstart   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 49
Project: quickstart-git2s3   Author: aws-quickstart   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2) 
Example 50
Project: Docker-XX-Net   Author: kuanghy   File: ffiplatform.py    (license) View Source Project 5 votes vote down vote up
def samefile(f1, f2):
        return os.path.abspath(f1) == os.path.abspath(f2)