Various lint and style fixes
This commit is contained in:
parent
df1019dd4b
commit
e9ce07b217
1 changed files with 23 additions and 22 deletions
|
@ -8,6 +8,7 @@ import json
|
|||
from pathlib import Path
|
||||
import pickle
|
||||
from urllib.parse import urlencode
|
||||
from typing import Dict
|
||||
|
||||
import git
|
||||
import requests
|
||||
|
@ -57,7 +58,7 @@ class GitHashCache:
|
|||
json.dump(self._data, handle, indent=4)
|
||||
|
||||
|
||||
def project_exists(project):
|
||||
def project_exists(project: str) -> bool:
|
||||
project_name = urlencode(project)
|
||||
request = requests.get(API_URL + project_name)
|
||||
|
||||
|
@ -67,48 +68,48 @@ def project_exists(project):
|
|||
return False
|
||||
|
||||
|
||||
def lsremote(url):
|
||||
def lsremote(url: str) -> Dict[str]:
|
||||
|
||||
remote_refs = {}
|
||||
g = git.cmd.Git()
|
||||
for ref in g.ls_remote(url).split('\n'):
|
||||
gitcmd = git.cmd.Git()
|
||||
for ref in gitcmd.ls_remote(url).split('\n'):
|
||||
hash_ref_list = ref.split('\t')
|
||||
remote_refs[hash_ref_list[1]] = hash_ref_list[0]
|
||||
|
||||
return remote_refs
|
||||
|
||||
|
||||
def get_remote_hash(url, branch="master"):
|
||||
def get_remote_hash(url: str, branch: str = "master") -> str:
|
||||
refs = "refs/heads/{}".format(branch)
|
||||
return lsremote(url)[refs]
|
||||
|
||||
|
||||
def run_osc(repository, package_name):
|
||||
def run_osc(repository: str, package_name: str) -> bool:
|
||||
|
||||
cmd = "osc service remoterun {0} {1}"
|
||||
cmd = cmd.format(repository, package_name)
|
||||
|
||||
logging.debug("Running {}".format(cmd))
|
||||
logging.info("Updating package {0}".format(package_name))
|
||||
logging.debug("Running %s", cmd)
|
||||
logging.info("Updating package %s", package_name)
|
||||
|
||||
pid = sarge.run(cmd)
|
||||
|
||||
if pid.returncode != 0:
|
||||
logging.error("Error during service run, package {}".format(
|
||||
package_name))
|
||||
logging.error("Error during service run, package %s", package_name)
|
||||
return False
|
||||
|
||||
logging.debug("Package {} complete".format(package_name))
|
||||
logging.debug("Package %s complete", package_name)
|
||||
return True
|
||||
|
||||
|
||||
def update_package(hash_data, package_name, remote_name, obs_repository,
|
||||
branch):
|
||||
def update_package(hash_data: GitHashCache, package_name: str,
|
||||
remote_name: str, obs_repository: str,
|
||||
branch: str):
|
||||
|
||||
repo_name = "https://invent.kde.org/{}".format(remote_name)
|
||||
|
||||
if not project_exists(remote_name):
|
||||
logging.warn("Repository {} not found, skipping".format(remote_name))
|
||||
logging.warning("Repository %s not found, skipping", remote_name)
|
||||
return
|
||||
|
||||
remote_hash = get_remote_hash(repo_name, branch)
|
||||
|
@ -120,9 +121,8 @@ def update_package(hash_data, package_name, remote_name, obs_repository,
|
|||
|
||||
current_hash = hash_data[obs_repository].get(remote_name, "")
|
||||
|
||||
logging.debug("Package {}, theirs {}, ours {}".format(remote_name,
|
||||
remote_hash,
|
||||
current_hash))
|
||||
logging.debug("Package %s, theirs %s, ours %s",
|
||||
remote_name, remote_hash, current_hash)
|
||||
|
||||
if remote_hash != current_hash:
|
||||
logging.debug("Hash doesn't match, updating")
|
||||
|
@ -132,7 +132,7 @@ def update_package(hash_data, package_name, remote_name, obs_repository,
|
|||
hash_data.to_json()
|
||||
|
||||
|
||||
def update_packages(cache_file, repo_mapping_file):
|
||||
def update_packages(cache_file: str, repo_mapping_file: str):
|
||||
|
||||
hash_data = GitHashCache(cache_file)
|
||||
hash_data.load()
|
||||
|
@ -143,16 +143,16 @@ def update_packages(cache_file, repo_mapping_file):
|
|||
|
||||
for obs_repository, branch_data in repo_data.items():
|
||||
|
||||
logging.info("Updating packages for {}".format(obs_repository))
|
||||
logging.info("Updating packages for %s", obs_repository)
|
||||
|
||||
for package in branch_data:
|
||||
kde_name = package["kde"]
|
||||
obs_name = package["obs"]
|
||||
branch = package["branch"]
|
||||
package_name = Path(kde_name).name
|
||||
logging.debug("Updating package {} ({})".format(package_name,
|
||||
obs_name))
|
||||
logging.debug("Using branch {}".format(branch))
|
||||
logging.debug("Updating package %s (%s)",
|
||||
package_name, obs_name)
|
||||
logging.debug("Using branch %s", branch)
|
||||
update_package(hash_data, obs_name, kde_name, obs_repository,
|
||||
branch)
|
||||
|
||||
|
@ -180,5 +180,6 @@ def main():
|
|||
update_packages(cache_file, options.mapping_file)
|
||||
logging.info("Complete")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Add table
Reference in a new issue