Mercurial > libervia-backend
diff sat/memory/cache.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | 2863345c9bbb |
children |
line wrap: on
line diff
--- a/sat/memory/cache.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/memory/cache.py Sat Apr 08 13:54:42 2023 +0200 @@ -45,9 +45,9 @@ if None, the cache will be common for all profiles """ self.profile = profile - path_elts = [host.memory.getConfig("", "local_dir"), C.CACHE_DIR] + path_elts = [host.memory.config_get("", "local_dir"), C.CACHE_DIR] if profile: - path_elts.extend(["profiles", regex.pathEscape(profile)]) + path_elts.extend(["profiles", regex.path_escape(profile)]) else: path_elts.append("common") self.cache_dir = Path(*path_elts) @@ -121,14 +121,14 @@ raise exceptions.DataError("Invalid char found") return self.cache_dir / filename - def getMetadata(self, uid: str, update_eol: bool = True) -> Optional[Dict[str, Any]]: + def get_metadata(self, uid: str, update_eol: bool = True) -> Optional[Dict[str, Any]]: """Retrieve metadata for cached data @param uid(unicode): unique identifier of file @param update_eol(bool): True if eol must extended if True, max_age will be added to eol (only if it is not already expired) @return (dict, None): metadata with following keys: - see [cacheData] for data details, an additional "path" key is the full path to + see [cache_data] for data details, an additional "path" key is the full path to cached file. None if file is not in cache (or cache is invalid) """ @@ -176,23 +176,23 @@ cache_data["path"] = self.getPath(cache_data["filename"]) return cache_data - def getFilePath(self, uid: str) -> Path: + def get_file_path(self, uid: str) -> Path: """Retrieve absolute path to file @param uid(unicode): unique identifier of file @return (unicode, None): absolute path to cached file None if file is not in cache (or cache is invalid) """ - metadata = self.getMetadata(uid) + metadata = self.get_metadata(uid) if metadata is not None: return metadata["path"] - def removeFromCache(self, uid, metadata=None): + def remove_from_cache(self, uid, metadata=None): """Remove data from cache @param uid(unicode): unique identifier cache file """ - cache_data = self.getMetadata(uid, update_eol=False) + cache_data = self.get_metadata(uid, update_eol=False) if cache_data is None: log.debug(f"cache with uid {uid!r} has already expired or been removed") return @@ -215,7 +215,7 @@ cache_file.unlink() log.debug(f"cache with uid {uid!r} has been removed") - def cacheData( + def cache_data( self, source: str, uid: str,