• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python shutil._destinsrc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shutil._destinsrc函数的典型用法代码示例。如果您正苦于以下问题:Python _destinsrc函数的具体用法?Python _destinsrc怎么用?Python _destinsrc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了_destinsrc函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_destinsrc_false_positive

 def test_destinsrc_false_positive(self):
     os.mkdir(TESTFN)
     try:
         for src, dst in [('srcdir', 'src/dest'), ('srcdir', 'srcdir.new')]:
             src = os.path.join(TESTFN, src)
             dst = os.path.join(TESTFN, dst)
             self.assertFalse(shutil._destinsrc(src, dst),
                         msg='_destinsrc() wrongly concluded that '
                         'dst (%s) is in src (%s)' % (dst, src))
     finally:
         shutil.rmtree(TESTFN, ignore_errors=True)
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:11,代码来源:test_shutil.py


示例2: test_destinsrc_false_positive

 def test_destinsrc_false_positive(self):
     os.mkdir(TESTFN)
     try:
         for src, dst in [("srcdir", "src/dest"), ("srcdir", "srcdir.new")]:
             src = os.path.join(TESTFN, src)
             dst = os.path.join(TESTFN, dst)
             self.assertFalse(
                 shutil._destinsrc(src, dst),
                 msg="_destinsrc() wrongly concluded that " "dst (%s) is in src (%s)" % (dst, src),
             )
     finally:
         shutil.rmtree(TESTFN, ignore_errors=True)
开发者ID:plirof,项目名称:minibloq_v0.83,代码行数:12,代码来源:test_shutil.py


示例3: shutil_move

def shutil_move(src, dst):
    """Recursively move a file or directory to another location. This is
    similar to the Unix "mv" command. Return the file or directory's
    destination.

    If the destination is a directory or a symlink to a directory, the source
    is moved inside the directory. The destination path must not already
    exist.

    If the destination already exists but is not a directory, it may be
    overwritten depending on os.rename() semantics.

    If the destination is on our current filesystem, then rename() is used.
    Otherwise, src is copied to the destination and then removed. Symlinks are
    recreated under the new name if os.rename() fails because of cross
    filesystem renames.

    A lot more could be done here...  A look at a mv.c shows a lot of
    the issues this implementation glosses over.

    """
    real_dst = dst
    if _os.path.isdir(dst):
        if shutil._samefile(src, dst):
            # We might be on a case insensitive filesystem,
            # perform the rename anyway.
            _os.rename(src, dst)
            return

        real_dst = _os.path.join(dst, shutil._basename(src))
        if _os.path.exists(real_dst):
            raise shutil.Error("Destination path '%s' already exists" % real_dst)
    try:
        _os.rename(src, real_dst)
    except OSError:
        if _os.path.islink(src):
            linkto = _os.readlink(src)
            _os.symlink(linkto, real_dst)
            _os.unlink(src)
        elif _os.path.isdir(src):
            if shutil._destinsrc(src, dst):
                raise shutil.Error("Cannot move a directory '%s' into itself '%s'." % (src, dst))
            shutil.copytree(src, real_dst, symlinks=True)
            shutil.rmtree(src)
        else:
            shutil.copy2(src, real_dst)
            _os.unlink(src)
    return real_dst
开发者ID:joshuasb,项目名称:knossos,代码行数:48,代码来源:py2_compat.py


示例4: move

def move(src, dst):
    """Recursively move a file or directory to another location. This is
    similar to the Unix "mv" command.

    If the destination is a directory or a symlink to a directory, the source
    is moved inside the directory. The destination path must not already
    exist.

    If the destination already exists but is not a directory, it may be
    overwritten depending on os.rename() semantics.

    If the destination is on our current filesystem, then rename() is used.
    Otherwise, src is copied to the destination and then removed.
    A lot more could be done here...  A look at a mv.c shows a lot of
    the issues this implementation glosses over.

    """
    real_dst = dst
    if os.path.isdir(dst):
        if _samefile(src, dst):
            # We might be on a case insensitive filesystem,
            # perform the rename anyway.
            os.rename(src, dst)
            return

        real_dst = os.path.join(dst, _basename(src))
        if os.path.exists(real_dst):
            raise Error("Destination path '%s' already exists" % real_dst)
    try:
        os.rename(src, real_dst)
    except OSError:
        if os.path.isdir(src):
            if _destinsrc(src, dst):
                msg = "Cannot move a directory '%s' into itself '%s'." % (src,
                                                                          dst)
                raise Error(msg)
            copytree(src, real_dst, symlinks=True)
            rmtree(src)
        else:
            copy(src, real_dst)
            os.unlink(src)
开发者ID:Outernet-Project,项目名称:fsal,代码行数:41,代码来源:asyncfs.py


示例5: flatten_dir

def flatten_dir(path, parent, parententry):
	if parent == None or (args.traverse_mount_points and os.path.ismount(path)):
		return

	nameinparent = parent + "/" + parententry

	files = os.listdir(path)
	if len(files) == 0:
		if args.remove_empty_dirs:
			question = "Remove empty directory '" + path + "'"
			if util.confirm(question, default_answer = args.default_yes, path = parent, always_yes = args.always):
				util.rmdir(nameinparent)

	elif len(files) == 1:
		#move single entry of dir to parent dir, and delete dir
		if util.names_similar(files[0], parententry):
			#filename is similar to parent filename, do not concatenate
			newname = files[0]
		else:
			newname = parententry + " - " + files[0]

		#find a free new name for the file
		newname = parent + "/" + util.find_free_name(parent, newname, [parententry])

		while True:
			def question(newname):
				result = "Move '"
				result += parent + "/" + util.colored(parententry + "/" + files[0], 36)
				result += "' to '"
				result += util.colored(os.path.relpath(newname, parent), 36)
				result += "'"
				return result
			def checker(newname):
				if newname == "":
					return "Path is empty"
				elif os.path.exists(newname) and os.path.normpath(newname) != os.path.normpath(parent + "/" + parententry):
					return "Path exists"
				else:
					return True

			newname = util.confirm(question, default_answer = args.default_yes, path = parent, val = newname, valname = "move to", valchecker = checker, valcompleter = util.filename_completer(), always_yes = args.always)
			if newname == False:
				break
			newname = os.path.normpath(newname)

			#if newname is equal to the dirname, we need to rename the dir first ('mv a b', 'mv b/a a', 'rmdir b')
			if os.path.normpath(parent + '/' + parententry) == newname:
				newparententry = util.find_free_name(parent, parententry)
				util.mv(parent + '/' + parententry, parent + '/' + newparententry)
				parententry = newparententry

			#check whether the file would be moved into a subdirectory of its old location
			if shutil._destinsrc(parent + '/' + parententry, newname):
				print("Can not move file to a subdirectory of its old location")

				if args.always:
					break
				else:
					continue

			#if the parent directory of newname does not exist yet, create it
			newdirname = util.dirname(newname)
			if not os.path.exists(newdirname):
				os.makedirs(newdirname)

			#move
			util.mv(parent + '/' + parententry + '/' + files[0], newname)
			util.rmdir(parent + '/' + parententry)

			break
开发者ID:SFTtech,项目名称:dirtreeflattener,代码行数:70,代码来源:flatten.py



注:本文中的shutil._destinsrc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python shutil._make_tarball函数代码示例发布时间:2022-05-27
下一篇:
Python config.load_shub_config函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap