database moved into datadir. filename no longer an option.

This commit is contained in:
voussoir 2016-12-16 01:53:51 -08:00
parent 6a96bc4ada
commit d704b960cc
2 changed files with 16 additions and 16 deletions

View file

@ -33,16 +33,16 @@ MAX_TAG_NAME_LENGTH = 32
VALID_TAG_CHARS = string.ascii_lowercase + string.digits + '_' VALID_TAG_CHARS = string.ascii_lowercase + string.digits + '_'
DEFAULT_ID_LENGTH = 12 DEFAULT_ID_LENGTH = 12
DEFAULT_DBNAME = 'phototagger.db'
DEFAULT_DATADIR = '.\\_etiquette' DEFAULT_DATADIR = '.\\_etiquette'
DEFAULT_DIGEST_EXCLUDE_FILES = [ DEFAULT_DIGEST_EXCLUDE_FILES = [
DEFAULT_DBNAME, 'phototagger.db',
'desktop.ini', 'desktop.ini',
'thumbs.db' 'thumbs.db'
] ]
DEFAULT_DIGEST_EXCLUDE_DIRS = [ DEFAULT_DIGEST_EXCLUDE_DIRS = [
'_site_thumbnails', '_site_thumbnails',
] ]
FILE_READ_CHUNK = 2 ** 20 FILE_READ_CHUNK = 2 ** 20
THUMBNAIL_WIDTH = 400 THUMBNAIL_WIDTH = 400

View file

@ -948,23 +948,25 @@ class PhotoDB(PDBAlbumMixin, PDBPhotoMixin, PDBTagMixin):
''' '''
def __init__( def __init__(
self, self,
databasename=None,
data_directory=None, data_directory=None,
*, *,
id_length=None id_length=None
): ):
if databasename is None:
databasename = constants.DEFAULT_DBNAME
if data_directory is None: if data_directory is None:
data_directory = constants.DEFAULT_DATADIR data_directory = constants.DEFAULT_DATADIR
if id_length is None: if id_length is None:
id_length = constants.DEFAULT_ID_LENGTH id_length = constants.DEFAULT_ID_LENGTH
self.databasename = databasename data_directory = normalize_filepath(data_directory)
self.database_abspath = os.path.abspath(databasename)
existing_database = os.path.exists(databasename) self.data_directory = os.path.abspath(data_directory)
self.sql = sqlite3.connect(databasename) os.makedirs(self.data_directory, exist_ok=True)
self.database_abspath = os.path.join(data_directory, 'phototagger.db')
existing_database = os.path.exists(self.database_abspath)
self.sql = sqlite3.connect(self.database_abspath)
self.cur = self.sql.cursor() self.cur = self.sql.cursor()
if existing_database: if existing_database:
self.cur.execute('PRAGMA user_version') self.cur.execute('PRAGMA user_version')
existing_version = self.cur.fetchone()[0] existing_version = self.cur.fetchone()[0]
@ -978,11 +980,9 @@ class PhotoDB(PDBAlbumMixin, PDBPhotoMixin, PDBTagMixin):
for statement in statements: for statement in statements:
self.cur.execute(statement) self.cur.execute(statement)
self.thumbnail_directory = os.path.join(self.data_directory, 'site_thumbnails')
self.data_directory = data_directory self.thumbnail_directory = os.path.abspath(self.thumbnail_directory)
self.thumbnail_folder = os.path.join(data_directory, 'site_thumbnails') os.makedirs(self.thumbnail_directory, exist_ok=True)
self.thumbnail_folder = os.path.abspath(self.thumbnail_folder)
os.makedirs(self.thumbnail_folder, exist_ok=True)
self.id_length = id_length self.id_length = id_length
@ -990,7 +990,7 @@ class PhotoDB(PDBAlbumMixin, PDBPhotoMixin, PDBTagMixin):
self._cached_frozen_children = None self._cached_frozen_children = None
def __repr__(self): def __repr__(self):
return 'PhotoDB(databasename={dbname})'.format(dbname=repr(self.databasename)) return 'PhotoDB(data_directory={datadir})'.format(datadir=repr(self.data_directory))
def _uncache(self): def _uncache(self):
self._cached_frozen_children = None self._cached_frozen_children = None
@ -1715,7 +1715,7 @@ class Photo(ObjectBase):
basename = chunked_id[-1] basename = chunked_id[-1]
folder = chunked_id[:-1] folder = chunked_id[:-1]
folder = os.sep.join(folder) folder = os.sep.join(folder)
folder = os.path.join(self.photodb.thumbnail_folder, folder) folder = os.path.join(self.photodb.thumbnail_directory, folder)
if folder: if folder:
os.makedirs(folder, exist_ok=True) os.makedirs(folder, exist_ok=True)
hopeful_filepath = os.path.join(folder, basename) + '.jpg' hopeful_filepath = os.path.join(folder, basename) + '.jpg'