# HG changeset patch # User Goffi # Date 1601305214 -7200 # Node ID e8d74ac7c479c2d86f82013ef2ad5b9ead8ac272 # Parent 2157880ba3b47f0d7f4905ecbc4926e16e72b637 core (memory/memory): added `getCachePath` method to get a cache dir from a namespace. diff -r 2157880ba3b4 -r e8d74ac7c479 sat/memory/memory.py --- a/sat/memory/memory.py Sun Sep 20 14:05:40 2020 +0200 +++ b/sat/memory/memory.py Mon Sep 28 17:00:14 2020 +0200 @@ -41,6 +41,7 @@ from sat.memory.crypto import PasswordHasher from sat.tools import config as tools_config from sat.tools.common import data_format +from sat.tools.common import regex log = getLogger(__name__) @@ -238,6 +239,7 @@ self.auth_sessions = PasswordSessions() # remember the authenticated profiles self.disco = Discovery(host) self.config = tools_config.parseMainConf(log_filenames=True) + self._cache_path = Path(self.getConfig("", "local_dir"), C.CACHE_DIR) database_file = os.path.expanduser( os.path.join(self.getConfig("", "local_dir"), C.SAVEFILE_DATABASE) ) @@ -1765,6 +1767,23 @@ files_path = self.host.getLocalPath(None, C.FILES_DIR, profile=False) yield self._deleteFile(client, peer_jid, recursive, files_path, file_data) + ## Cache ## + + def getCachePath(self, namespace: str, *args: str) -> Path: + """Get path to use to get a common path for a namespace + + This can be used by plugins to manage permanent data. It's the responsability + of plugins to clean this directory from unused data. + @param namespace: unique namespace to use + @param args: extra identifier which will be added to the path + """ + namespace = namespace.strip().lower() + return Path( + self._cache_path, + regex.pathEscape(namespace), + *(regex.pathEscape(a) for a in args) + ) + ## Misc ## def isEntityAvailable(self, client, entity_jid):