本文整理汇总了Python中posixpath.samefile函数的典型用法代码示例。如果您正苦于以下问题:Python samefile函数的具体用法?Python samefile怎么用?Python samefile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了samefile函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_samefile
def test_samefile(self):
f = open(test_support.TESTFN + "1", "wb")
try:
f.write("foo")
f.close()
self.assertIs(posixpath.samefile(test_support.TESTFN + "1", test_support.TESTFN + "1"), True)
# If we don't have links, assume that os.stat doesn't return resonable
# inode information and thus, that samefile() doesn't work
if hasattr(os, "symlink"):
os.symlink(test_support.TESTFN + "1", test_support.TESTFN + "2")
self.assertIs(posixpath.samefile(test_support.TESTFN + "1", test_support.TESTFN + "2"), True)
os.remove(test_support.TESTFN + "2")
f = open(test_support.TESTFN + "2", "wb")
f.write("bar")
f.close()
self.assertIs(posixpath.samefile(test_support.TESTFN + "1", test_support.TESTFN + "2"), False)
finally:
if not f.close():
f.close()
try:
os.remove(test_support.TESTFN + "1")
except os.error:
pass
try:
os.remove(test_support.TESTFN + "2")
except os.error:
pass
self.assertRaises(TypeError, posixpath.samefile)
开发者ID:krattai,项目名称:xbmc-antiquated,代码行数:29,代码来源:test_posixpath.py
示例2: test_samefile_on_links
def test_samefile_on_links(self):
test_fn1 = support.TESTFN + "1"
test_fn2 = support.TESTFN + "2"
self._create_file(test_fn1)
os.symlink(test_fn1, test_fn2)
self.assertTrue(posixpath.samefile(test_fn1, test_fn2))
os.remove(test_fn2)
self._create_file(test_fn2)
self.assertFalse(posixpath.samefile(test_fn1, test_fn2))
开发者ID:pierreorz,项目名称:web_ctp,代码行数:11,代码来源:test_posixpath.py
示例3: unload_dtags
def unload_dtags(rootpath, dirpath):
"""Remove symlinks using a directory's dtags."""
tags = dtags.list_tags(dirpath)
dirpath = pathlib.readlink(dirpath)
for tagname in tags:
tagpath = tagnames.tag2path(rootpath, tagname)
if posixpath.samefile(dirpath, tagpath):
os.unlink(tagpath)
开发者ID:darkfeline,项目名称:dantalian,代码行数:8,代码来源:base.py
示例4: untag
def untag(rootpath, path, directory):
"""Untag file from a directory.
Args:
rootpath: Rootpath to resolve tagnames.
path: Path of file or directory to tag.
directory: Directory path.
"""
target = path
to_unlink = []
for filepath in pathlib.listdirpaths(directory):
if posixpath.samefile(target, filepath):
to_unlink.append(filepath)
for filepath in to_unlink:
base.unlink(rootpath, filepath)
开发者ID:darkfeline,项目名称:dantalian,代码行数:15,代码来源:tagging.py
示例5: list_links
def list_links(top, path):
"""List all links to the target file.
Args:
top: Path to top of directory tree to search.
path: Path of file.
Returns:
Generator yielding paths.
"""
target = path
for (dirpath, dirnames, filenames) in os.walk(top):
for name in chain(dirnames, filenames):
filepath = posixpath.join(dirpath, name)
if posixpath.samefile(target, filepath):
yield filepath
开发者ID:darkfeline,项目名称:dantalian,代码行数:16,代码来源:base.py
示例6: copyfile
def copyfile(originalfile, newfile, copy=False, create_new=False,
hashmethod=None, use_hardlink=False,
copy_related_files=True):
"""Copy or link ``originalfile`` to ``newfile``.
If ``use_hardlink`` is True, and the file can be hard-linked, then a
link is created, instead of copying the file.
If a hard link is not created and ``copy`` is False, then a symbolic
link is created.
Parameters
----------
originalfile : str
full path to original file
newfile : str
full path to new file
copy : Bool
specifies whether to copy or symlink files
(default=False) but only for POSIX systems
use_hardlink : Bool
specifies whether to hard-link files, when able
(Default=False), taking precedence over copy
copy_related_files : Bool
specifies whether to also operate on related files, as defined in
``related_filetype_sets``
Returns
-------
None
"""
newhash = None
orighash = None
fmlogger.debug(newfile)
if create_new:
while os.path.exists(newfile):
base, fname, ext = split_filename(newfile)
s = re.search('_c[0-9]{4,4}$', fname)
i = 0
if s:
i = int(s.group()[2:]) + 1
fname = fname[:-6] + "_c%04d" % i
else:
fname += "_c%04d" % i
newfile = base + os.sep + fname + ext
if hashmethod is None:
hashmethod = config.get('execution', 'hash_method').lower()
# Don't try creating symlinks on CIFS
if copy is False and on_cifs(newfile):
copy = True
# Existing file
# -------------
# Options:
# symlink
# to regular file originalfile (keep if symlinking)
# to same dest as symlink originalfile (keep if symlinking)
# to other file (unlink)
# regular file
# hard link to originalfile (keep)
# copy of file (same hash) (keep)
# different file (diff hash) (unlink)
keep = False
if os.path.lexists(newfile):
if os.path.islink(newfile):
if all((os.readlink(newfile) == os.path.realpath(originalfile),
not use_hardlink, not copy)):
keep = True
elif posixpath.samefile(newfile, originalfile):
keep = True
else:
if hashmethod == 'timestamp':
hashfn = hash_timestamp
elif hashmethod == 'content':
hashfn = hash_infile
newhash = hashfn(newfile)
fmlogger.debug("File: %s already exists,%s, copy:%d" %
(newfile, newhash, copy))
orighash = hashfn(originalfile)
keep = newhash == orighash
if keep:
fmlogger.debug("File: %s already exists, not overwriting, copy:%d"
% (newfile, copy))
else:
os.unlink(newfile)
# New file
# --------
# use_hardlink & can_hardlink => hardlink
# ~hardlink & ~copy & can_symlink => symlink
# ~hardlink & ~symlink => copy
if not keep and use_hardlink:
try:
fmlogger.debug("Linking File: %s->%s" % (newfile, originalfile))
# Use realpath to avoid hardlinking symlinks
os.link(os.path.realpath(originalfile), newfile)
#.........这里部分代码省略.........
开发者ID:NifTK,项目名称:nipype,代码行数:101,代码来源:filemanip.py
示例7: test_samefile
def test_samefile(self):
test_fn = support.TESTFN + "1"
self._create_file(test_fn)
self.assertTrue(posixpath.samefile(test_fn, test_fn))
self.assertRaises(TypeError, posixpath.samefile)
开发者ID:pierreorz,项目名称:web_ctp,代码行数:5,代码来源:test_posixpath.py
注:本文中的posixpath.samefile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论