Mercurial > libervia-backend
comparison sat/memory/memory.py @ 3371:e8d74ac7c479
core (memory/memory): added `getCachePath` method to get a cache dir from a namespace.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 28 Sep 2020 17:00:14 +0200 |
parents | d24252df91ee |
children | be6d91572633 |
comparison
equal
deleted
inserted
replaced
3370:2157880ba3b4 | 3371:e8d74ac7c479 |
---|---|
39 from sat.memory.disco import Discovery | 39 from sat.memory.disco import Discovery |
40 from sat.memory.crypto import BlockCipher | 40 from sat.memory.crypto import BlockCipher |
41 from sat.memory.crypto import PasswordHasher | 41 from sat.memory.crypto import PasswordHasher |
42 from sat.tools import config as tools_config | 42 from sat.tools import config as tools_config |
43 from sat.tools.common import data_format | 43 from sat.tools.common import data_format |
44 from sat.tools.common import regex | |
44 | 45 |
45 | 46 |
46 log = getLogger(__name__) | 47 log = getLogger(__name__) |
47 | 48 |
48 | 49 |
236 self._key_signals = set() # key which need a signal to frontends when updated | 237 self._key_signals = set() # key which need a signal to frontends when updated |
237 self.subscriptions = {} | 238 self.subscriptions = {} |
238 self.auth_sessions = PasswordSessions() # remember the authenticated profiles | 239 self.auth_sessions = PasswordSessions() # remember the authenticated profiles |
239 self.disco = Discovery(host) | 240 self.disco = Discovery(host) |
240 self.config = tools_config.parseMainConf(log_filenames=True) | 241 self.config = tools_config.parseMainConf(log_filenames=True) |
242 self._cache_path = Path(self.getConfig("", "local_dir"), C.CACHE_DIR) | |
241 database_file = os.path.expanduser( | 243 database_file = os.path.expanduser( |
242 os.path.join(self.getConfig("", "local_dir"), C.SAVEFILE_DATABASE) | 244 os.path.join(self.getConfig("", "local_dir"), C.SAVEFILE_DATABASE) |
243 ) | 245 ) |
244 self.storage = SqliteStorage(database_file, host.version) | 246 self.storage = SqliteStorage(database_file, host.version) |
245 PersistentDict.storage = self.storage | 247 PersistentDict.storage = self.storage |
1763 if file_data["type"] != C.FILE_TYPE_DIRECTORY and recursive: | 1765 if file_data["type"] != C.FILE_TYPE_DIRECTORY and recursive: |
1764 raise ValueError("recursive can only be set for directories") | 1766 raise ValueError("recursive can only be set for directories") |
1765 files_path = self.host.getLocalPath(None, C.FILES_DIR, profile=False) | 1767 files_path = self.host.getLocalPath(None, C.FILES_DIR, profile=False) |
1766 yield self._deleteFile(client, peer_jid, recursive, files_path, file_data) | 1768 yield self._deleteFile(client, peer_jid, recursive, files_path, file_data) |
1767 | 1769 |
1770 ## Cache ## | |
1771 | |
1772 def getCachePath(self, namespace: str, *args: str) -> Path: | |
1773 """Get path to use to get a common path for a namespace | |
1774 | |
1775 This can be used by plugins to manage permanent data. It's the responsability | |
1776 of plugins to clean this directory from unused data. | |
1777 @param namespace: unique namespace to use | |
1778 @param args: extra identifier which will be added to the path | |
1779 """ | |
1780 namespace = namespace.strip().lower() | |
1781 return Path( | |
1782 self._cache_path, | |
1783 regex.pathEscape(namespace), | |
1784 *(regex.pathEscape(a) for a in args) | |
1785 ) | |
1786 | |
1768 ## Misc ## | 1787 ## Misc ## |
1769 | 1788 |
1770 def isEntityAvailable(self, client, entity_jid): | 1789 def isEntityAvailable(self, client, entity_jid): |
1771 """Tell from the presence information if the given entity is available. | 1790 """Tell from the presence information if the given entity is available. |
1772 | 1791 |