From 3268c1f28f7063e3b134fbbd688276cf97f3017d Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 4 Mar 2022 12:55:35 +0100 Subject: [PATCH] dnf-json: shorten CacheState loading and saving method names CacheState.load_cache_state_from_disk() is long and redundant. CacheState.store_on_disk() is fine (and load_from_disk() would also be fine) but in the absence of any other store/load sources, the from_disk() part is also unnecessary. CacheState.store() and CacheState.load() should be enough. --- dnf-json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dnf-json b/dnf-json index a3b05d2c2..6f16b8c88 100755 --- a/dnf-json +++ b/dnf-json @@ -77,14 +77,14 @@ class CacheState(): shutil.rmtree(folder) @staticmethod - def load_cache_state_from_disk(cache_dir): + def load(cache_dir): try: with open(os.path.join(cache_dir,"cache_state.pkl"), "rb") as inp: return pickle.load(inp) except FileNotFoundError: return CacheState(cache_dir, timedelta(hours=24)) - def store_on_disk(self): + def store(self): with open(os.path.join(self.cache_dir, "cache_state.pkl"), "wb") as outp: return pickle.dump(self, outp) @@ -324,7 +324,7 @@ class DnfJsonRequestHandler(BaseHTTPRequestHandler): if not self.cache_dir: self.response_failure({ "kind": "Error", "reason": "No cache dir set" }) - cache_state = CacheState.load_cache_state_from_disk(self.cache_dir) + cache_state = CacheState.load(self.cache_dir) with tempfile.TemporaryDirectory() as persistdir: try: @@ -370,7 +370,7 @@ class DnfJsonRequestHandler(BaseHTTPRequestHandler): for cache_folder in self.init_cache_folder_list(repos): cache_state.update_used(cache_folder) cache_state.clean_unused() - cache_state.store_on_disk() + cache_state.store() log.info("Starting the dnf-json server")