diff --git a/update_unstable.py b/update_unstable.py index 67d077e..5058b47 100755 --- a/update_unstable.py +++ b/update_unstable.py @@ -6,7 +6,6 @@ import argparse import logging import json from pathlib import Path -import pickle from urllib.parse import urlencode import git @@ -37,8 +36,8 @@ class GitHashCache: def save(self): logging.debug("Saving pickled data") - with open(self.cache, "wb") as handle: - pickle.dump(self._data, handle, pickle.HIGHEST_PROTOCOL) + with open(self.cache, "w") as handle: + json.dump(self._data, handle, indent=4) def load(self): @@ -46,23 +45,9 @@ class GitHashCache: logging.debug("File cache not found, not loading") return - logging.debug("Saving pickled data") - with open(self.cache, "rb") as handle: - self._data = pickle.load(handle) - - def load_json(self): - if not Path(self.cache).with_suffix(".json").exists(): - logging.debug("File cache not found, not loading") - return - - with Path(self.cache).with_suffix(".json").open() as handle: + with open(self.cache) as handle: self._data = json.load(handle) - def to_json(self): - - with Path(self.cache).with_suffix(".json").open("w") as handle: - json.dump(self._data, handle, indent=4) - def project_exists(project): project_name = urlencode(project) @@ -135,7 +120,6 @@ def update_package(hash_data, package_name, if run_osc(obs_repository, package_name): hash_data[obs_repository][remote_name] = remote_hash hash_data.save() - hash_data.to_json() def update_packages(cache_file, repo_mapping_file): @@ -170,6 +154,9 @@ def update_packages(cache_file, repo_mapping_file): def main(): parser = argparse.ArgumentParser() + parser.add_argument( + "--cache-file", help="Location of the cache file", + default=Path.home() / ".local/share/obs_repo_cache.json") parser.add_argument("mapping_file", help="KDE:OBS repository mapping file") parser.add_argument("--debug", help="Show debugging output", action="store_true") @@ -180,8 +167,7 @@ def main(): logging.basicConfig(format='%(levelname)s - %(message)s', level=level) - cache_file = Path.home() / ".local/share/obs_repo_cache.cache" - cache_file = str(cache_file) + cache_file = options.cache_file update_packages(cache_file, options.mapping_file) logging.info("Complete")