Python pathlib 模块,PosixPath() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用pathlib.PosixPath()

项目:ceph-lcm    作者:Mirantis    | 项目源码 | 文件源码
def test_prepare_api_response(new_cluster):
    integration = cinder_integration.CinderIntegration.find_one(
        new_cluster.model_id
    )
    integration.config = "config"
    integration.keyrings["images.keyring"] = "[client.images]\n\tkey = 111"
    integration.keyrings["vols.keyring"] = "[client.vols]\n\tkey = 22"

    root_path = pathlib.PosixPath(pytest.faux.gen_alphanumeric())
    response = integration.prepare_api_response(str(root_path))

    assert str(root_path.joinpath("ceph.conf")) in response
    assert str(root_path.joinpath("images.keyring")) in response
    assert str(root_path.joinpath("vols.keyring")) in response
    assert len(response) == 3

    assert response[str(root_path.joinpath("images.keyring"))] == \
        integration.keyrings["images.keyring"]
    assert response[str(root_path.joinpath("vols.keyring"))] == \
        integration.keyrings["vols.keyring"]

    assert "[client.images]" in response[str(root_path.joinpath("ceph.conf"))]
    assert "[client.vols]" in response[str(root_path.joinpath("ceph.conf"))]
项目:dopplerr    作者:Stibbons    | 项目源码 | 文件源码
def find_config_storage(self):
        configfile = self.json_configstorage_default_filename
        if self.json_configstorage_environ_var_name in os.environ:
            configfile = os.environ[self.json_configstorage_environ_var_name]
            log.debug("%s defined: %s", self.json_configstorage_environ_var_name, configfile)
        for i in range(len(sys.argv)):
            good = []
            if self.json_configstorage_short_param_name:
                good.append(self.json_configstorage_short_param_name)
            if self.json_configstorage_long_param_name:
                good.append(self.json_configstorage_long_param_name)
            if sys.argv[i] in good:
                if i == len(sys.argv):
                    raise Exception("No value given to {}".format(" or ".join(good)))
                configfile = sys.argv[i + 1]
                log.debug("%s defined: %s", " or ".join(good), configfile)
                break
        config_file_path = PosixPath(configfile)
        log.debug("Configuration file set to: %s", configfile)
        self.__resolved_config_file = config_file_path.resolve().as_posix()
        self._load_bare_config()
项目:ceph-lcm    作者:Mirantis    | 项目源码 | 文件源码
def prepare_api_response(self, root_path):
        path = pathlib.PosixPath(root_path)
        config = self.config

        response = {}
        for basename, content in self.keyrings.items():
            response[str(path.joinpath(basename))] = content
            config += "\n{0}\nkeyring = {1}\n".format(
                content.split("\n", 1)[0],
                path.joinpath(basename)
            )
        response[str(path.joinpath("ceph.conf"))] = config

        return response
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_concrete_class(self):
        p = self.cls('a')
        self.assertIs(type(p),
            pathlib.WindowsPath if os.name == 'nt' else pathlib.PosixPath)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_unsupported_flavour(self):
        if os.name == 'nt':
            self.assertRaises(NotImplementedError, pathlib.PosixPath)
        else:
            self.assertRaises(NotImplementedError, pathlib.WindowsPath)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_concrete_class(self):
        p = self.cls('a')
        self.assertIs(type(p),
            pathlib.WindowsPath if os.name == 'nt' else pathlib.PosixPath)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_unsupported_flavour(self):
        if os.name == 'nt':
            self.assertRaises(NotImplementedError, pathlib.PosixPath)
        else:
            self.assertRaises(NotImplementedError, pathlib.WindowsPath)
项目:correct_shit_f    作者:PrieureDeSion    | 项目源码 | 文件源码
def test_get_rules(self, glob, settings, paths, conf_rules, exclude_rules,
                       loaded_rules):
        glob([PosixPath(path) for path in paths])
        settings.update(rules=conf_rules,
                        priority={},
                        exclude_rules=exclude_rules)
        rules = corrector.get_rules()
        self._compare_names(rules, loaded_rules)
项目:dopplerr    作者:Stibbons    | 项目源码 | 文件源码
def _find_frontend_data():
    installed_data_frontend = pkg_resources.resource_filename(__name__, 'frontend')
    if PosixPath(installed_data_frontend).exists():
        log.debug("Found local frontend path: %s", installed_data_frontend)
        return installed_data_frontend
    setup_py = pkg_resources.resource_filename(__name__, "main.py")
    dev_env_frontend_dist = PosixPath(setup_py).parent.parent / "frontend" / "dist"
    if dev_env_frontend_dist.exists():
        log.debug("Found dev local frontend path: %s", dev_env_frontend_dist)
        return str(dev_env_frontend_dist)
    return None
项目:dopplerr    作者:Stibbons    | 项目源码 | 文件源码
def _load_bare_config(self):
        log.debug("Loading configuration file: %s", self.__resolved_config_file)
        config_file_path = PosixPath(self.__resolved_config_file)
        if config_file_path.exists():
            with config_file_path.open() as f:
                self.__bare_config_dict = json.load(f)
        else:
            self.__bare_config_dict = {}
项目:dopplerr    作者:Stibbons    | 项目源码 | 文件源码
def save_bare_config_dict(self, bare_cfg):
        with PosixPath(self.__resolved_config_file).open('w') as f:
            f.write(json.dumps(bare_cfg, sort_keys=True, indent=4, separators=(',', ': ')))