core (memory/memory): added getCachePath method to get a cache dir from a namespace.

This commit is contained in:
Goffi 2020-09-28 17:00:14 +02:00
commit 0250053e19

View file

@ -41,6 +41,7 @@ from sat.memory.crypto import BlockCipher
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 @@ class Memory(object):
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 @@ class Memory(object):
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):