Browse Source

backup: fix mypy-detected errors

master
Jim Paris 7 months ago
parent
commit
756dbe1898
1 changed files with 10 additions and 10 deletions
  1. +10
    -10
      backup.py

+ 10
- 10
backup.py View File

@@ -251,11 +251,12 @@ def main(argv: list[str]):

args = parser.parse_args()
config = Config(args.config)
backup = Backup(config, args.dry_run)

# Parse variables from vars.sh
hostname = os.uname().nodename
borg = str(base / "borg.sh")
notify = str(base / "notify.sh")
borg_sh = str(base / "borg.sh")
notify_sh = str(base / "notify.sh")
try:
with open(args.vars) as f:
for line in f:
@@ -267,14 +268,13 @@ def main(argv: list[str]):
if var == "HOSTNAME":
hostname = value
if var == "BORG":
borg = value
borg_sh = value
if var == "BORG_DIR":
notify = pathlib.Path(value) / "notify.sh"
notify_sh = str(pathlib.Path(value) / "notify.sh")
except Exception as e:
self.log('W', f"failed to parse variables from {args.vars}: {str(e)}")
backup.log('W', f"failed to parse variables from {args.vars}: {str(e)}")

# Run backup
backup = Backup(config, args.dry_run)
captured_output: list[bytes] = []

if args.dry_run:
@@ -285,7 +285,7 @@ def main(argv: list[str]):
backup.run(out)
sys.stdout.flush()
else:
borg = subprocess.Popen([borg,
borg = subprocess.Popen([borg_sh,
"create",
"--verbose",
"--progress",
@@ -405,12 +405,12 @@ def main(argv: list[str]):
if errmsg and warnmsg:
summary = f"{errmsg}, {warnmsg}"
elif errors:
summary = errmsg
summary = errmsg or ""
else:
summary = warnmsg
summary = warnmsg or ""

# Call notify.sh
res = subprocess.run([notify, summary, email], input=body_text)
res = subprocess.run([notify_sh, summary, email], input=body_text)
if res.returncode != 0:
backup.log('E', f"failed to send notification")
errors += 1


Loading…
Cancel
Save