Fix numerous flake8 warnings

This commit is contained in:
Jaisen Mathai 2016-06-24 00:31:58 -04:00
parent 1ad3d16da6
commit cb38bf5176
5 changed files with 18 additions and 33 deletions

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
flake8 elodie --exclude=tests && nosetests -w elodie/tests flake8 elodie --exclude=tests,external && nosetests -w elodie/tests

View File

@ -76,11 +76,11 @@ def coordinates_by_name(name):
def decimal_to_dms(decimal): def decimal_to_dms(decimal):
decimal = float(decimal) decimal = float(decimal)
decimal_abs = abs(decimal) decimal_abs = abs(decimal)
minutes,seconds = divmod(decimal_abs*3600,60) minutes, seconds = divmod(decimal_abs*3600, 60)
degrees,minutes = divmod(minutes,60) degrees, minutes = divmod(minutes, 60)
degrees = degrees degrees = degrees
sign = 1 if decimal >= 0 else -1 sign = 1 if decimal >= 0 else -1
return (degrees,minutes,seconds, sign) return (degrees, minutes, seconds, sign)
def dms_to_decimal(degrees, minutes, seconds, direction=' '): def dms_to_decimal(degrees, minutes, seconds, direction=' '):

View File

@ -15,10 +15,6 @@ from elodie.dependencies import get_exiftool
from elodie.external.pyexiftool import ExifTool from elodie.external.pyexiftool import ExifTool
from elodie.media.base import Base from elodie.media.base import Base
import os
import re
import subprocess
class Media(Base): class Media(Base):
@ -92,12 +88,16 @@ class Media(Base):
for key in self.latitude_keys + self.longitude_keys: for key in self.latitude_keys + self.longitude_keys:
# TODO: verify that we need to check ref key # TODO: verify that we need to check ref key
# when self.set_gps_ref != True # when self.set_gps_ref != True
if type == 'latitude' and key in self.latitude_keys and key in exif: if type == 'latitude' and key in self.latitude_keys and \
if self.latitude_ref_key in exif and exif[self.latitude_ref_key] == 'S': #noqa key in exif:
if self.latitude_ref_key in exif and \
exif[self.latitude_ref_key] == 'S':
direction_multiplier = -1 direction_multiplier = -1
return exif[key] * direction_multiplier return exif[key] * direction_multiplier
elif type == 'longitude' and key in self.longitude_keys and key in exif: #noqa elif type == 'longitude' and key in self.longitude_keys and \
if self.longitude_ref_key in exif and exif[self.longitude_ref_key] == 'W': #noqa key in exif:
if self.longitude_ref_key in exif and \
exif[self.longitude_ref_key] == 'W':
direction_multiplier = -1 direction_multiplier = -1
return exif[key] * direction_multiplier return exif[key] * direction_multiplier
@ -170,8 +170,6 @@ class Media(Base):
if(time is None): if(time is None):
return False return False
source = self.source
tags = {} tags = {}
formatted_time = time.strftime('%Y:%m:%d %H:%M:%S') formatted_time = time.strftime('%Y:%m:%d %H:%M:%S')
for key in self.exif_map['date_taken']: for key in self.exif_map['date_taken']:
@ -185,8 +183,6 @@ class Media(Base):
if(not self.is_valid()): if(not self.is_valid()):
return None return None
source = self.source
# The lat/lon _keys array has an order of precedence. # The lat/lon _keys array has an order of precedence.
# The first key is writable and we will give the writable # The first key is writable and we will give the writable
# key precence when reading. # key precence when reading.
@ -222,8 +218,6 @@ class Media(Base):
if(title is None): if(title is None):
return None return None
source = self.source
tags = {self.title_key: title} tags = {self.title_key: title}
status = self.__set_tags(tags) status = self.__set_tags(tags)
self.reset_cache() self.reset_cache()

View File

@ -15,8 +15,6 @@ from re import compile
from elodie import constants from elodie import constants
from elodie import geolocation
from elodie.external.pyexiftool import ExifTool
from media import Media from media import Media
@ -69,7 +67,7 @@ class Photo(Media):
""" """
if(not self.is_valid()): if(not self.is_valid()):
return None return None
source = self.source source = self.source
seconds_since_epoch = min(os.path.getmtime(source), os.path.getctime(source)) # noqa seconds_since_epoch = min(os.path.getmtime(source), os.path.getctime(source)) # noqa
@ -80,7 +78,7 @@ class Photo(Media):
# We need to parse a string from EXIF into a timestamp. # We need to parse a string from EXIF into a timestamp.
# EXIF DateTimeOriginal and EXIF DateTime are both stored # EXIF DateTimeOriginal and EXIF DateTime are both stored
# in %Y:%m:%d %H:%M:%S format # in %Y:%m:%d %H:%M:%S format
# we use split on a space and then r':|-' -> convert to int -> .timetuple() # we split on a space and then r':|-' -> convert to int -> .timetuple()
# the conversion in the local timezone # the conversion in the local timezone
# EXIF DateTime is already stored as a timestamp # EXIF DateTime is already stored as a timestamp
# Sourced from https://github.com/photo/frontend/blob/master/src/libraries/models/Photo.php#L500 # noqa # Sourced from https://github.com/photo/frontend/blob/master/src/libraries/models/Photo.php#L500 # noqa

View File

@ -7,19 +7,12 @@ objects (AVI, MOV, etc.).
# load modules # load modules
from distutils.spawn import find_executable from distutils.spawn import find_executable
import tempfile
from datetime import datetime from datetime import datetime
import os import os
import re import re
import shutil
import subprocess
import time import time
from elodie import constants
from elodie import plist_parser
from elodie.dependencies import get_exiftool
from media import Base
from media import Media from media import Media
@ -45,12 +38,12 @@ class Video(Media):
self.title_key = 'XMP:DisplayName' self.title_key = 'XMP:DisplayName'
self.latitude_keys = [ self.latitude_keys = [
'XMP:GPSLatitude', 'XMP:GPSLatitude',
#'QuickTime:GPSLatitude', # 'QuickTime:GPSLatitude',
'Composite:GPSLatitude' 'Composite:GPSLatitude'
] ]
self.longitude_keys = [ self.longitude_keys = [
'XMP:GPSLongitude', 'XMP:GPSLongitude',
#'QuickTime:GPSLongitude', # 'QuickTime:GPSLongitude',
'Composite:GPSLongitude' 'Composite:GPSLongitude'
] ]
self.latitude_ref_key = 'EXIF:GPSLatitudeRef' self.latitude_ref_key = 'EXIF:GPSLatitudeRef'
@ -81,7 +74,7 @@ class Video(Media):
""" """
if(not self.is_valid()): if(not self.is_valid()):
return None return None
source = self.source source = self.source
seconds_since_epoch = min(os.path.getmtime(source), os.path.getctime(source)) # noqa seconds_since_epoch = min(os.path.getmtime(source), os.path.getctime(source)) # noqa
@ -107,7 +100,7 @@ class Video(Media):
if date_offset is not None: if date_offset is not None:
offset_parts = date_offset[1:].split(':') offset_parts = date_offset[1:].split(':')
offset_seconds = int(offset_parts[0]) * 3600 offset_seconds = int(offset_parts[0]) * 3600
offset_seconds = offset_seconds + int(offset_parts[1]) * 60 #noqa offset_seconds = offset_seconds + int(offset_parts[1]) * 60 # noqa
if date_offset[0] == '-': if date_offset[0] == '-':
seconds_since_epoch - offset_seconds seconds_since_epoch - offset_seconds
elif date_offset[0] == '+': elif date_offset[0] == '+':