parent
38c93b1ad5
commit
22751b7d95
2 changed files with 18 additions and 27 deletions
|
|
@ -17,7 +17,6 @@
|
||||||
"""Script for taking pre/post snapshots; run from pacman hooks."""
|
"""Script for taking pre/post snapshots; run from pacman hooks."""
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from collections import namedtuple
|
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -60,12 +59,6 @@ class SnapperCmd:
|
||||||
return " ".join(self.cmd)
|
return " ".join(self.cmd)
|
||||||
|
|
||||||
|
|
||||||
ProcessedConfig = namedtuple(
|
|
||||||
"ProcessedConfig",
|
|
||||||
["description", "cleanup_algorithm", "userdata", "snapshot"]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigProcessor:
|
class ConfigProcessor:
|
||||||
|
|
||||||
def __init__(self, ini_file, snapshot_type, parent_cmd=None, packages=None):
|
def __init__(self, ini_file, snapshot_type, parent_cmd=None, packages=None):
|
||||||
|
|
@ -126,12 +119,12 @@ class ConfigProcessor:
|
||||||
def __call__(self, section):
|
def __call__(self, section):
|
||||||
if section not in self.config:
|
if section not in self.config:
|
||||||
self.config.add_section(section)
|
self.config.add_section(section)
|
||||||
return ProcessedConfig(
|
return {
|
||||||
self.get_description(section),
|
"description": self.get_description(section),
|
||||||
self.get_cleanup_algorithm(section),
|
"cleanup_algorithm": self.get_cleanup_algorithm(section),
|
||||||
self.get_userdata(section),
|
"userdata": self.get_userdata(section),
|
||||||
self.config.getboolean(section, "snapshot")
|
"snapshot": self.config.getboolean(section, "snapshot")
|
||||||
)
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_snapper_configs(conf_file):
|
def get_snapper_configs(conf_file):
|
||||||
|
|
@ -188,12 +181,12 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
for snapper_config in snapper_configs:
|
for snapper_config in snapper_configs:
|
||||||
|
|
||||||
processed_config = config_processor(snapper_config)
|
data = config_processor(snapper_config)
|
||||||
if processed_config["snapshot"]:
|
if data["snapshot"]:
|
||||||
prefile = tmpdir / f"snap-pac-pre_{snapper_config}"
|
prefile = tmpdir / f"snap-pac-pre_{snapper_config}"
|
||||||
pre_number = get_pre_number(snapshot_type, prefile)
|
pre_number = get_pre_number(snapshot_type, prefile)
|
||||||
snapper_cmd = SnapperCmd(snapper_config, snapshot_type, processed_config["cleanup_algorithm"],
|
snapper_cmd = SnapperCmd(snapper_config, snapshot_type, data["cleanup_algorithm"],
|
||||||
processed_config["description"], chroot, pre_number, processed_config["userdata"])
|
data["description"], chroot, pre_number, data["userdata"])
|
||||||
num = snapper_cmd()
|
num = snapper_cmd()
|
||||||
logging.info(f"==> {snapper_config}: {num}")
|
logging.info(f"==> {snapper_config}: {num}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,7 @@ import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from scripts.snap_pac import (
|
from scripts.snap_pac import SnapperCmd, ConfigProcessor, check_skip, get_pre_number, get_snapper_configs
|
||||||
SnapperCmd, ConfigProcessor, check_skip, get_pre_number, get_snapper_configs,
|
|
||||||
ProcessedConfig
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
@ -68,27 +65,28 @@ def test_skip_snap_pac():
|
||||||
@pytest.mark.parametrize("section, command, packages, snapshot_type, result", [
|
@pytest.mark.parametrize("section, command, packages, snapshot_type, result", [
|
||||||
(
|
(
|
||||||
"root", "foo", ["bar"], "pre",
|
"root", "foo", ["bar"], "pre",
|
||||||
ProcessedConfig("foo", "number", "", True)
|
{"description": "foo", "cleanup_algorithm": "number", "userdata": "", "snapshot": True}
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"root", "pacman -Syu", [], "pre",
|
"root", "pacman -Syu", [], "pre",
|
||||||
ProcessedConfig("pacman -Syu", "number", "important=yes", True)
|
{"description": "pacman -Syu", "cleanup_algorithm": "number", "userdata": "important=yes", "snapshot": True}
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"mail", "pacman -Syu", [], "pre",
|
"mail", "pacman -Syu", [], "pre",
|
||||||
ProcessedConfig("pacman -Syu", "number", "", False)
|
{"description": "pacman -Syu", "cleanup_algorithm": "number", "userdata": "", "snapshot": False}
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"home", "pacman -Syu", [], "pre",
|
"home", "pacman -Syu", [], "pre",
|
||||||
ProcessedConfig("pac", "number", "foo=bar,requestid=42", True)
|
{"description": "pac", "cleanup_algorithm": "number", "userdata": "foo=bar,requestid=42", "snapshot": True}
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"home", "pacman -Syu", [], "post",
|
"home", "pacman -Syu", [], "post",
|
||||||
ProcessedConfig("a r", "number", "foo=bar,requestid=42", True)
|
{"description": "a r", "cleanup_algorithm": "number", "userdata": "foo=bar,requestid=42", "snapshot": True}
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"myconfig", "pacman -S linux", ["linux"], "post",
|
"myconfig", "pacman -S linux", ["linux"], "post",
|
||||||
ProcessedConfig("linux", "timeline", "foo=bar,important=yes,requestid=42", True)
|
{"description": "linux", "cleanup_algorithm": "timeline",
|
||||||
|
"userdata": "foo=bar,important=yes,requestid=42", "snapshot": True}
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
def test_config_processor(section, command, packages, snapshot_type, result):
|
def test_config_processor(section, command, packages, snapshot_type, result):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue