feat: add self-update functionality

- add new configuration option `self-update` to enable automatic updates
- implement `do_selfupdate` function in `lib/helper.py` to perform the update
- call `do_selfupdate` in `dc-ops` if `self-update` is enabled

🤖
This commit is contained in:
Sebastian Mark 2023-12-21 18:38:03 +01:00
parent a2e5852159
commit 130b26ba5f
3 changed files with 24 additions and 1 deletions

View file

@ -1,9 +1,26 @@
import logging as log
import subprocess
import sys
from pathlib import Path
import git
def do_selfupdate():
"""perform git pull on script's base directory"""
repo_path = Path(sys.argv[0]).parent.absolute()
repo = git.Repo(repo_path)
try:
pull_res = repo.remotes.origin.pull()[0]
except git.exc.GitCommandError as e:
log.error(str(e))
return
if pull_res.old_commit:
log.info("selfupdate: successfully updated myself - exiting")
sys.exit(0)
log.info("selfupdate: no updates found for myself")
def run_subprocess(command: str, workdir: str) -> bool:
"""execute subprocess and print output