From cb38bf517614ae8a3ec6ecc16ffe48f2b3be607f Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Fri, 24 Jun 2016 00:31:58 -0400 Subject: [PATCH] Fix numerous flake8 warnings --- .pre-commit | 2 +- elodie/geolocation.py | 6 +++--- elodie/media/media.py | 22 ++++++++-------------- elodie/media/photo.py | 6 ++---- elodie/media/video.py | 15 ++++----------- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/.pre-commit b/.pre-commit index 76f60de..12c1810 100755 --- a/.pre-commit +++ b/.pre-commit @@ -1,3 +1,3 @@ #!/usr/bin/env bash -flake8 elodie --exclude=tests && nosetests -w elodie/tests +flake8 elodie --exclude=tests,external && nosetests -w elodie/tests diff --git a/elodie/geolocation.py b/elodie/geolocation.py index f83bdd1..158a931 100644 --- a/elodie/geolocation.py +++ b/elodie/geolocation.py @@ -76,11 +76,11 @@ def coordinates_by_name(name): def decimal_to_dms(decimal): decimal = float(decimal) decimal_abs = abs(decimal) - minutes,seconds = divmod(decimal_abs*3600,60) - degrees,minutes = divmod(minutes,60) + minutes, seconds = divmod(decimal_abs*3600, 60) + degrees, minutes = divmod(minutes, 60) degrees = degrees 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=' '): diff --git a/elodie/media/media.py b/elodie/media/media.py index 2bb7846..2e8f9b6 100644 --- a/elodie/media/media.py +++ b/elodie/media/media.py @@ -15,10 +15,6 @@ from elodie.dependencies import get_exiftool from elodie.external.pyexiftool import ExifTool from elodie.media.base import Base -import os -import re -import subprocess - class Media(Base): @@ -92,12 +88,16 @@ class Media(Base): for key in self.latitude_keys + self.longitude_keys: # TODO: verify that we need to check ref key # when self.set_gps_ref != True - if type == 'latitude' and key in self.latitude_keys and key in exif: - if self.latitude_ref_key in exif and exif[self.latitude_ref_key] == 'S': #noqa + if type == 'latitude' and key in self.latitude_keys and \ + key in exif: + if self.latitude_ref_key in exif and \ + exif[self.latitude_ref_key] == 'S': direction_multiplier = -1 return exif[key] * direction_multiplier - elif type == 'longitude' and key in self.longitude_keys and key in exif: #noqa - if self.longitude_ref_key in exif and exif[self.longitude_ref_key] == 'W': #noqa + elif type == 'longitude' and key in self.longitude_keys and \ + key in exif: + if self.longitude_ref_key in exif and \ + exif[self.longitude_ref_key] == 'W': direction_multiplier = -1 return exif[key] * direction_multiplier @@ -170,8 +170,6 @@ class Media(Base): if(time is None): return False - source = self.source - tags = {} formatted_time = time.strftime('%Y:%m:%d %H:%M:%S') for key in self.exif_map['date_taken']: @@ -185,8 +183,6 @@ class Media(Base): if(not self.is_valid()): return None - source = self.source - # The lat/lon _keys array has an order of precedence. # The first key is writable and we will give the writable # key precence when reading. @@ -222,8 +218,6 @@ class Media(Base): if(title is None): return None - source = self.source - tags = {self.title_key: title} status = self.__set_tags(tags) self.reset_cache() diff --git a/elodie/media/photo.py b/elodie/media/photo.py index 5d994e6..99b27a5 100644 --- a/elodie/media/photo.py +++ b/elodie/media/photo.py @@ -15,8 +15,6 @@ from re import compile from elodie import constants -from elodie import geolocation -from elodie.external.pyexiftool import ExifTool from media import Media @@ -69,7 +67,7 @@ class Photo(Media): """ if(not self.is_valid()): return None - + source = self.source 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. # EXIF DateTimeOriginal and EXIF DateTime are both stored # 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 # EXIF DateTime is already stored as a timestamp # Sourced from https://github.com/photo/frontend/blob/master/src/libraries/models/Photo.php#L500 # noqa diff --git a/elodie/media/video.py b/elodie/media/video.py index 7083294..b49f50a 100644 --- a/elodie/media/video.py +++ b/elodie/media/video.py @@ -7,19 +7,12 @@ objects (AVI, MOV, etc.). # load modules from distutils.spawn import find_executable -import tempfile from datetime import datetime import os import re -import shutil -import subprocess 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 @@ -45,12 +38,12 @@ class Video(Media): self.title_key = 'XMP:DisplayName' self.latitude_keys = [ 'XMP:GPSLatitude', - #'QuickTime:GPSLatitude', + # 'QuickTime:GPSLatitude', 'Composite:GPSLatitude' ] self.longitude_keys = [ 'XMP:GPSLongitude', - #'QuickTime:GPSLongitude', + # 'QuickTime:GPSLongitude', 'Composite:GPSLongitude' ] self.latitude_ref_key = 'EXIF:GPSLatitudeRef' @@ -81,7 +74,7 @@ class Video(Media): """ if(not self.is_valid()): return None - + source = self.source 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: offset_parts = date_offset[1:].split(':') 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] == '-': seconds_since_epoch - offset_seconds elif date_offset[0] == '+':