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]
|
||||
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()}
|
||||
|
||||
|
||||
|
|
|
@ -60,7 +60,8 @@ def time_me(function):
|
|||
start = time.time()
|
||||
result = function(*args, **kwargs)
|
||||
end = time.time()
|
||||
print('%s: %0.8f' % (function.__name__, end-start))
|
||||
duration = end - start
|
||||
print('%s: %0.8f' % (function.__name__, duration))
|
||||
return result
|
||||
return timed_function
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ class EtiquetteException(Exception, metaclass=ErrorTypeAdder):
|
|||
Exception's constructor arguments.
|
||||
'''
|
||||
error_message = ''
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__()
|
||||
self.given_args = args
|
||||
|
@ -77,6 +78,7 @@ class Exists(EtiquetteException):
|
|||
|
||||
class AlbumExists(Exists):
|
||||
error_message = 'Album "{}" already exists.'
|
||||
|
||||
def __init__(self, album):
|
||||
self.album = album
|
||||
EtiquetteException.__init__(self, album)
|
||||
|
@ -86,18 +88,21 @@ class GroupExists(Exists):
|
|||
|
||||
class PhotoExists(Exists):
|
||||
error_message = 'Photo "{}" already exists.'
|
||||
|
||||
def __init__(self, photo):
|
||||
self.photo = photo
|
||||
EtiquetteException.__init__(self, photo)
|
||||
|
||||
class TagExists(Exists):
|
||||
error_message = 'Tag "{}" already exists.'
|
||||
|
||||
def __init__(self, tag):
|
||||
self.tag = tag
|
||||
EtiquetteException.__init__(self, tag)
|
||||
|
||||
class UserExists(Exists):
|
||||
error_message = 'User "{}" already exists.'
|
||||
|
||||
def __init__(self, user):
|
||||
self.user = 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)
|
||||
'''
|
||||
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_height = int(image_height * ratio)
|
||||
|
@ -229,13 +231,11 @@ def read_filebytes(filepath, range_min, range_max, chunk_size=2 ** 20):
|
|||
'''
|
||||
range_span = range_max - range_min
|
||||
|
||||
#print('read span', range_min, range_max, range_span)
|
||||
f = open(filepath, 'rb')
|
||||
f.seek(range_min)
|
||||
sent_amount = 0
|
||||
with f:
|
||||
while sent_amount < range_span:
|
||||
#print(sent_amount)
|
||||
chunk = f.read(chunk_size)
|
||||
if len(chunk) == 0:
|
||||
break
|
||||
|
|
|
@ -762,12 +762,11 @@ class Photo(ObjectBase):
|
|||
size=size,
|
||||
time=timestamp,
|
||||
)
|
||||
except:
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
else:
|
||||
return_filepath = hopeful_filepath
|
||||
|
||||
|
||||
if return_filepath != self.thumbnail:
|
||||
data = {
|
||||
'id': self.id,
|
||||
|
@ -1331,7 +1330,7 @@ class Tag(ObjectBase, GroupableMixin):
|
|||
return
|
||||
|
||||
try:
|
||||
existing_tag = self.photodb.get_tag(name=new_name)
|
||||
self.photodb.get_tag(name=new_name)
|
||||
except exceptions.NoSuchTag:
|
||||
pass
|
||||
else:
|
||||
|
|
|
@ -1313,6 +1313,7 @@ class PhotoDB(
|
|||
etc
|
||||
'''
|
||||
output_notes = []
|
||||
|
||||
def create_or_get(name):
|
||||
#print('cog', name)
|
||||
try:
|
||||
|
|
|
@ -55,7 +55,6 @@ def build_query(
|
|||
if column != 'RANDOM()':
|
||||
notnulls.add(column)
|
||||
|
||||
|
||||
if minimums:
|
||||
for (column, value) in minimums.items():
|
||||
wheres.add(column + ' >= ' + str(value))
|
||||
|
|
Loading…
Reference in a new issue