comparison sat/core/sat_main.py @ 3285:4240b44842bb

core: getLocalPath now returns a Path
author Goffi <goffi@goffi.org>
date Fri, 29 May 2020 21:02:20 +0200
parents f300d78f08f3
children 9bc3fca290ab
comparison
equal deleted inserted replaced
3284:751d8fa45ced 3285:4240b44842bb
854 return await image.convert(source, dest, extra) 854 return await image.convert(source, dest, extra)
855 855
856 856
857 # local dirs 857 # local dirs
858 858
859 def getLocalPath(self, client, dir_name, *extra_path, **kwargs): 859 def getLocalPath(
860 """retrieve path for local data 860 self,
861 client,
862 dir_name: str,
863 *extra_path,
864 **kwargs
865 ) -> Path:
866 """Retrieve path for local data
861 867
862 if path doesn't exist, it will be created 868 if path doesn't exist, it will be created
863 @param client(SatXMPPClient, None): client instance 869 @param client(SatXMPPClient, None): client instance
864 used when profile is set, can be None if profile is False 870 used when profile is set, can be None if profile is False
865 @param dir_name(unicode): name of the main path directory 871 @param dir_name(unicode): name of the main path directory
866 @param component(bool): if True, path will be prefixed with C.COMPONENTS_DIR 872 @param component(bool): if True, path will be prefixed with C.COMPONENTS_DIR
867 @param profile(bool): if True, path will be suffixed by profile name 873 @param profile(bool): if True, path will be suffixed by profile name
868 @param *extra_path: extra path element(s) to use 874 @param *extra_path: extra path element(s) to use
869 @return (unicode): path 875 @return: path
870 """ 876 """
871 # FIXME: component and profile are parsed with **kwargs because of python 2 877 # FIXME: component and profile are parsed with **kwargs because of python 2
872 # limitations. Once moved to python 3, this can be fixed 878 # limitations. Once moved to python 3, this can be fixed
873 component = kwargs.pop("component", False) 879 component = kwargs.pop("component", False)
874 profile = kwargs.pop("profile", True) 880 profile = kwargs.pop("profile", True)
880 path_elts.append(regex.pathEscape(dir_name)) 886 path_elts.append(regex.pathEscape(dir_name))
881 if extra_path: 887 if extra_path:
882 path_elts.extend([regex.pathEscape(p) for p in extra_path]) 888 path_elts.extend([regex.pathEscape(p) for p in extra_path])
883 if profile: 889 if profile:
884 regex.pathEscape(client.profile) 890 regex.pathEscape(client.profile)
885 path = os.path.join(*path_elts) 891 local_path = Path(*path_elts)
886 if not os.path.exists(path): 892 local_path.mkdir(0o700, parents=True, exist_ok=True)
887 os.makedirs(path) 893 return local_path
888 return path
889 894
890 ## Client management ## 895 ## Client management ##
891 896
892 def setParam(self, name, value, category, security_limit, profile_key): 897 def setParam(self, name, value, category, security_limit, profile_key):
893 """set wanted paramater and notice observers""" 898 """set wanted paramater and notice observers"""