Add PhotoDB init option create
. Disable to require existing.
This commit is contained in:
parent
101f6d9c47
commit
d85d911b22
1 changed files with 8 additions and 1 deletions
|
@ -1075,6 +1075,8 @@ class PhotoDB(
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
data_directory=None,
|
data_directory=None,
|
||||||
|
*,
|
||||||
|
create=True,
|
||||||
ephemeral=False,
|
ephemeral=False,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -1098,7 +1100,6 @@ class PhotoDB(
|
||||||
|
|
||||||
if self.data_directory.exists and not self.data_directory.is_dir:
|
if self.data_directory.exists and not self.data_directory.is_dir:
|
||||||
raise exceptions.BadDataDirectory(self.data_directory.absolute_path)
|
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)
|
self.log = logging.getLogger('etiquette:%s' % self.data_directory.absolute_path)
|
||||||
self.log.setLevel(logging.DEBUG)
|
self.log.setLevel(logging.DEBUG)
|
||||||
|
@ -1110,6 +1111,12 @@ class PhotoDB(
|
||||||
else:
|
else:
|
||||||
self.database_filepath = self.data_directory.with_child(constants.DEFAULT_DBNAME)
|
self.database_filepath = self.data_directory.with_child(constants.DEFAULT_DBNAME)
|
||||||
existing_database = self.database_filepath.exists
|
existing_database = self.database_filepath.exists
|
||||||
|
|
||||||
|
if not create and not self.ephemeral and not existing_database:
|
||||||
|
raise FileNotFoundError('"%s" does not exist and create is off.' % self.data_directory)
|
||||||
|
|
||||||
|
if not self.ephemeral:
|
||||||
|
os.makedirs(self.data_directory.absolute_path, exist_ok=True)
|
||||||
self.sql = sqlite3.connect(self.database_filepath.absolute_path)
|
self.sql = sqlite3.connect(self.database_filepath.absolute_path)
|
||||||
|
|
||||||
if existing_database:
|
if existing_database:
|
||||||
|
|
Loading…
Reference in a new issue