changeset 3285:4240b44842bb

core: getLocalPath now returns a Path
author Goffi <goffi@goffi.org>
date Fri, 29 May 2020 21:02:20 +0200
parents 751d8fa45ced
children ddf3ded93b78
files sat/core/sat_main.py
diffstat 1 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/sat/core/sat_main.py	Fri May 29 20:57:23 2020 +0200
+++ b/sat/core/sat_main.py	Fri May 29 21:02:20 2020 +0200
@@ -856,8 +856,14 @@
 
     # local dirs
 
-    def getLocalPath(self, client, dir_name, *extra_path, **kwargs):
-        """retrieve path for local data
+    def getLocalPath(
+        self,
+        client,
+        dir_name: str,
+        *extra_path,
+        **kwargs
+    ) -> Path:
+        """Retrieve path for local data
 
         if path doesn't exist, it will be created
         @param client(SatXMPPClient, None): client instance
@@ -866,7 +872,7 @@
         @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 *extra_path: extra path element(s) to use
-        @return (unicode): path
+        @return: path
         """
         # FIXME: component and profile are parsed with **kwargs because of python 2
         #   limitations. Once moved to python 3, this can be fixed
@@ -882,10 +888,9 @@
             path_elts.extend([regex.pathEscape(p) for p in extra_path])
         if profile:
             regex.pathEscape(client.profile)
-        path = os.path.join(*path_elts)
-        if not os.path.exists(path):
-            os.makedirs(path)
-        return path
+        local_path = Path(*path_elts)
+        local_path.mkdir(0o700, parents=True, exist_ok=True)
+        return local_path
 
     ## Client management ##