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


Python os.removedirs方法代碼示例

本文整理匯總了Python中os.removedirs方法的典型用法代碼示例。如果您正苦於以下問題:Python os.removedirs方法的具體用法?Python os.removedirs怎麽用?Python os.removedirs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.removedirs方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mkdir_permissions

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def mkdir_permissions(request):
    """ Fixture for creating dir with specific read/write permissions """
    def make_mkdir(read=False, write=False):
        if read and write:
            mode = 0o755
        elif read and not write:
            mode = 0o555
        elif not read and write:
            mode = 0o333
        elif not read and not write:
            mode = 0o000

        path = mkdtemp()
        os.chmod(path, mode)

        def fin():
            os.chmod(path, 0o755)
            os.removedirs(path)
        request.addfinalizer(fin)

        return path

    return make_mkdir 
開發者ID:ceholden,項目名稱:yatsm,代碼行數:25,代碼來源:conftest.py

示例2: test_test_cache

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def test_test_cache(mkdir_permissions):
    # Test when cache dir exists already
    path = mkdir_permissions(read=False, write=False)
    assert (False, False) == cache.test_cache(dict(cache_line_dir=path))

    path = mkdir_permissions(read=False, write=True)
    assert (False, True) == cache.test_cache(dict(cache_line_dir=path))

    path = mkdir_permissions(read=True, write=False)
    assert (True, False) == cache.test_cache(dict(cache_line_dir=path))

    path = mkdir_permissions(read=True, write=True)
    assert (True, True) == cache.test_cache(dict(cache_line_dir=path))

    # Test when cache dir doesn't exist
    tmp = os.path.join(tempfile.tempdir,
                       next(tempfile._get_candidate_names()) + '_yatsm')
    read_write = cache.test_cache(dict(cache_line_dir=tmp))
    os.removedirs(tmp)

    assert (True, True) == read_write 
開發者ID:ceholden,項目名稱:yatsm,代碼行數:23,代碼來源:test_cache.py

示例3: test_parseable_file_path

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def test_parseable_file_path(self):
        file_name = "test_target.py"
        fake_path = HERE + os.getcwd()
        module = join(fake_path, file_name)

        try:
            # create module under directories which have the same name as reporter.path_strip_prefix
            # e.g. /src/some/path/src/test_target.py when reporter.path_strip_prefix = /src/
            os.makedirs(fake_path)
            with open(module, "w") as test_target:
                test_target.write("a,b = object()")

            self._test_output(
                [module, "--output-format=parseable"],
                expected_output=join(os.getcwd(), file_name),
            )
        finally:
            os.remove(module)
            os.removedirs(fake_path) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:21,代碼來源:test_self.py

示例4: _init_dirs

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def _init_dirs(self):
        test_dirs = ["a a", "b", "D_"]
        config = "improbable"
        root = tempfile.mkdtemp()

        def cleanup():
            try:
                os.removedirs(root)
            except (FileNotFoundError, OSError):
                pass

        os.chdir(root)

        for dir_ in test_dirs:
            os.mkdir(dir_, 0o0750)

            f = "{0}.toml".format(config)
            flags = os.O_WRONLY | os.O_CREAT
            rel_path = "{0}/{1}".format(dir_, f)
            abs_file_path = os.path.join(root, rel_path)
            with os.fdopen(os.open(abs_file_path, flags, 0o0640), "w") as fp:
                fp.write('key = "value is {0}"\n'.format(dir_))

        return root, config, cleanup 
開發者ID:alexferl,項目名稱:vyper,代碼行數:26,代碼來源:test_vyper.py

示例5: sorter

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def sorter(user_directory, api_type, location, metadata):
    legacy_directory = os.path.join(user_directory, api_type, location)
    if not os.path.isdir(legacy_directory):
        return
    legacy_files = os.listdir(legacy_directory)
    metadata_directory = os.path.join(
        user_directory, "Metadata", api_type+".json")
    results = list(chain(*metadata["valid"]))
    for result in results:
        legacy_filepath = os.path.join(legacy_directory, result["filename"])
        filepath = os.path.join(result["directory"], result["filename"])
        if result["filename"] in legacy_files:
            if os.path.isfile(filepath):
                same_file = filecmp.cmp(
                    legacy_filepath, filepath, shallow=False)
                if same_file:
                    os.remove(filepath)
                else:
                    os.remove(legacy_filepath)
                    continue
            shutil.move(legacy_filepath, filepath)
    if not os.listdir(legacy_directory):
        os.removedirs(legacy_directory) 
開發者ID:DIGITALCRIMINAL,項目名稱:OnlyFans,代碼行數:25,代碼來源:ofsorter.py

示例6: renames

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [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

示例7: delete_output_files_jobs

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def delete_output_files_jobs(self, recursive=False):
        """
        Delete the output files of all finished jobs in the current project and in all subprojects if recursive=True is
        selected.

        Args:
            recursive (bool): [True/False] delete the output files of all jobs in all subprojects - default=False
        """
        for job_id in self.get_job_ids(recursive=recursive):
            job = self.inspect(job_id)
            if job.status == "finished":
                for file in job.list_files():
                    fullname = os.path.join(job.working_directory, file)
                    if os.path.isfile(fullname) and ".h5" not in fullname:
                        os.remove(fullname)
                    elif os.path.isdir(fullname):
                        os.removedirs(fullname) 
開發者ID:pyiron,項目名稱:pyiron,代碼行數:19,代碼來源:generic.py

示例8: RemoveAllStalePycFiles

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def RemoveAllStalePycFiles(base_dir):
  """Scan directories for old .pyc files without a .py file and delete them."""
  for dirname, _, filenames in os.walk(base_dir):
    if '.git' in dirname:
      continue
    for filename in filenames:
      root, ext = os.path.splitext(filename)
      if ext != '.pyc':
        continue

      pyc_path = os.path.join(dirname, filename)
      py_path = os.path.join(dirname, root + '.py')

      try:
        if not os.path.exists(py_path):
          os.remove(pyc_path)
      except OSError:
        # Wrap OS calls in try/except in case another process touched this file.
        pass

    try:
      os.removedirs(dirname)
    except OSError:
      # Wrap OS calls in try/except in case another process touched this dir.
      pass 
開發者ID:FSecureLABS,項目名稱:Jandroid,代碼行數:27,代碼來源:systrace.py

示例9: do_clear_data_by_user

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def do_clear_data_by_user(QQ, conn):
    DATA_DIR_KEY = BASE_DIR + QQ + '/'
    WEB_IMAGE_PATH_DIR = WEB_IMAGE_PATH + QQ + '/'
    if os.path.exists(DATA_DIR_KEY):
        # 刪除有QQ號的所有key
        # 該方法在docker中無法使用,因為該容器內無redis-cli
        # delete_cmd = "redis-cli KEYS \"*" + QQ + "*\"|xargs redis-cli DEL"
        # print(delete_cmd)
        # os.system(delete_cmd)
        # 刪除 該路徑下所有文件
        os.system("rm -rf " + DATA_DIR_KEY)
        os.system("rm -rf " + WEB_IMAGE_PATH_DIR)
        conn.hdel(USER_MAP_KEY, QQ)
        conn.lrem(WAITING_USER_LIST, 0, QQ)
        # redis的del不支持正則表達式,因此隻能循環刪除
        all_keys = conn.keys("*" + QQ + "*")
        print()
        for key in all_keys:
            conn.delete(key)
        # os.removedirs(os.path.join(BASE_DIR, QQ))
        finish = 1
    else:
        finish = 2
    return finish 
開發者ID:Maicius,項目名稱:QQZoneMood,代碼行數:26,代碼來源:dataController.py

示例10: remove_dir

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def remove_dir(dir_path):
    print("刪除文件夾的目錄是:"+dir_path)

    # 如果是空文件夾
    if not os.listdir(dir_path):
       os.removedirs(dir_path)

    for root, dirs, files in os.walk(dir_path, topdown=False):
        for name in files:
            os.remove(os.path.join(root, name))
        for name in dirs:
            os.rmdir(os.path.join(root, name)) 
開發者ID:xingag,項目名稱:tools_python,代碼行數:14,代碼來源:delete_build.py

示例11: renames

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [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

示例12: clean_path

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def clean_path(path):
        if not path:
            logging.info("Directory clean up - empty dir passed")
            return

        logging.info("Directory clean up - removing  %s", path)
        try:
            # TODO: need to use osfs-rmdir on VSAN. For now jus yell if it failed
            os.removedirs(path)
        except Exception as e:
            logging.warning("Directory clean up failed  -  %s, err: %s", path, e) 
開發者ID:vmware-archive,項目名稱:vsphere-storage-for-docker,代碼行數:13,代碼來源:vmdk_ops_test.py

示例13: tearDown

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def tearDown(self):
        path = os.path.join(test_support.TESTFN, 'dir1', 'dir2', 'dir3',
                            'dir4', 'dir5', 'dir6')
        # If the tests failed, the bottom-most directory ('../dir6')
        # may not have been created, so we look for the outermost directory
        # that exists.
        while not os.path.exists(path) and path != test_support.TESTFN:
            path = os.path.dirname(path)

        os.removedirs(path) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_os.py

示例14: removedirs

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def removedirs(self):
		os.removedirs(self)


	# --- Modifying operations on files 
開發者ID:OpenMTC,項目名稱:OpenMTC,代碼行數:7,代碼來源:__init__.py

示例15: _delete_file

# 需要導入模塊: import os [as 別名]
# 或者: from os import removedirs [as 別名]
def _delete_file(configurator, path):
    """ remove file and remove it's directories if empty """
    path = os.path.join(configurator.target_directory, path)
    os.remove(path)
    try:
        os.removedirs(os.path.dirname(path))
    except OSError:
        pass 
開發者ID:acsone,項目名稱:bobtemplates.odoo,代碼行數:10,代碼來源:hooks.py


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