comparison 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
comparison
equal deleted inserted replaced
3931:6c5f0fbc519b 3932:7af29260ecb8
21 import uuid 21 import uuid
22 import hashlib 22 import hashlib
23 import copy 23 import copy
24 from pathlib import Path 24 from pathlib import Path
25 from typing import Optional, List, Tuple, Dict 25 from typing import Optional, List, Tuple, Dict
26
27 from wokkel.data_form import Option
26 import sat 28 import sat
27 from sat.core.i18n import _, D_, languageSwitch 29 from sat.core.i18n import _, D_, languageSwitch
28 from sat.core import patches 30 from sat.core import patches
29 patches.apply() 31 patches.apply()
30 from twisted.application import service 32 from twisted.application import service
875 return await image.convert(source, dest, extra) 877 return await image.convert(source, dest, extra)
876 878
877 879
878 # local dirs 880 # local dirs
879 881
880 def getLocalPath( 882 def get_local_path(
881 self, 883 self,
882 client, 884 client: Optional[xmpp.SatXMPPEntity],
883 dir_name: str, 885 dir_name: str,
884 *extra_path, 886 *extra_path: str,
885 **kwargs 887 component: bool = False,
886 ) -> Path: 888 ) -> Path:
887 """Retrieve path for local data 889 """Retrieve path for local data
888 890
889 if path doesn't exist, it will be created 891 if path doesn't exist, it will be created
890 @param client(SatXMPPClient, None): client instance 892 @param client: client instance
891 used when profile is set, can be None if profile is False 893 if not none, client.profile will be used as last path element
892 @param dir_name(unicode): name of the main path directory 894 @param dir_name: name of the main path directory
893 @param component(bool): if True, path will be prefixed with C.COMPONENTS_DIR
894 @param profile(bool): if True, path will be suffixed by profile name
895 @param *extra_path: extra path element(s) to use 895 @param *extra_path: extra path element(s) to use
896 @param component: if True, path will be prefixed with C.COMPONENTS_DIR
896 @return: path 897 @return: path
897 """ 898 """
898 # FIXME: component and profile are parsed with **kwargs because of python 2 899 local_dir = self.memory.getConfig("", "local_dir")
899 # limitations. Once moved to python 3, this can be fixed 900 if not local_dir:
900 component = kwargs.pop("component", False) 901 raise exceptions.InternalError("local_dir must be set")
901 profile = kwargs.pop("profile", True) 902 path_elts = []
902 assert not kwargs
903
904 path_elts = [self.memory.getConfig("", "local_dir")]
905 if component: 903 if component:
906 path_elts.append(C.COMPONENTS_DIR) 904 path_elts.append(C.COMPONENTS_DIR)
907 path_elts.append(regex.pathEscape(dir_name)) 905 path_elts.append(regex.pathEscape(dir_name))
908 if extra_path: 906 if extra_path:
909 path_elts.extend([regex.pathEscape(p) for p in extra_path]) 907 path_elts.extend([regex.pathEscape(p) for p in extra_path])
910 if profile: 908 if client is not None:
911 regex.pathEscape(client.profile) 909 path_elts.append(regex.pathEscape(client.profile))
912 local_path = Path(*path_elts) 910 local_path = Path(*path_elts)
913 local_path.mkdir(0o700, parents=True, exist_ok=True) 911 local_path.mkdir(0o700, parents=True, exist_ok=True)
914 return local_path 912 return local_path
915 913
916 ## Client management ## 914 ## Client management ##