From 66ce230f401049c5964150700db3e265b8f29ae5 Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Mon, 18 Mar 2019 05:29:35 -0700 Subject: [PATCH] Add pkg_dir attribute, clean up code, and update respective tests --- rbackup/hierarchy/snapshot.py | 46 +++++++++++++++++++---------------- tests/test_snapshot.py | 10 ++++++-- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/rbackup/hierarchy/snapshot.py b/rbackup/hierarchy/snapshot.py index 92febeb..1c71f47 100644 --- a/rbackup/hierarchy/snapshot.py +++ b/rbackup/hierarchy/snapshot.py @@ -1,7 +1,7 @@ """ .. author:: Eric Torres .. module:: rbackup.hierarchy.snapshot - :synopsis: Classes for creating the /tmp hierarchy. + :synopsis: Classes for creating the backup hierarchy. """ import logging @@ -29,52 +29,56 @@ class Snapshot(Hierarchy): """Default constructor for the Snapshot class.""" super().__init__(path) - self._boot_dir = self.path / "boot" - self._etc_dir = self.path / "etc" - self._home_dir = self.path / "home" - self._root_home_dir = self.path / "root" - @property def boot_dir(self): - """Retrieve the /boot /tmp directory of this snapshot. + """Retrieve the /boot backup directory of this snapshot. Example ------- - >>> s = Snapshot('/tmp/data/snapshot-new') + >>> s = Snapshot('backup/data/snapshot-new') >>> s.boot_dir - PosixPath('/tmp/data/snapshot-new/boot') + PosixPath('backup/data/snapshot-new/boot/loader') :rtype: path-like object """ - return self._boot_dir + return self.path / "boot" / "loader" @property def etc_dir(self): - """Retrieve the /etc /tmp directory of this snapshot. + """Retrieve the /etc backup directory of this snapshot. Example ------- - >>> s = Snapshot('/tmp/data/snapshot-new') + >>> s = Snapshot('backup/data/snapshot-new') >>> s.etc_dir - PosixPath('/tmp/data/snapshot-new/etc') + PosixPath('backup/data/snapshot-new/etc') :rtype: path-like object """ - return self._etc_dir + return self.path / "etc" @property def home_dir(self): - """Retrieve the /home /tmp directory of this snapshot. + """Retrieve the /home backup directory of this snapshot. Example ------- - >>> s = Snapshot('/tmp/data/snapshot-new') + >>> s = Snapshot('backup/data/snapshot-new') >>> s.home_dir - PosixPath('/tmp/data/snapshot-new/home') + PosixPath('backup/data/snapshot-new/home') :rtype: path-like object """ - return self._home_dir + return self.path / "home" + + @property + def pkg_dir(self): + """Retrieve the package manager backup directory of this snapshot. + >>> s = Snapshot('backup/data/snapshot-new') + >>> s.pkg_dir + PosixPath('backup/data/snapshot-new/pkg') + """ + return self.path / "pkg" @property def root_home_dir(self): @@ -82,13 +86,13 @@ class Snapshot(Hierarchy): Example ------- - >>> s = Snapshot('/tmp/data/snapshot-new') + >>> s = Snapshot('backup/data/snapshot-new') >>> s.root_home_dir - PosixPath('/tmp/data/snapshot-new/root') + PosixPath('backup/data/snapshot-new/root') :rtype: path-like object """ - return self._root_home_dir + return self.path / "root" # ========== Functions ========== diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index d7f42d2..df80c57 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -10,7 +10,7 @@ from pathlib import Path from rbackup.hierarchy.snapshot import Snapshot # ========== Constants ========== -TESTING_MODULE = "rbackup.hierarchy.repository" +TESTING_MODULE = "rbackup.hierarchy.snapshot" # ========== Functions ========== @@ -33,7 +33,8 @@ class TestSnapshot(unittest.TestCase): def test_boot_dir(self): self.assertEqual( - self.test_snapshot.boot_dir, self.snapshot_fullpath / "boot" + self.test_snapshot.boot_dir, + self.snapshot_fullpath / "boot" / "loader", ) def test_etc_dir(self): @@ -46,6 +47,11 @@ class TestSnapshot(unittest.TestCase): self.test_snapshot.home_dir, self.snapshot_fullpath / "home" ) + def test_pkg_dir(self): + self.assertEqual( + self.test_snapshot.pkg_dir, self.snapshot_fullpath / "pkg" + ) + def test_root_home_dir(self): self.assertEqual( self.test_snapshot.root_home_dir, self.snapshot_fullpath / "root"