changeset 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 6c5f0fbc519b
children cecf45416403
files sat/core/sat_main.py sat/memory/memory.py sat/plugins/plugin_comp_file_sharing.py sat/plugins/plugin_comp_file_sharing_management.py
diffstat 4 files changed, 23 insertions(+), 25 deletions(-) [+]
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
--- a/sat/memory/memory.py	Fri Oct 07 22:22:13 2022 +0200
+++ b/sat/memory/memory.py	Mon Oct 10 15:23:59 2022 +0200
@@ -1828,7 +1828,7 @@
         file_data = files_data[0]
         if file_data["type"] != C.FILE_TYPE_DIRECTORY and recursive:
             raise ValueError("recursive can only be set for directories")
-        files_path = self.host.getLocalPath(None, C.FILES_DIR, profile=False)
+        files_path = self.host.get_local_path(None, C.FILES_DIR)
         await self._deleteFile(client, peer_jid, recursive, files_path, file_data)
 
     ## Cache ##
--- a/sat/plugins/plugin_comp_file_sharing.py	Fri Oct 07 22:22:13 2022 +0200
+++ b/sat/plugins/plugin_comp_file_sharing.py	Mon Oct 10 15:23:59 2022 +0200
@@ -322,8 +322,8 @@
 
     def __init__(self, file_sharing):
         self.file_sharing = file_sharing
-        self.file_tmp_dir = file_sharing.host.getLocalPath(
-            None, C.FILES_TMP_DIR, TMP_BUFFER_DIR, component=True, profile=False
+        self.file_tmp_dir = file_sharing.host.get_local_path(
+            None, C.FILES_TMP_DIR, TMP_BUFFER_DIR, component=True
         )
         for old_file in self.file_tmp_dir.iterdir():
             log.debug(f"purging old buffer file at {old_file}")
@@ -369,7 +369,7 @@
         self.host.trigger.add(
             "XEP-0329_parseResult_directory",
             self._getDirectoryMetadataElts)
-        self.files_path = self.host.getLocalPath(None, C.FILES_DIR, profile=False)
+        self.files_path = self.host.get_local_path(None, C.FILES_DIR)
         self.http_port = int(self.host.memory.getConfig(
             'component file-sharing', 'http_upload_port', 8888))
         connection_type = self.host.memory.getConfig(
@@ -532,8 +532,8 @@
                         file_size=utils.getHumanSize(file_data['size'])
                     )
                 )
-        file_tmp_dir = self.host.getLocalPath(
-            None, C.FILES_TMP_DIR, peer_jid.userhost(), component=True, profile=False
+        file_tmp_dir = self.host.get_local_path(
+            None, C.FILES_TMP_DIR, peer_jid.userhost(), component=True
         )
         file_tmp_path = file_data['file_path'] = files_utils.get_unique_name(
             file_tmp_dir/filename)
--- a/sat/plugins/plugin_comp_file_sharing_management.py	Fri Oct 07 22:22:13 2022 +0200
+++ b/sat/plugins/plugin_comp_file_sharing_management.py	Mon Oct 10 15:23:59 2022 +0200
@@ -73,7 +73,7 @@
         self.host = host
         self._c = host.plugins["XEP-0050"]
         self._t = host.plugins["XEP-0264"]
-        self.files_path = host.getLocalPath(None, C.FILES_DIR, profile=False)
+        self.files_path = host.get_local_path(None, C.FILES_DIR)
         host.bridge.addMethod(
             "fileSharingDelete",
             ".plugin",