当前位置: 首页>>代码示例>>Python>>正文


Python shutil.rmtree方法代码示例

本文整理汇总了Python中shutil.rmtree方法的典型用法代码示例。如果您正苦于以下问题:Python shutil.rmtree方法的具体用法?Python shutil.rmtree怎么用?Python shutil.rmtree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shutil的用法示例。


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

示例1: __call__

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def __call__(self, args, env):
        samples_dir = env.get('samples-dir')
        for label in ("cat", "dog"):
            dest = os.path.join(samples_dir, label)
            if os.path.exists(dest):
                raise VergeMLError("Directory {} already exists in samples dir: {}".format(label, dest))
        print("Downloading cats and dogs to {}.".format(samples_dir))
        src_dir = self.download_files([(_URL, "catsdogs.zip")], env)
        path = os.path.join(src_dir, "catsdogs.zip")

        print("Extracting data.")
        zipf = zipfile.ZipFile(path, 'r')
        zipf.extractall(src_dir)
        zipf.close()

        for file, dest in (("PetImages/Dog", "dog"), ("PetImages/Cat", "cat")):
            shutil.copytree(os.path.join(src_dir, file), os.path.join(samples_dir, dest))

        shutil.rmtree(src_dir)

        # WTF?
        os.unlink(os.path.join(samples_dir, "cat", "666.jpg"))
        os.unlink(os.path.join(samples_dir, "dog", "11702.jpg"))

        print("Finished downloading cats and dogs.") 
开发者ID:mme,项目名称:vergeml,代码行数:27,代码来源:cats_and_dogs.py

示例2: _download_straight_dope_notebooks

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def _download_straight_dope_notebooks():
    """Downloads the Straight Dope Notebooks.

    Returns:
        True if it succeeds in downloading the notebooks without error.
    """
    logging.info('Cleaning and setting up notebooks directory "{}"'.format(NOTEBOOKS_DIR))
    shutil.rmtree(NOTEBOOKS_DIR, ignore_errors=True)

    cmd = [GIT_PATH,
           'clone',
           GIT_REPO,
           NOTEBOOKS_DIR]

    proc, msg = _run_command(cmd)

    if proc.returncode != 0:
        err_msg = 'Error downloading Straight Dope notebooks.\n'
        err_msg += msg
        logging.error(err_msg)
        return False
    return True 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:24,代码来源:straight_dope_test_utils.py

示例3: test_multiprocessing_download_successful

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def test_multiprocessing_download_successful():
    """ test download with multiprocessing """
    tmp = tempfile.mkdtemp()
    tmpfile = os.path.join(tmp, 'README.md')
    process_list = []
    # test it with 10 processes
    for i in range(10):
        process_list.append(mp.Process(
            target=_download_successful, args=(tmpfile,)))
        process_list[i].start()
    for i in range(10):
        process_list[i].join()
    assert os.path.getsize(tmpfile) > 100, os.path.getsize(tmpfile)
    # check only one file we want left
    pattern = os.path.join(tmp, 'README.md*')
    assert len(glob.glob(pattern)) == 1, glob.glob(pattern)
    # delete temp dir
    shutil.rmtree(tmp) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:20,代码来源:test_gluon_utils.py

示例4: __call__

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def __call__(self, args, env):
        samples_dir = env.get('samples-dir')

        print("Downloading unique objects to {}.".format(samples_dir))

        src_dir = self.download_files([_URL], env=env, dir=env.get('cache-dir'))
        path = os.path.join(src_dir, "ObjectsAll.zip")

        zipf = zipfile.ZipFile(path, 'r')
        zipf.extractall(src_dir)
        zipf.close()

        for file in os.listdir(os.path.join(src_dir, "OBJECTSALL")):
            shutil.copy(os.path.join(src_dir, "OBJECTSALL", file), samples_dir)

        shutil.rmtree(src_dir)

        print("Finished downloading unique objects.") 
开发者ID:mme,项目名称:vergeml,代码行数:20,代码来源:unique_objects.py

示例5: do_iteration

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def do_iteration(self, mutation_fn, aggression):
        """
        This method is called with an output mutation filename and a
        real aggression (see :ref:`aggression`) indicating the amount
        of aggression the fuzzing algorithm should use.  *mutation_fn*
        is unique for every invokation of :meth:`do_iteration`.

        It is an error for this method not to write the mutated
        template to *mutation_fn* before returning a result.  If a
        result is not found, the mutation filename may be written to
        if needed, but it is not required.

        If a notable result is found, it should be returned as a
        :class:`FuzzResult` instance.  This will be stored and reported
        to the ALF central server at the next check-in interval.  A
        return of None indicates a result was not found.

        The filenames of any temporary files or folders created during
        execution can be safely removed using :func:`alf.delete`.  This
        is safer than using :func:`os.remove` or :func:`shutil.rmtree`
        directly.  *mutation_fn* does not need to be deleted, it is
        cleaned up automatically.
        """
        raise NotImplementedError() 
开发者ID:blackberry,项目名称:ALF,代码行数:26,代码来源:__init__.py

示例6: _delete_directory_contents

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def _delete_directory_contents(self, dirpath, filter_func):
        """Delete all files in a directory.

        :param dirpath: path to directory to clear
        :type dirpath: ``unicode`` or ``str``
        :param filter_func function to determine whether a file shall be
            deleted or not.
        :type filter_func ``callable``

        """
        if os.path.exists(dirpath):
            for filename in os.listdir(dirpath):
                if not filter_func(filename):
                    continue
                path = os.path.join(dirpath, filename)
                if os.path.isdir(path):
                    shutil.rmtree(path)
                else:
                    os.unlink(path)
                self.logger.debug('deleted : %r', path) 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:22,代码来源:workflow.py

示例7: test_extraction

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def test_extraction():
    import shutil

    src = 'c:/Users/shinj/Downloads/clonezilla-live-2.5.2-31-amd64.iso'
    tmp_dir = 'c:/Users/shinj/Documents/tmp'
    for subdir, pattern in [
            ('single_string', 'EFI/'),
            ('single_list', ['EFI/']),
            ('multi', ['EFI/', 'syslinux/']),
            ('all', None) ]:
        dest_dir = os.path.join(tmp_dir, subdir)
        if os.path.exists(dest_dir):
            shutil.rmtree(dest_dir)
        os.mkdir(dest_dir)
        args = [src, dest_dir]
        if pattern is not None:
            args.append(pattern)
        print ('Calling extract_iso(%s)' % args)
        extract_iso(*args) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:21,代码来源:_7zip.py

示例8: save_dictionary

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def save_dictionary(config):
    """
    :param config: config
    :return:
    """
    if config.save_dict is True:
        if os.path.exists(config.dict_directory):
            shutil.rmtree(config.dict_directory)
        if not os.path.isdir(config.dict_directory):
            os.makedirs(config.dict_directory)

        config.word_dict_path = "/".join([config.dict_directory, config.word_dict])
        config.label_dict_path = "/".join([config.dict_directory, config.label_dict])
        print("word_dict_path : {}".format(config.word_dict_path))
        print("label_dict_path : {}".format(config.label_dict_path))
        save_dict2file(config.create_alphabet.word_alphabet.words2id, config.word_dict_path)
        save_dict2file(config.create_alphabet.label_alphabet.words2id, config.label_dict_path)
        # copy to mulu
        print("copy dictionary to {}".format(config.save_dir))
        shutil.copytree(config.dict_directory, "/".join([config.save_dir, config.dict_directory]))


# load data / create alphabet / create iterator 
开发者ID:bamtercelboo,项目名称:pytorch_NER_BiLSTM_CNN_CRF,代码行数:25,代码来源:mainHelp.py

示例9: test_creation

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def test_creation(self):
        if os.path.exists(self.base_dir):
            shutil.rmtree(self.checkpoints_dir, ignore_errors=True)

        try:
            FileStructManager(base_dir=self.base_dir, is_continue=False)
        except FileStructManager.FSMException as err:
            self.fail("Raise error when base directory exists: [{}]".format(err))

        self.assertFalse(os.path.exists(self.base_dir))

        try:
            FileStructManager(base_dir=self.base_dir, is_continue=False)
        except FileStructManager.FSMException as err:
            self.fail("Raise error when base directory exists but empty: [{}]".format(err))

        os.makedirs(os.path.join(self.base_dir, 'new_dir'))
        try:
            FileStructManager(base_dir=self.base_dir, is_continue=False)
        except:
            self.fail("Error initialize when exists non-registered folders in base directory")

        shutil.rmtree(self.base_dir, ignore_errors=True) 
开发者ID:toodef,项目名称:neural-pipeline,代码行数:25,代码来源:utils_test.py

示例10: dotplot2

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def dotplot2(s1, s2, wordsize=5, overlap=5, verbose=1):
        """ verbose = 0 (no progress), 1 (progress if s1 and s2 are long) or
        2 (progress in any case) """
        doProgress = False
        if verbose > 1 or len(s1)*len(s2) > 1e6:
            doProgress = True

        mat = numpy.ones(((len(s1)-wordsize)/overlap+2, (len(s2)-wordsize)/overlap+2))

        for i in range(0, len(s1)-wordsize, overlap):
            if i % 1000 == 0 and doProgress:
                logging.info("  dotplot progress: {} of {} rows done".format(i, len(s1)-wordsize))
            word1 = s1[i:i+wordsize]

            for j in range(0, len(s2)-wordsize, overlap):
                word2 = s2[j:j+wordsize]

                if word1 == word2 or word1 == word2[::-1]:
                    mat[i/overlap, j/overlap] = 0
        
        imgData = None
        tempDir = tempfile.mkdtemp()
        try:
            path = os.path.join(tempDir, "dotplot.png")
            misc.imsave(path, mat)
            imgData = open(path).read()
        except Exception as e:
            logging.error("Error generating dotplots:'{}'".format(e))
        finally:
            shutil.rmtree(tempDir)
        return imgData 
开发者ID:svviz,项目名称:svviz,代码行数:33,代码来源:dotplots.py

示例11: __del__

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def __del__(self):
        '''
            Called when the instance is about to be destroyed.
        '''
        if hasattr(self, '_tmpdir'):
            self._logger.info('Clean up temporary directory "{0}".'.format(self._tmpdir))
            shutil.rmtree(self._tmpdir) 
开发者ID:apache,项目名称:incubator-spot,代码行数:9,代码来源:collector.py

示例12: fix_plugin_directories

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def fix_plugin_directories(dest):
    """
    Loops through all folders in the output directory, reads the their manifest
    file, and renames the directory to the standard <platform>_<guid> format
    """
    # Loop through directories in the destination directory
    for existing_dir in os.listdir(dest):
        existing_path = os.path.join(dest, existing_dir)

        # Skip non-directories
        if not os.path.isdir(existing_path):
            continue

        try:
            with open(os.path.join(existing_path, 'manifest.json')) as m:
                data = json.load(m)
                platform = data['platform']
                guid = data['guid']

                # Close json file
                m.close()

                expected_dir = platform + '_' + guid
                expected_path = os.path.join(dest, expected_dir)

                if existing_path != expected_path:
                    print('NOTICE: Folder should be "{}", but it is named "{}"'
                          .format(expected_dir, existing_dir))

                    if os.path.isdir(expected_path):
                        print('NOTICE: Correct pathed plugin already exists,'
                              + ' deleting extra plugin')
                        shutil.rmtree(existing_path)
                    else:
                        print('NOTICE: Renaming folder to proper name')
                        shutil.move(existing_path, expected_path)
        except (FileNotFoundError, json.decoder.JSONDecodeError, KeyError):
            print('ERROR: Could not read plugin data from {} folder'
                  .format(existing_path)) 
开发者ID:Slashbunny,项目名称:gog-galaxy-plugin-downloader,代码行数:41,代码来源:download.py

示例13: delete_old_plugins

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def delete_old_plugins(data, dest):
    """
    Deletes versions of plugins that don't match the yaml manifest. In theory
    this should only be older versions, but any version that doesn't match
    the yaml definition will be deleted

    This explicitly does not touch other directories that do not match the
    known plugin names.

    If the version doesn't match the yaml definition, the directory is removed
    """
    # Loop over each plugin
    for name, data in data.items():
        expected_plugin_dir = name + '_' + data['guid']

        # Loop through directories in the destination directory
        for item in os.listdir(dest):
            full_path = os.path.join(dest, item)

            # Skip non-directories
            if not os.path.isdir(full_path):
                continue

            # Skip directory names that are in the valid plugin directory array
            if item == expected_plugin_dir:
                continue

            # If any other directory begins with <plugin_name>_, delete it
            if item.startswith(name + '_'):
                print('Deleting wrong version "{}" from "{}"'
                      .format(item, dest))
                shutil.rmtree(full_path) 
开发者ID:Slashbunny,项目名称:gog-galaxy-plugin-downloader,代码行数:34,代码来源:download.py

示例14: download

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def download(env):
    """60000 tiny colour images in 100 classes.

The CIFAR-100 dataset consists of 60000 32x32 colour images in 100 
classes, with 6000 images per class. There are 500 training images
and 100 testing images per class.

Credits:
  Alex Krizhevsky
  Vinod Nair
  Geoffrey Hinton

For more information visit: 
https://www.cs.toronto.edu/~kriz/cifar.html"""

    url = "https://www.cs.toronto.edu/~kriz/cifar-100-python.tar.gz"

    samples_dir = env.get('base.samples_dir')

    print("Downloading CIFAR-100 to {}.".format(samples_dir))

    src_dir = download_files([url], dir=env.get('base.cache_dir'))
    path = os.path.join(src_dir, "cifar-100-python.tar.gz")

    tarf = tarfile.TarFile(path, 'r:gz')
    tarf.extractall(src_dir)
    tarf.close()

    shutil.rmtree(src_dir)

    print("Finished downloading CIFAR-100.") 
开发者ID:mme,项目名称:vergeml,代码行数:33,代码来源:cifar_100.py

示例15: download

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import rmtree [as 别名]
def download(env):
    """60000 tiny colour images in 10 classes.

The CIFAR-10 dataset consists of 60000 32x32 colour images in 10 
classes, with 6000 images per class. There are 50000 training 
images and 10000 test images.

Credits:
  Alex Krizhevsky
  Vinod Nair
  Geoffrey Hinton

For more information visit: 
https://www.cs.toronto.edu/~kriz/cifar.html"""

    url = "https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz"

    samples_dir = env.get('base.samples_dir')

    print("Downloading CIFAR-10 to {}.".format(samples_dir))

    src_dir = download_files([url], dir=env.get('base.cache_dir'))
    path = os.path.join(src_dir, "cifar-10-python.tar.gz")

    tarf = tarfile.TarFile(path, 'r:gz')
    tarf.extractall(src_dir)
    tarf.close()

    shutil.rmtree(src_dir)

    print("Finished downloading CIFAR-10.") 
开发者ID:mme,项目名称:vergeml,代码行数:33,代码来源:cifar_10.py


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