From 2660af23d869ff4f0619edd091119a26b7816b05 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 16 Jan 2021 09:36:23 +0100 Subject: [PATCH] Destination directories now get created when needed --- app/specs/spec.py | 9 ++++++--- backups.yaml | 4 ++-- backups_test.yaml | 14 -------------- 3 files changed, 8 insertions(+), 19 deletions(-) delete mode 100644 backups_test.yaml diff --git a/app/specs/spec.py b/app/specs/spec.py index 35481ae..8e57093 100644 --- a/app/specs/spec.py +++ b/app/specs/spec.py @@ -45,10 +45,13 @@ class Spec: destination if type(destination) == Path else Path(destination) ) - # Check existence of destination folder - if not self.destination.exists() or not self.destination.is_dir(): + # Create destination if non-existent + try: + self.destination.mkdir(parents=True, exist_ok=True) + + except FileExistsError: raise NotADirectoryError( - "{} doesn't exist or isn't a directory.".format( + "{} already exists, but isn't a directory.".format( self.destination ) ) diff --git a/backups.yaml b/backups.yaml index fb8104c..e82340e 100644 --- a/backups.yaml +++ b/backups.yaml @@ -36,6 +36,6 @@ specs: directories: test: - destination: "/home/jjr/test" + destination: "/tmp/to" limit: 5 - source: "/home/jjr" + source: "/tmp/from" diff --git a/backups_test.yaml b/backups_test.yaml deleted file mode 100644 index 2249ec3..0000000 --- a/backups_test.yaml +++ /dev/null @@ -1,14 +0,0 @@ -defaults: - directories: - notify: - title: 'yeet' - events: - - 'random' - - limit: 7 - -specs: - directories: - test: - source: '/tmp/from' - destination: '/tmp/to'