本文整理汇总了Python中os.renames方法的典型用法代码示例。如果您正苦于以下问题:Python os.renames方法的具体用法?Python os.renames怎么用?Python os.renames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.renames方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unpack
# 需要导入模块: import os [as 别名]
# 或者: from os import renames [as 别名]
def unpack(src_dir, dst_dir):
'''Move everything under `src_dir` to `dst_dir`, and delete the former.'''
for dirpath, dirnames, filenames in os.walk(src_dir):
subdir = os.path.relpath(dirpath, src_dir)
for f in filenames:
src = os.path.join(dirpath, f)
dst = os.path.join(dst_dir, subdir, f)
os.renames(src, dst)
for n, d in reversed(list(enumerate(dirnames))):
src = os.path.join(dirpath, d)
dst = os.path.join(dst_dir, subdir, d)
if not os.path.exists(dst):
# Directory does not exist in destination,
# rename it and prune it from os.walk list.
os.renames(src, dst)
del dirnames[n]
# Cleanup.
for dirpath, dirnames, filenames in os.walk(src_dir, topdown=True):
assert not filenames
os.rmdir(dirpath)
示例2: renames
# 需要导入模块: import os [as 别名]
# 或者: from os import renames [as 别名]
def renames(old, new):
# type: (str, str) -> None
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
示例3: prepare_build_destination
# 需要导入模块: import os [as 别名]
# 或者: from os import renames [as 别名]
def prepare_build_destination(self, flush=False) -> None:
if flush:
remove_dir(self.build_dir)
self._build_files_copied = False
if self._build_files_copied:
return
if os.path.exists(self.build_dir) and not self.keep_build_dir:
remove_dir(self.build_dir)
copy_aur_repo(self.repo_path, self.build_dir)
pkgbuild_name = os.path.basename(self.pkgbuild_path)
if pkgbuild_name != 'PKGBUILD':
default_pkgbuild_path = os.path.join(self.build_dir, 'PKGBUILD')
custom_pkgbuild_path = os.path.join(self.build_dir, pkgbuild_name)
if os.path.exists(default_pkgbuild_path):
os.unlink(default_pkgbuild_path)
os.renames(custom_pkgbuild_path, default_pkgbuild_path)
self._build_files_copied = True
示例4: start_wine
# 需要导入模块: import os [as 别名]
# 或者: from os import renames [as 别名]
def start_wine(self):
try:
filepath, ext = os.path.splitext(self.mal_path)
# add .exe ext
self.mal_path = filepath if ext else '%s.exe' % filepath
os.renames(filepath, self.mal_path)
wine_path = os.path.join(self.result_path, 'wine.txt')
with open(wine_path, 'w') as f:
child = subprocess.Popen(["wine", self.mal_path], stdout = f, stderr = f, env = {'WINEDEBUG': '+relay'})
self.logger.debug("WINEDEBUG:+relay wine %s" % (self.mal_path,))
if child.poll() is None:
self.logger.info("Start wine(pid=%s) successfully." % (child.pid))
self.progrunner = 'wine'
self.wine = child
else:
self.logger.error("Start wine failed.")
sys.exit()
except Exception, e:
self.logger.exception('%s: %s' % (Exception, e))
sys.exit()
###
示例5: renames
# 需要导入模块: import os [as 别名]
# 或者: from os import renames [as 别名]
def renames(old, new):
"""Like os.renames(), but handles renaming across devices."""
# Implementation borrowed from os.renames().
head, tail = os.path.split(new)
if head and tail and not os.path.exists(head):
os.makedirs(head)
shutil.move(old, new)
head, tail = os.path.split(old)
if head and tail:
try:
os.removedirs(head)
except OSError:
pass
示例6: extract_tarballs
# 需要导入模块: import os [as 别名]
# 或者: from os import renames [as 别名]
def extract_tarballs(self) -> None:
"""Extract tarballs to the given cache_dir, or verify that they've been extracted."""
for tarball in self.config.tarballs:
target_path = os.path.join(self.extracted_tarballs_dir, tarball.path)
tarball_path = os.path.join(self.get_setting(tarball.base_var), tarball.path)
if not os.path.isfile(tarball_path):
raise ValueError("Path {0} does not point to a valid tarball!".format(tarball_path))
if os.path.isdir(target_path):
# If the folder already seems to exist, continue
continue
else:
# Else, extract the tarballs.
os.makedirs(target_path, mode=0o700, exist_ok=True) # Make sure it exists or tar will not be happy.
self.logger.debug("Extracting/verifying tarball %s" % (tarball_path))
tarfile.open(tarball_path).extractall(target_path)
for root, dirs, files in os.walk(target_path):
for d in dirs:
os.chmod(os.path.join(root, d), mode=0o700)
for f in files:
file = os.path.join(root, f)
os.chmod(file, mode=0o700)
# extract tarball recursively
if tarfile.is_tarfile(file):
self.logger.debug("Extracting/verifying tarball %s" % (file))
tarfile.open(file).extractall(path=os.path.join(root, f + "_dir"))
os.remove(file)
os.renames(os.path.join(root, f + "_dir"), file)
self.post_install_script()