defaults for ConfigProcessor

This commit is contained in:
Wes Barnett 2021-03-26 21:29:23 -04:00
parent 73f683533f
commit 7734706157
No known key found for this signature in database
GPG key ID: 1070BCC98C18BD66
2 changed files with 13 additions and 7 deletions

View file

@ -61,11 +61,19 @@ class SnapperCmd:
class ConfigProcessor:
def __init__(self, ini_file, parent_cmd, packages, snapshot_type):
def __init__(self, ini_file, snapshot_type, parent_cmd=None, packages=None):
"""Set up defaults for snap-pac configuration."""
if parent_cmd is None:
self.parent_cmd = os.popen(f"ps -p {os.getppid()} -o args=").read().strip()
else:
self.parent_cmd = parent_cmd
if packages is None:
self.packages = [line.rstrip("\n") for line in sys.stdin]
else:
self.packages = packages
self.snapshot_type = snapshot_type
self.config = ConfigParser()
@ -166,9 +174,7 @@ if __name__ == "__main__":
snapper_conf_file = args.snapper_conf_file
snap_pac_ini = args.snap_pac_ini
parent_cmd = os.popen(f"ps -p {os.getppid()} -o args=").read().strip()
packages = [line.rstrip("\n") for line in sys.stdin]
config_processor = ConfigProcessor(snap_pac_ini, parent_cmd, packages, snapshot_type)
config_processor = ConfigProcessor(snap_pac_ini, snapshot_type)
snapper_configs = get_snapper_configs(snapper_conf_file)
chroot = os.stat("/") != os.stat("/proc/1/root/.")
tmpdir = Path(tempfile.gettempdir())

View file

@ -104,7 +104,7 @@ def test_config_processor(section, command, packages, snapshot_type, result):
f.write("important_packages = [\"linux\", \"linux-lts\"]\n")
f.write("userdata = [\"foo=bar\", \"requestid=42\"]\n")
name = f.name
config_processor = ConfigProcessor(name, command, packages, snapshot_type)
config_processor = ConfigProcessor(name, snapshot_type, command, packages)
assert config_processor(section) == result