chore: fix pylint complains

This commit is contained in:
Sebastian Mark 2024-06-10 12:09:05 +02:00
parent 3d52b21442
commit 260ab2ba22
2 changed files with 14 additions and 8 deletions

10
dc-ops
View file

@ -5,6 +5,8 @@
# CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de) # CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de)
# for civil use only # for civil use only
# pylint: disable=missing-module-docstring,invalid-name
import argparse import argparse
import logging as log import logging as log
from pathlib import Path from pathlib import Path
@ -15,12 +17,12 @@ from lib.helper import run_subprocess, update_git_repo, do_selfupdate
# read config file # read config file
configfile = Path(__file__).with_name("config.yml") configfile = Path(__file__).with_name("config.yml")
with configfile.open("r") as f: with configfile.open("r", encoding="utf-8") as f:
cfg = yaml.safe_load(f.read()) cfg = yaml.safe_load(f.read())
# fmt: off # fmt: off
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--ignore-git-status", action="store_true", help="continue even if there are no new commits") # noqa parser.add_argument("--ignore-git-status", action="store_true", help="continue even if there are no new commits")
parser.add_argument("--loglevel", help="set loglevel (overrides config file)") parser.add_argument("--loglevel", help="set loglevel (overrides config file)")
args = parser.parse_args() args = parser.parse_args()
# fmt: on # fmt: on
@ -47,7 +49,7 @@ for stack in cfg["stacks"]:
# header # header
stackdir = stack["dir"] stackdir = stack["dir"]
log.info(f"processing: {stackdir}") log.info("processing: %s", stackdir)
# update repo and check for new commits # update repo and check for new commits
if not update_git_repo(stackdir, args.ignore_git_status): if not update_git_repo(stackdir, args.ignore_git_status):
@ -63,7 +65,7 @@ for stack in cfg["stacks"]:
# (or just for the directory if no compose-file defined) # (or just for the directory if no compose-file defined)
composefiles = stack.get("compose-files", ["docker-compose.yml"]) composefiles = stack.get("compose-files", ["docker-compose.yml"])
for composefile in composefiles: for composefile in composefiles:
log.info(f"-> bringing up {composefile}") log.info("-> bringing up %s", composefile)
if not run_subprocess( if not run_subprocess(
f"docker compose --file {composefile} up --detach {composeopts}", f"docker compose --file {composefile} up --detach {composeopts}",
stackdir, stackdir,

View file

@ -1,3 +1,5 @@
# pylint: disable=missing-module-docstring
import logging as log import logging as log
import subprocess import subprocess
import sys import sys
@ -32,7 +34,9 @@ def run_subprocess(command: str, workdir: str) -> bool:
bool: False if subprocess fails bool: False if subprocess fails
""" """
try: try:
log.debug(subprocess.run(command.split(" "), cwd=workdir, text=True)) log.debug(
subprocess.run(command.split(" "), cwd=workdir, text=True, check=False)
)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
return False return False
@ -62,7 +66,7 @@ def update_git_repo(repo_path: str, ignore_git_status: bool) -> bool:
try: try:
fetch_res = repo.remotes.origin.fetch()[0] fetch_res = repo.remotes.origin.fetch()[0]
except git.exc.GitCommandError as e: except git.exc.GitCommandError as e:
log.error("-> " + str(e)) log.error("-> %s ", str(e))
return False return False
# check for new commits # check for new commits
@ -72,9 +76,9 @@ def update_git_repo(repo_path: str, ignore_git_status: bool) -> bool:
# pull remote changes to local branch # pull remote changes to local branch
try: try:
log.info("-> " + repo.git.pull()) log.info("-> %s", repo.git.pull())
except git.exc.GitCommandError as e: except git.exc.GitCommandError as e:
log.error("-> " + str(e)) log.error("-> %s", str(e))
return False return False
return True return True