1
0
Fork 0

Undo typing changes, remote Python is too old

This commit is contained in:
Luca Beltrame 2021-01-02 10:27:29 +01:00
parent 0921c0f2f7
commit dbe9937560
Signed by: einar
GPG key ID: 4707F46E9EC72DEC

View file

@ -8,7 +8,6 @@ import json
from pathlib import Path from pathlib import Path
import pickle import pickle
from urllib.parse import urlencode from urllib.parse import urlencode
from typing import Dict
import git import git
import requests import requests
@ -51,13 +50,21 @@ class GitHashCache:
with open(self.cache, "rb") as handle: with open(self.cache, "rb") as handle:
self._data = pickle.load(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): def to_json(self):
with Path(self.cache).with_suffix(".json").open("w") as handle: with Path(self.cache).with_suffix(".json").open("w") as handle:
json.dump(self._data, handle, indent=4) json.dump(self._data, handle, indent=4)
def project_exists(project: str) -> bool: def project_exists(project):
project_name = urlencode(project) project_name = urlencode(project)
request = requests.get(API_URL + project_name) request = requests.get(API_URL + project_name)
@ -67,7 +74,7 @@ def project_exists(project: str) -> bool:
return False return False
def lsremote(url: str) -> Dict[str]: def lsremote(url):
remote_refs = {} remote_refs = {}
gitcmd = git.cmd.Git() gitcmd = git.cmd.Git()
@ -78,12 +85,12 @@ def lsremote(url: str) -> Dict[str]:
return remote_refs 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) refs = "refs/heads/{}".format(branch)
return lsremote(url)[refs] 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 = "osc service remoterun {0} {1}"
cmd = cmd.format(repository, package_name) cmd = cmd.format(repository, package_name)
@ -101,9 +108,9 @@ def run_osc(repository: str, package_name: str) -> bool:
return True return True
def update_package(hash_data: GitHashCache, package_name: str, def update_package(hash_data, package_name,
remote_name: str, obs_repository: str, remote_name, obs_repository,
branch: str): branch):
repo_name = "https://invent.kde.org/{}".format(remote_name) 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() 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 = GitHashCache(cache_file)
hash_data.load() hash_data.load()