當前位置: 首頁>>代碼示例>>Python>>正文


Python os.renames方法代碼示例

本文整理匯總了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) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:22,代碼來源:wheel.py

示例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 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:18,代碼來源:misc.py

示例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 
開發者ID:actionless,項目名稱:pikaur,代碼行數:20,代碼來源:build.py

示例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()

    ### 
開發者ID:felicitychou,項目名稱:MalAnalyzer,代碼行數:25,代碼來源:container_analyze.py

示例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 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:17,代碼來源:__init__.py

示例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() 
開發者ID:ucb-bar,項目名稱:hammer,代碼行數:30,代碼來源:hammer_tech.py


注:本文中的os.renames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。