From 101f6d9c47a5aa3491c772754e7a54eaea15c304 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 13 Mar 2018 02:21:35 -0700 Subject: [PATCH] Add exception BadDataDirectory. --- etiquette/exceptions.py | 6 ++++++ etiquette/photodb.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/etiquette/exceptions.py b/etiquette/exceptions.py index 95e0ca8..78a3eb6 100644 --- a/etiquette/exceptions.py +++ b/etiquette/exceptions.py @@ -152,6 +152,12 @@ class WrongLogin(EtiquetteException): # GENERAL ERRORS +class BadDataDirectory(EtiquetteException): + ''' + Raised by PhotoDB __init__ if the requested data_directory is invalid. + ''' + error_message = 'Bad data directory "{}"' + OUTOFDATE = ''' Database is out of date. {current} should be {new}. Please use utilities\\database_upgrader.py diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 65f5791..7eb03df 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -1095,6 +1095,9 @@ class PhotoDB( data_directory = helpers.remove_path_badchars(data_directory, allowed=':/\\') self.data_directory = pathclass.Path(data_directory) + + if self.data_directory.exists and not self.data_directory.is_dir: + raise exceptions.BadDataDirectory(self.data_directory.absolute_path) os.makedirs(self.data_directory.absolute_path, exist_ok=True) self.log = logging.getLogger('etiquette:%s' % self.data_directory.absolute_path)