Mercurial > libervia-backend
diff sat/core/sat_main.py @ 3932:7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
- renaming is following global methods renaming to use snake_case
- for reasons lost in the mists of time, a `profile` argument was used while checking if
`client` is set is enough, and `client.profile` was escaped but actually not used in the
path.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 10 Oct 2022 15:23:59 +0200 |
parents | ce5d03772689 |
children | f5ba7594cced |
line wrap: on
line diff
--- a/sat/core/sat_main.py Fri Oct 07 22:22:13 2022 +0200 +++ b/sat/core/sat_main.py Mon Oct 10 15:23:59 2022 +0200 @@ -23,6 +23,8 @@ import copy from pathlib import Path from typing import Optional, List, Tuple, Dict + +from wokkel.data_form import Option import sat from sat.core.i18n import _, D_, languageSwitch from sat.core import patches @@ -877,38 +879,34 @@ # local dirs - def getLocalPath( + def get_local_path( self, - client, + client: Optional[xmpp.SatXMPPEntity], dir_name: str, - *extra_path, - **kwargs + *extra_path: str, + component: bool = False, ) -> Path: """Retrieve path for local data if path doesn't exist, it will be created - @param client(SatXMPPClient, None): client instance - used when profile is set, can be None if profile is False - @param dir_name(unicode): name of the main path directory - @param component(bool): if True, path will be prefixed with C.COMPONENTS_DIR - @param profile(bool): if True, path will be suffixed by profile name + @param client: client instance + if not none, client.profile will be used as last path element + @param dir_name: name of the main path directory @param *extra_path: extra path element(s) to use + @param component: if True, path will be prefixed with C.COMPONENTS_DIR @return: path """ - # FIXME: component and profile are parsed with **kwargs because of python 2 - # limitations. Once moved to python 3, this can be fixed - component = kwargs.pop("component", False) - profile = kwargs.pop("profile", True) - assert not kwargs - - path_elts = [self.memory.getConfig("", "local_dir")] + local_dir = self.memory.getConfig("", "local_dir") + if not local_dir: + raise exceptions.InternalError("local_dir must be set") + path_elts = [] if component: path_elts.append(C.COMPONENTS_DIR) path_elts.append(regex.pathEscape(dir_name)) if extra_path: path_elts.extend([regex.pathEscape(p) for p in extra_path]) - if profile: - regex.pathEscape(client.profile) + if client is not None: + path_elts.append(regex.pathEscape(client.profile)) local_path = Path(*path_elts) local_path.mkdir(0o700, parents=True, exist_ok=True) return local_path