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


Python os.rmdir方法代码示例

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


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

示例1: test_prepare

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def test_prepare(self):
        p = get_data_folder()
        api = FileAPI(p)

        folders = ["one", "two"]
        relative = "/".join(folders) + "/three.txt"
        api.prepare_dir(relative)

        rmdirs = []
        for f in folders:
            p = p + "/" + f
            self.assertTrue(os.path.exists(p))
            rmdirs.append(p)

        self.assertFalse(os.path.exists(api.to_abs(relative)))

        for f in rmdirs[::-1]:
            os.rmdir(f) 
开发者ID:icoxfog417,项目名称:mlimages,代码行数:20,代码来源:test_file_api.py

示例2: get_cifar10

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def get_cifar10(data_dir):
    if not os.path.isdir(data_dir):
        os.system("mkdir " + data_dir)
    cwd = os.path.abspath(os.getcwd())
    os.chdir(data_dir)
    if (not os.path.exists('train.rec')) or \
       (not os.path.exists('test.rec')) :
        import urllib, zipfile, glob
        dirname = os.getcwd()
        zippath = os.path.join(dirname, "cifar10.zip")
        urllib.urlretrieve("http://data.mxnet.io/mxnet/data/cifar10.zip", zippath)
        zf = zipfile.ZipFile(zippath, "r")
        zf.extractall()
        zf.close()
        os.remove(zippath)
        for f in glob.glob(os.path.join(dirname, "cifar", "*")):
            name = f.split(os.path.sep)[-1]
            os.rename(f, os.path.join(dirname, name))
        os.rmdir(os.path.join(dirname, "cifar"))
    os.chdir(cwd)

# data 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:24,代码来源:get_data.py

示例3: test_create_new_folder_parallel

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def test_create_new_folder_parallel():
    folder = os.path.join('output', str(uuid.uuid4()))

    def run_makedirs(folder, exceptions):
        try:
            makedirs_safe(folder)
        except Exception as exc:
            exceptions.put(exc)

    for _ in range(5):
        exceptions = queue.Queue()
        thread1 = threading.Thread(target=run_makedirs, args=(folder, exceptions))
        thread2 = threading.Thread(target=run_makedirs, args=(folder, exceptions))
        thread1.start()
        thread2.start()
        thread1.join()
        thread2.join()

        assert exceptions.qsize() == 0
        assert os.path.isdir(folder)
        os.rmdir(folder) 
开发者ID:Telefonica,项目名称:toolium,代码行数:23,代码来源:test_path_utils.py

示例4: _delete_measures_files_for_metric

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def _delete_measures_files_for_metric(self, metric_id, files):
        for f in files:
            try:
                os.unlink(self._build_measure_path(metric_id, f))
            except OSError as e:
                # Another process deleted it in the meantime, no prob'
                if e.errno != errno.ENOENT:
                    raise
        try:
            os.rmdir(self._build_measure_path(metric_id))
        except OSError as e:
            # ENOENT: ok, it has been removed at almost the same time
            #         by another process
            # ENOTEMPTY: ok, someone pushed measure in the meantime,
            #            we'll delete the measures and directory later
            # EEXIST: some systems use this instead of ENOTEMPTY
            if e.errno not in (errno.ENOENT, errno.ENOTEMPTY, errno.EEXIST):
                raise 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:20,代码来源:file.py

示例5: test_prepare_find_m2m

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def test_prepare_find_m2m(self, sphere3_fn):
        l = sim_struct.LEADFIELD()
        l.pathfem = ''
        l.fnamehead = sphere3_fn
        path, n = os.path.split(sphere3_fn)
        dir_fn = os.path.join(path, 'm2m_'+n[:-4])
        os.mkdir(dir_fn)
        l._prepare()
        assert os.path.abspath(l.subpath) == os.path.abspath(dir_fn)
        os.rmdir(dir_fn)
        l = sim_struct.LEADFIELD()
        l.pathfem = ''
        l.fnamehead = sphere3_fn
        path, n = os.path.split(sphere3_fn)
        dir_fn = os.path.join(path, 'm2m_'+n[:-4])
        os.mkdir(dir_fn)
        l._prepare()
        assert os.path.abspath(l.subpath) == os.path.abspath(dir_fn)
        os.rmdir(dir_fn) 
开发者ID:simnibs,项目名称:simnibs,代码行数:21,代码来源:test_sim_struct.py

示例6: test_log_file

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def test_log_file(self):
        tmpdir = tempfile.mkdtemp()
        try:
            self.options.log_file_prefix = tmpdir + '/test_log'
            enable_pretty_logging(options=self.options, logger=self.logger)
            self.assertEqual(1, len(self.logger.handlers))
            self.logger.error('hello')
            self.logger.handlers[0].flush()
            filenames = glob.glob(tmpdir + '/test_log*')
            self.assertEqual(1, len(filenames))
            with open(filenames[0]) as f:
                self.assertRegexpMatches(f.read(), r'^\[E [^]]*\] hello$')
        finally:
            for handler in self.logger.handlers:
                handler.flush()
                handler.close()
            for filename in glob.glob(tmpdir + '/test_log*'):
                os.unlink(filename)
            os.rmdir(tmpdir) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:21,代码来源:log_test.py

示例7: test_log_file_with_timed_rotating

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def test_log_file_with_timed_rotating(self):
        tmpdir = tempfile.mkdtemp()
        try:
            self.options.log_file_prefix = tmpdir + '/test_log'
            self.options.log_rotate_mode = 'time'
            enable_pretty_logging(options=self.options, logger=self.logger)
            self.logger.error('hello')
            self.logger.handlers[0].flush()
            filenames = glob.glob(tmpdir + '/test_log*')
            self.assertEqual(1, len(filenames))
            with open(filenames[0]) as f:
                self.assertRegexpMatches(
                    f.read(),
                    r'^\[E [^]]*\] hello$')
        finally:
            for handler in self.logger.handlers:
                handler.flush()
                handler.close()
            for filename in glob.glob(tmpdir + '/test_log*'):
                os.unlink(filename)
            os.rmdir(tmpdir) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:23,代码来源:log_test.py

示例8: remove

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def remove(self, rec=1, ignore_errors=False):
        """ remove a file or directory (or a directory tree if rec=1).
        if ignore_errors is True, errors while removing directories will
        be ignored.
        """
        if self.check(dir=1, link=0):
            if rec:
                # force remove of readonly files on windows
                if iswin32:
                    self.chmod(0o700, rec=1)
                import shutil
                py.error.checked_call(
                    shutil.rmtree, self.strpath,
                    ignore_errors=ignore_errors)
            else:
                py.error.checked_call(os.rmdir, self.strpath)
        else:
            if iswin32:
                self.chmod(0o700)
            py.error.checked_call(os.remove, self.strpath) 
开发者ID:pytest-dev,项目名称:py,代码行数:22,代码来源:local.py

示例9: tearDown

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def tearDown(self):
        '''Remove any files generated during the test'''
        #unittest.TestCase.tearDown(self)
        
        root = os.path.join(".", "files")
        endingList = os.listdir(root)
        endingDir = os.getcwd()
        rmList = [fn for fn in endingList if fn not in self.startingList]
        
        if self.oldRoot == root:
            for fn in rmList:
                fnFullPath = os.path.join(root, fn)
                if os.path.isdir(fnFullPath):
                    os.rmdir(fnFullPath)
                else:
                    os.remove(fnFullPath)
        
        os.chdir(self.oldRoot) 
开发者ID:timmahrt,项目名称:ProMo,代码行数:20,代码来源:integration_tests.py

示例10: test_initial_pysat_load

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def test_initial_pysat_load(self):
        import shutil
        saved = False
        try:
            root = os.path.join(os.getenv('HOME'), '.pysat')
            new_root = os.path.join(os.getenv('HOME'), '.saved_pysat')
            shutil.move(root, new_root)
            saved = True
        except:
            pass

        re_load(pysat)

        try:
            if saved:
                # remove directory, trying to be careful
                os.remove(os.path.join(root, 'data_path.txt'))
                os.rmdir(root)
                shutil.move(new_root, root)
        except:
            pass

        assert True 
开发者ID:pysat,项目名称:pysat,代码行数:25,代码来源:test_utils.py

示例11: _download

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def _download(self, root):
        if os.path.isdir(os.path.join(root, 'train')):
            return  # Downloaded already

        os.makedirs(root, exist_ok=True)

        zip_file = os.path.join(root, self.UNZIPPED_DIR_NAME + '.zip')

        print('Downloading {}...'.format(os.path.basename(zip_file)))
        download_file_from_google_drive(self.GOOGLE_DRIVE_FILE_ID, zip_file)

        print('Extracting {}...'.format(os.path.basename(zip_file)))
        with zipfile.ZipFile(zip_file, 'r') as fp:
            fp.extractall(root)
        os.remove(zip_file)

        os.rename(os.path.join(root, self.UNZIPPED_DIR_NAME, self.UNZIPPED_TRAIN_SUBDIR),
                  os.path.join(root, 'train'))
        os.rename(os.path.join(root, self.UNZIPPED_DIR_NAME, self.UNZIPPED_VAL_SUBDIR),
                  os.path.join(root, 'val'))
        os.rmdir(os.path.join(root, self.UNZIPPED_DIR_NAME)) 
开发者ID:bayesiains,项目名称:nsf,代码行数:23,代码来源:imagenet.py

示例12: create_floppy_image

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def create_floppy_image(vlock_filename, floppy_image):
    """ Creates the floppy image used to install the vlock file
    """

    # Delete any existing image to start clean
    if os.access(floppy_image, os.R_OK):
        os.unlink(floppy_image)

    subprocess.check_call("mkfs.vfat -C {} 1440".format(floppy_image),
                          shell=True)

    floppy_mnt = "/tmp/mnt-dashboard"
    os.mkdir(floppy_mnt)

    subprocess.check_call("mount -o loop {} {}".format(floppy_image,
                                                       floppy_mnt),
                          shell=True)

    shutil.copy(vlock_filename, os.path.join(floppy_mnt, "versionlock.list"))

    subprocess.check_call("umount {}".format(floppy_mnt), shell=True)
    os.rmdir(floppy_mnt) 
开发者ID:dsp-jetpack,项目名称:JetPack,代码行数:24,代码来源:deploy-dashboard-vm.py

示例13: rollback

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def rollback(self):
        if not self.dry_run:
            for f in list(self.files_written):
                if os.path.exists(f):
                    os.remove(f)
            # dirs should all be empty now, except perhaps for
            # __pycache__ subdirs
            # reverse so that subdirs appear before their parents
            dirs = sorted(self.dirs_created, reverse=True)
            for d in dirs:
                flist = os.listdir(d)
                if flist:
                    assert flist == ['__pycache__']
                    sd = os.path.join(d, flist[0])
                    os.rmdir(sd)
                os.rmdir(d)     # should fail if non-empty
        self._init_record() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:util.py

示例14: test_subdirectory_deleted

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def test_subdirectory_deleted(self):
    """Tests that internal _directory_to_subdirs is updated on delete."""
    path = self._create_directory('test')
    sub_path = self._create_directory('test/test2')
    self._watcher.start()

    self.assertEqual(
        set([sub_path]),
        self._watcher._directory_to_subdirs[path])
    os.rmdir(sub_path)
    self.assertEqual(
        set([sub_path]),
        self._watcher._get_changed_paths())
    self.assertEqual(
        set(),
        self._watcher._directory_to_subdirs[path])

    os.rmdir(path)
    self.assertEqual(
        set([path]),
        self._watcher._get_changed_paths()) 
开发者ID:elsigh,项目名称:browserscope,代码行数:23,代码来源:inotify_file_watcher_test.py

示例15: _delete_cgroup

# 需要导入模块: import os [as 别名]
# 或者: from os import rmdir [as 别名]
def _delete_cgroup(cgroup_path):
    paths = _get_cgroup_full_path(cgroup_path)

    try:
        os.rmdir(paths[CgroupType.CPU])
    except FileNotFoundError:
        log.warning('cpu cgroup "{}" not found'.format(cgroup_path))

    try:
        os.rmdir(paths[CgroupType.MEMORY])
    except FileNotFoundError:
        log.warning('memory cgroup "{}" not found'.format(cgroup_path))

    try:
        os.rmdir(paths[CgroupType.CPUSET])
    except FileNotFoundError:
        log.warning('cpuset cgroup "{}" not found'.format(cgroup_path))

    try:
        os.rmdir(paths[CgroupType.PERF_EVENT])
    except FileNotFoundError:
        log.warning('perf_event cgroup "{}" not found'.format(cgroup_path)) 
开发者ID:intel,项目名称:workload-collocation-agent,代码行数:24,代码来源:tester.py


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