From 48c74aa8f8ba59e1b3782c0be7a4560973b31924 Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Mon, 22 Apr 2019 21:18:25 -0700 Subject: [PATCH] Implement __dir__ dunder method --- rbackup/struct/hierarchy.py | 17 +++++++++++++++++ rbackup/struct/repository.py | 19 +++++++++++++++++++ rbackup/struct/snapshot.py | 3 +++ 3 files changed, 39 insertions(+) diff --git a/rbackup/struct/hierarchy.py b/rbackup/struct/hierarchy.py index 026940d..c0aa7bb 100644 --- a/rbackup/struct/hierarchy.py +++ b/rbackup/struct/hierarchy.py @@ -66,6 +66,23 @@ class Hierarchy(PathLike): """Return a string representation of this Hierarchy.""" return str(self._path) + def __dir__(self): + return [ + "__dir__", + "__eq__", + "__fspath__", + "__hash__", + "__ne__", + "__repr__", + "__str__", + "path", + "name", + "metadata_path", + "cleanup", + "read_metadata", + "write_metadata", + ] + def _gen_metadata(self): """Generate metadata for this repository. diff --git a/rbackup/struct/repository.py b/rbackup/struct/repository.py index f2c14a5..1e59e6e 100644 --- a/rbackup/struct/repository.py +++ b/rbackup/struct/repository.py @@ -143,6 +143,25 @@ class Repository(Hierarchy): """Return the next Snapshot in this Repository.""" return next(self._snapshot_iterator) + def __dir__(self): + return [ + super().__dir__(), + "__contains__", + "__delitem__", + "__getitem__", + "__iter__", + "__len__", + "__next__", + "is_valid_snapshot_name", + "snapshot_dir", + "snapshot_symlink", + "snapshots", + "empty", + "cleanup", + "create_snapshot", + "symlink_snapshot", + ] + @staticmethod def is_valid_snapshot_name(name): """Check if the given name is a valid name. diff --git a/rbackup/struct/snapshot.py b/rbackup/struct/snapshot.py index 5127d79..1bbaf88 100644 --- a/rbackup/struct/snapshot.py +++ b/rbackup/struct/snapshot.py @@ -31,6 +31,9 @@ class Snapshot(Hierarchy): self._pkg_dir = self.path / "pkg" + def __dir__(self): + return [super().__dir__(), "ctime", "pkg_dir"] + def __repr__(self): """Return a string representation of this Snapshot.""" return f"{self.__class__.__name__}('{self.name}')"