diff --git a/update_unstable.py b/update_unstable.py index 5f5a8df..67d077e 100755 --- a/update_unstable.py +++ b/update_unstable.py @@ -8,7 +8,6 @@ import json from pathlib import Path import pickle from urllib.parse import urlencode -from typing import Dict import git import requests @@ -51,13 +50,21 @@ class GitHashCache: 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: + 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: str) -> bool: +def project_exists(project): project_name = urlencode(project) request = requests.get(API_URL + project_name) @@ -67,7 +74,7 @@ def project_exists(project: str) -> bool: return False -def lsremote(url: str) -> Dict[str]: +def lsremote(url): remote_refs = {} gitcmd = git.cmd.Git() @@ -78,12 +85,12 @@ def lsremote(url: str) -> Dict[str]: return remote_refs -def get_remote_hash(url: str, branch: str = "master") -> str: +def get_remote_hash(url, branch="master"): refs = "refs/heads/{}".format(branch) return lsremote(url)[refs] -def run_osc(repository: str, package_name: str) -> bool: +def run_osc(repository, package_name): cmd = "osc service remoterun {0} {1}" cmd = cmd.format(repository, package_name) @@ -101,9 +108,9 @@ def run_osc(repository: str, package_name: str) -> bool: return True -def update_package(hash_data: GitHashCache, package_name: str, - remote_name: str, obs_repository: str, - branch: str): +def update_package(hash_data, package_name, + remote_name, obs_repository, + branch): repo_name = "https://invent.kde.org/{}".format(remote_name) @@ -131,7 +138,7 @@ def update_package(hash_data: GitHashCache, package_name: str, hash_data.to_json() -def update_packages(cache_file: str, repo_mapping_file: str): +def update_packages(cache_file, repo_mapping_file): hash_data = GitHashCache(cache_file) hash_data.load()