Minor linter appeasements.
This commit is contained in:
parent
c99e783d04
commit
1cd78a678b
7 changed files with 25 additions and 12 deletions
|
@ -147,7 +147,15 @@ for statement in DB_INIT.split(';'):
|
||||||
column_names = [x.strip().split(' ')[0] for x in column_names]
|
column_names = [x.strip().split(' ')[0] for x in column_names]
|
||||||
SQL_COLUMNS[table_name] = column_names
|
SQL_COLUMNS[table_name] = column_names
|
||||||
|
|
||||||
_sql_dictify = lambda columns: {key:index for (index, key) in enumerate(columns)}
|
def _sql_dictify(columns):
|
||||||
|
'''
|
||||||
|
A dictionary where the key is the item and the value is the index.
|
||||||
|
Used to convert a stringy name into the correct number to then index into
|
||||||
|
an sql row.
|
||||||
|
['test', 'toast'] -> {'test': 0, 'toast': 1}
|
||||||
|
'''
|
||||||
|
return {key: index for (index, key) in enumerate(columns)}
|
||||||
|
|
||||||
SQL_INDEX = {key: _sql_dictify(value) for (key, value) in SQL_COLUMNS.items()}
|
SQL_INDEX = {key: _sql_dictify(value) for (key, value) in SQL_COLUMNS.items()}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,8 @@ def time_me(function):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
result = function(*args, **kwargs)
|
result = function(*args, **kwargs)
|
||||||
end = time.time()
|
end = time.time()
|
||||||
print('%s: %0.8f' % (function.__name__, end-start))
|
duration = end - start
|
||||||
|
print('%s: %0.8f' % (function.__name__, duration))
|
||||||
return result
|
return result
|
||||||
return timed_function
|
return timed_function
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ class EtiquetteException(Exception, metaclass=ErrorTypeAdder):
|
||||||
Exception's constructor arguments.
|
Exception's constructor arguments.
|
||||||
'''
|
'''
|
||||||
error_message = ''
|
error_message = ''
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.given_args = args
|
self.given_args = args
|
||||||
|
@ -77,6 +78,7 @@ class Exists(EtiquetteException):
|
||||||
|
|
||||||
class AlbumExists(Exists):
|
class AlbumExists(Exists):
|
||||||
error_message = 'Album "{}" already exists.'
|
error_message = 'Album "{}" already exists.'
|
||||||
|
|
||||||
def __init__(self, album):
|
def __init__(self, album):
|
||||||
self.album = album
|
self.album = album
|
||||||
EtiquetteException.__init__(self, album)
|
EtiquetteException.__init__(self, album)
|
||||||
|
@ -86,18 +88,21 @@ class GroupExists(Exists):
|
||||||
|
|
||||||
class PhotoExists(Exists):
|
class PhotoExists(Exists):
|
||||||
error_message = 'Photo "{}" already exists.'
|
error_message = 'Photo "{}" already exists.'
|
||||||
|
|
||||||
def __init__(self, photo):
|
def __init__(self, photo):
|
||||||
self.photo = photo
|
self.photo = photo
|
||||||
EtiquetteException.__init__(self, photo)
|
EtiquetteException.__init__(self, photo)
|
||||||
|
|
||||||
class TagExists(Exists):
|
class TagExists(Exists):
|
||||||
error_message = 'Tag "{}" already exists.'
|
error_message = 'Tag "{}" already exists.'
|
||||||
|
|
||||||
def __init__(self, tag):
|
def __init__(self, tag):
|
||||||
self.tag = tag
|
self.tag = tag
|
||||||
EtiquetteException.__init__(self, tag)
|
EtiquetteException.__init__(self, tag)
|
||||||
|
|
||||||
class UserExists(Exists):
|
class UserExists(Exists):
|
||||||
error_message = 'User "{}" already exists.'
|
error_message = 'User "{}" already exists.'
|
||||||
|
|
||||||
def __init__(self, user):
|
def __init__(self, user):
|
||||||
self.user = user
|
self.user = user
|
||||||
EtiquetteException.__init__(self, user)
|
EtiquetteException.__init__(self, user)
|
||||||
|
|
|
@ -140,7 +140,9 @@ def fit_into_bounds(image_width, image_height, frame_width, frame_height):
|
||||||
|
|
||||||
(1920, 1080, 400, 400) -> (400, 225)
|
(1920, 1080, 400, 400) -> (400, 225)
|
||||||
'''
|
'''
|
||||||
ratio = min(frame_width/image_width, frame_height/image_height)
|
width_ratio = frame_width / image_width
|
||||||
|
height_ratio = frame_height / image_height
|
||||||
|
ratio = min(width_ratio, height_ratio)
|
||||||
|
|
||||||
new_width = int(image_width * ratio)
|
new_width = int(image_width * ratio)
|
||||||
new_height = int(image_height * ratio)
|
new_height = int(image_height * ratio)
|
||||||
|
@ -193,10 +195,10 @@ def hms_to_seconds(hms):
|
||||||
hms = hms.split(':')
|
hms = hms.split(':')
|
||||||
seconds = 0
|
seconds = 0
|
||||||
if len(hms) == 3:
|
if len(hms) == 3:
|
||||||
seconds += int(hms[0])*3600
|
seconds += int(hms[0]) * 3600
|
||||||
hms.pop(0)
|
hms.pop(0)
|
||||||
if len(hms) == 2:
|
if len(hms) == 2:
|
||||||
seconds += int(hms[0])*60
|
seconds += int(hms[0]) * 60
|
||||||
hms.pop(0)
|
hms.pop(0)
|
||||||
if len(hms) == 1:
|
if len(hms) == 1:
|
||||||
seconds += float(hms[0])
|
seconds += float(hms[0])
|
||||||
|
@ -229,13 +231,11 @@ def read_filebytes(filepath, range_min, range_max, chunk_size=2 ** 20):
|
||||||
'''
|
'''
|
||||||
range_span = range_max - range_min
|
range_span = range_max - range_min
|
||||||
|
|
||||||
#print('read span', range_min, range_max, range_span)
|
|
||||||
f = open(filepath, 'rb')
|
f = open(filepath, 'rb')
|
||||||
f.seek(range_min)
|
f.seek(range_min)
|
||||||
sent_amount = 0
|
sent_amount = 0
|
||||||
with f:
|
with f:
|
||||||
while sent_amount < range_span:
|
while sent_amount < range_span:
|
||||||
#print(sent_amount)
|
|
||||||
chunk = f.read(chunk_size)
|
chunk = f.read(chunk_size)
|
||||||
if len(chunk) == 0:
|
if len(chunk) == 0:
|
||||||
break
|
break
|
||||||
|
|
|
@ -762,12 +762,11 @@ class Photo(ObjectBase):
|
||||||
size=size,
|
size=size,
|
||||||
time=timestamp,
|
time=timestamp,
|
||||||
)
|
)
|
||||||
except:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
else:
|
else:
|
||||||
return_filepath = hopeful_filepath
|
return_filepath = hopeful_filepath
|
||||||
|
|
||||||
|
|
||||||
if return_filepath != self.thumbnail:
|
if return_filepath != self.thumbnail:
|
||||||
data = {
|
data = {
|
||||||
'id': self.id,
|
'id': self.id,
|
||||||
|
@ -1331,7 +1330,7 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
existing_tag = self.photodb.get_tag(name=new_name)
|
self.photodb.get_tag(name=new_name)
|
||||||
except exceptions.NoSuchTag:
|
except exceptions.NoSuchTag:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1313,6 +1313,7 @@ class PhotoDB(
|
||||||
etc
|
etc
|
||||||
'''
|
'''
|
||||||
output_notes = []
|
output_notes = []
|
||||||
|
|
||||||
def create_or_get(name):
|
def create_or_get(name):
|
||||||
#print('cog', name)
|
#print('cog', name)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -55,7 +55,6 @@ def build_query(
|
||||||
if column != 'RANDOM()':
|
if column != 'RANDOM()':
|
||||||
notnulls.add(column)
|
notnulls.add(column)
|
||||||
|
|
||||||
|
|
||||||
if minimums:
|
if minimums:
|
||||||
for (column, value) in minimums.items():
|
for (column, value) in minimums.items():
|
||||||
wheres.add(column + ' >= ' + str(value))
|
wheres.add(column + ' >= ' + str(value))
|
||||||
|
|
Loading…
Reference in a new issue