simplify paths with Pathlib
This commit is contained in:
parent
de9ef06efa
commit
1716654236
1 changed files with 5 additions and 10 deletions
|
|
@ -19,6 +19,7 @@
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
import logging
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
@ -91,20 +92,14 @@ def get_pre_number(snapshot_type, prefile):
|
||||||
pre_number = None
|
pre_number = None
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
with open(prefile, "r") as f:
|
pre_number = prefile.read_text()
|
||||||
pre_number = f.read().rstrip("\n")
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise FileNotFoundError(f"prefile {prefile} not found. Ensure you have run the pre snapshot first.")
|
raise FileNotFoundError(f"prefile {prefile} not found. Ensure you have run the pre snapshot first.")
|
||||||
else:
|
else:
|
||||||
os.remove(prefile)
|
prefile.unlink()
|
||||||
return pre_number
|
return pre_number
|
||||||
|
|
||||||
|
|
||||||
def write_pre_number(num, prefile):
|
|
||||||
with open(prefile, "w") as f:
|
|
||||||
f.write(num)
|
|
||||||
|
|
||||||
|
|
||||||
def main(snap_pac_ini, snapper_conf_file, args):
|
def main(snap_pac_ini, snapper_conf_file, args):
|
||||||
|
|
||||||
if os.getenv("SNAP_PAC_SKIP", "n").lower() in ["y", "yes", "true", "1"]:
|
if os.getenv("SNAP_PAC_SKIP", "n").lower() in ["y", "yes", "true", "1"]:
|
||||||
|
|
@ -125,7 +120,7 @@ def main(snap_pac_ini, snapper_conf_file, args):
|
||||||
logging.debug(f"{snapper_config = }")
|
logging.debug(f"{snapper_config = }")
|
||||||
|
|
||||||
if config.getboolean(snapper_config, "snapshot"):
|
if config.getboolean(snapper_config, "snapshot"):
|
||||||
prefile = f"/tmp/snap-pac-pre_{snapper_config}"
|
prefile = "/tmp" / Path(f"snap-pac-pre_{snapper_config}")
|
||||||
logging.debug(f"{prefile = }")
|
logging.debug(f"{prefile = }")
|
||||||
|
|
||||||
cleanup_algorithm = config.get(snapper_config, "cleanup_algorithm")
|
cleanup_algorithm = config.get(snapper_config, "cleanup_algorithm")
|
||||||
|
|
@ -138,7 +133,7 @@ def main(snap_pac_ini, snapper_conf_file, args):
|
||||||
logging.info(f"==> {snapper_config}: {num}")
|
logging.info(f"==> {snapper_config}: {num}")
|
||||||
|
|
||||||
if args.type == "pre":
|
if args.type == "pre":
|
||||||
write_pre_number(num, prefile)
|
prefile.write_text(num)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue