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."""
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from collections import namedtuple
|
||||
from configparser import ConfigParser
|
||||
import json
|
||||
import logging
|
||||
|
|
@ -60,12 +59,6 @@ class SnapperCmd:
|
|||
return " ".join(self.cmd)
|
||||
|
||||
|
||||
ProcessedConfig = namedtuple(
|
||||
"ProcessedConfig",
|
||||
["description", "cleanup_algorithm", "userdata", "snapshot"]
|
||||
)
|
||||
|
||||
|
||||
class ConfigProcessor:
|
||||
|
||||
def __init__(self, ini_file, snapshot_type, parent_cmd=None, packages=None):
|
||||
|
|
@ -126,12 +119,12 @@ class ConfigProcessor:
|
|||
def __call__(self, section):
|
||||
if section not in self.config:
|
||||
self.config.add_section(section)
|
||||
return ProcessedConfig(
|
||||
self.get_description(section),
|
||||
self.get_cleanup_algorithm(section),
|
||||
self.get_userdata(section),
|
||||
self.config.getboolean(section, "snapshot")
|
||||
)
|
||||
return {
|
||||
"description": self.get_description(section),
|
||||
"cleanup_algorithm": self.get_cleanup_algorithm(section),
|
||||
"userdata": self.get_userdata(section),
|
||||
"snapshot": self.config.getboolean(section, "snapshot")
|
||||
}
|
||||
|
||||
|
||||
def get_snapper_configs(conf_file):
|
||||
|
|
@ -188,12 +181,12 @@ if __name__ == "__main__":
|
|||
|
||||
for snapper_config in snapper_configs:
|
||||
|
||||
processed_config = config_processor(snapper_config)
|
||||
if processed_config["snapshot"]:
|
||||
data = config_processor(snapper_config)
|
||||
if data["snapshot"]:
|
||||
prefile = tmpdir / f"snap-pac-pre_{snapper_config}"
|
||||
pre_number = get_pre_number(snapshot_type, prefile)
|
||||
snapper_cmd = SnapperCmd(snapper_config, snapshot_type, processed_config["cleanup_algorithm"],
|
||||
processed_config["description"], chroot, pre_number, processed_config["userdata"])
|
||||
snapper_cmd = SnapperCmd(snapper_config, snapshot_type, data["cleanup_algorithm"],
|
||||
data["description"], chroot, pre_number, data["userdata"])
|
||||
num = snapper_cmd()
|
||||
logging.info(f"==> {snapper_config}: {num}")
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,7 @@ import os
|
|||
|
||||
import pytest
|
||||
|
||||
from scripts.snap_pac import (
|
||||
SnapperCmd, ConfigProcessor, check_skip, get_pre_number, get_snapper_configs,
|
||||
ProcessedConfig
|
||||
)
|
||||
from scripts.snap_pac import SnapperCmd, ConfigProcessor, check_skip, get_pre_number, get_snapper_configs
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -68,27 +65,28 @@ def test_skip_snap_pac():
|
|||
@pytest.mark.parametrize("section, command, packages, snapshot_type, result", [
|
||||
(
|
||||
"root", "foo", ["bar"], "pre",
|
||||
ProcessedConfig("foo", "number", "", True)
|
||||
{"description": "foo", "cleanup_algorithm": "number", "userdata": "", "snapshot": True}
|
||||
),
|
||||
(
|
||||
"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",
|
||||
ProcessedConfig("pacman -Syu", "number", "", False)
|
||||
{"description": "pacman -Syu", "cleanup_algorithm": "number", "userdata": "", "snapshot": False}
|
||||
),
|
||||
(
|
||||
"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",
|
||||
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",
|
||||
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):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue