Use more pathclass.Path
This commit is contained in:
parent
d35011c083
commit
0bfbc789ca
1 changed files with 10 additions and 13 deletions
|
@ -407,9 +407,9 @@ class PDBPhotoMixin:
|
||||||
return self.get_thing_by_id('photo', photoid)
|
return self.get_thing_by_id('photo', photoid)
|
||||||
|
|
||||||
def get_photo_by_path(self, filepath):
|
def get_photo_by_path(self, filepath):
|
||||||
filepath = os.path.abspath(filepath)
|
filepath = pathclass.Path(filepath)
|
||||||
cur = self.sql.cursor()
|
cur = self.sql.cursor()
|
||||||
cur.execute('SELECT * FROM photos WHERE filepath == ?', [filepath])
|
cur.execute('SELECT * FROM photos WHERE filepath == ?', [filepath.absolute_path])
|
||||||
fetch = cur.fetchone()
|
fetch = cur.fetchone()
|
||||||
if fetch is None:
|
if fetch is None:
|
||||||
raise exceptions.NoSuchPhoto(filepath)
|
raise exceptions.NoSuchPhoto(filepath)
|
||||||
|
@ -442,7 +442,7 @@ class PDBPhotoMixin:
|
||||||
|
|
||||||
def new_photo(
|
def new_photo(
|
||||||
self,
|
self,
|
||||||
filename,
|
filepath,
|
||||||
*,
|
*,
|
||||||
allow_duplicates=False,
|
allow_duplicates=False,
|
||||||
author=None,
|
author=None,
|
||||||
|
@ -463,32 +463,29 @@ class PDBPhotoMixin:
|
||||||
if not self.config['enable_new_photo']:
|
if not self.config['enable_new_photo']:
|
||||||
raise exceptions.FeatureDisabled('new_photo')
|
raise exceptions.FeatureDisabled('new_photo')
|
||||||
|
|
||||||
filename = os.path.abspath(filename)
|
filepath = pathclass.Path(filepath)
|
||||||
if not os.path.isfile(filename):
|
if not filepath.is_file:
|
||||||
raise FileNotFoundError(filename)
|
raise FileNotFoundError(filepath.absolute_path)
|
||||||
|
|
||||||
if not allow_duplicates:
|
if not allow_duplicates:
|
||||||
try:
|
try:
|
||||||
existing = self.get_photo_by_path(filename)
|
existing = self.get_photo_by_path(filepath)
|
||||||
except exceptions.NoSuchPhoto:
|
except exceptions.NoSuchPhoto:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise exceptions.PhotoExists(existing)
|
raise exceptions.PhotoExists(existing)
|
||||||
|
|
||||||
self.log.debug('New Photo: %s' % filename)
|
self.log.debug('New Photo: %s' % filepath.absolute_path)
|
||||||
author_id = self.get_user_id_or_none(author)
|
author_id = self.get_user_id_or_none(author)
|
||||||
|
|
||||||
extension = os.path.splitext(filename)[1]
|
|
||||||
extension = extension.replace('.', '')
|
|
||||||
#extension = self.normalize_tagname(extension)
|
|
||||||
created = int(helpers.now())
|
created = int(helpers.now())
|
||||||
photoid = self.generate_id('photos')
|
photoid = self.generate_id('photos')
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'id': photoid,
|
'id': photoid,
|
||||||
'filepath': filename,
|
'filepath': filepath.absolute_path,
|
||||||
'override_filename': None,
|
'override_filename': None,
|
||||||
'extension': extension,
|
'extension': filepath.extension,
|
||||||
'created': created,
|
'created': created,
|
||||||
'tagged_at': None,
|
'tagged_at': None,
|
||||||
'author_id': author_id,
|
'author_id': author_id,
|
||||||
|
|
Loading…
Reference in a new issue