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)