Add exception BadDataDirectory.

This commit is contained in:
voussoir 2018-03-13 02:21:35 -07:00
parent b89da5dec2
commit 101f6d9c47
2 changed files with 9 additions and 0 deletions

View file

@ -152,6 +152,12 @@ class WrongLogin(EtiquetteException):
# GENERAL ERRORS # GENERAL ERRORS
class BadDataDirectory(EtiquetteException):
'''
Raised by PhotoDB __init__ if the requested data_directory is invalid.
'''
error_message = 'Bad data directory "{}"'
OUTOFDATE = ''' OUTOFDATE = '''
Database is out of date. {current} should be {new}. Database is out of date. {current} should be {new}.
Please use utilities\\database_upgrader.py Please use utilities\\database_upgrader.py

View file

@ -1095,6 +1095,9 @@ class PhotoDB(
data_directory = helpers.remove_path_badchars(data_directory, allowed=':/\\') data_directory = helpers.remove_path_badchars(data_directory, allowed=':/\\')
self.data_directory = pathclass.Path(data_directory) 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) os.makedirs(self.data_directory.absolute_path, exist_ok=True)
self.log = logging.getLogger('etiquette:%s' % self.data_directory.absolute_path) self.log = logging.getLogger('etiquette:%s' % self.data_directory.absolute_path)