diff --git a/hooks/10_snap-pac-removal.hook b/hooks/10_snap-pac-removal.hook deleted file mode 100644 index 6c8f921..0000000 --- a/hooks/10_snap-pac-removal.hook +++ /dev/null @@ -1,28 +0,0 @@ -# snap-pac -# https://github.com/wesbarnett/snap-pac -# Copyright (C) 2016, 2017, 2018 James W. Barnett - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -[Trigger] -Operation = Remove -Type = Package -Target = snap-pac - -[Action] -Description = You are removing snap-pac. No post transaction snapshots will be taken. -Depends = snap-pac -When = PreTransaction -Exec = /usr/bin/bash -c "rm -f /tmp/snap-pac-pre_*" diff --git a/hooks/zz_snap-pac-install.hook b/hooks/zz_snap-pac-install.hook deleted file mode 100644 index 4beeb68..0000000 --- a/hooks/zz_snap-pac-install.hook +++ /dev/null @@ -1,28 +0,0 @@ -# snap-pac -# https://github.com/wesbarnett/snap-pac -# Copyright (C) 2016, 2017, 2018 James W. Barnett - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -[Trigger] -Operation = Install -Type = Package -Target = snap-pac - -[Action] -Description = You are installing snap-pac, so no post transaction snapshots will be taken. -Depends = snap-pac -When = PostTransaction -Exec = /usr/bin/true diff --git a/hooks/zy_snapper-post.hook b/hooks/zz_snapper_post.hook similarity index 100% rename from hooks/zy_snapper-post.hook rename to hooks/zz_snapper_post.hook diff --git a/scripts/snap_pac.py b/scripts/snap_pac.py index c054de8..77dbcc4 100755 --- a/scripts/snap_pac.py +++ b/scripts/snap_pac.py @@ -38,7 +38,6 @@ class SnapperCmd: self.cmd.append("--no-dbus") self.cmd.extend([ f"--config {config} create", - f"--type {snapshot_type}", f"--cleanup-algorithm {cleanup_algorithm}", "--print-number" ]) @@ -50,7 +49,11 @@ class SnapperCmd: if pre_number is not None: self.cmd.append(f"--pre-number {pre_number}") else: - raise ValueError("snapshot type specified as 'post' but no pre snapshot number passed.") + logging.debug("snapshot type specified as 'post' but no pre snapshot number, " + "so setting snapshot type to 'single'. If installing " + "snap-pac this is normal.") + snapshot_type = "single" + self.cmd.append(f"--type {snapshot_type}") def __call__(self): return os.popen(self.__str__()).read().rstrip("\n") @@ -148,7 +151,9 @@ class Prefile: try: pre_number = self.file.read_text() except FileNotFoundError: - raise FileNotFoundError(f"prefile {self.file} not found. Ensure you have run the pre snapshot first.") + pre_number = None + logging.debug(f"prefile {self.file} not found. Ensure you have run the pre snapshot first. " + "If installing snap-pac this is normal.") else: self.file.unlink() return pre_number diff --git a/tests/test_script.py b/tests/test_script.py index f36dd8e..953f941 100644 --- a/tests/test_script.py +++ b/tests/test_script.py @@ -10,27 +10,32 @@ from scripts.snap_pac import check_skip, ConfigProcessor, get_snapper_configs, P @pytest.mark.parametrize("snapper_cmd, actual_cmd", [ ( SnapperCmd("root", "pre", "number", "foo"), - "snapper --config root create --type pre --cleanup-algorithm number --print-number --description \"foo\"" + "snapper --config root create --cleanup-algorithm number --print-number --description \"foo\" --type pre" ), ( SnapperCmd("root", "post", "number", "bar", False, 1234), - "snapper --config root create --type post --cleanup-algorithm number --print-number" - " --description \"bar\" --pre-number 1234" + "snapper --config root create --cleanup-algorithm number --print-number" + " --description \"bar\" --pre-number 1234 --type post" ), ( SnapperCmd("root", "post", "number", "bar", True, 1234), - "snapper --no-dbus --config root create --type post --cleanup-algorithm number --print-number" - " --description \"bar\" --pre-number 1234" + "snapper --no-dbus --config root create --cleanup-algorithm number --print-number" + " --description \"bar\" --pre-number 1234 --type post" ), ( SnapperCmd("root", "post", "number", "bar", False, 1234, "important=yes"), - "snapper --config root create --type post --cleanup-algorithm number --print-number" - " --description \"bar\" --userdata \"important=yes\" --pre-number 1234" + "snapper --config root create --cleanup-algorithm number --print-number" + " --description \"bar\" --userdata \"important=yes\" --pre-number 1234 --type post" ), ( SnapperCmd("root", "post", "number", "bar", False, 1234, "foo=bar,important=yes"), - "snapper --config root create --type post --cleanup-algorithm number --print-number" - " --description \"bar\" --userdata \"foo=bar,important=yes\" --pre-number 1234" + "snapper --config root create --cleanup-algorithm number --print-number" + " --description \"bar\" --userdata \"foo=bar,important=yes\" --pre-number 1234 --type post" + ), + ( + SnapperCmd("root", "post", "number", "bar", False, None, "foo=bar,important=yes"), + "snapper --config root create --cleanup-algorithm number --print-number" + " --description \"bar\" --userdata \"foo=bar,important=yes\" --type single" ) ]) def test_snapper_cmd(snapper_cmd, actual_cmd): @@ -114,5 +119,4 @@ def test_prefile_read(): def test_no_prefile(): prefile = Prefile("foo-pre-file-not-found", "post") - with pytest.raises(FileNotFoundError): - prefile.read() + assert prefile.read() is None