From b01b611d26e603538e4342c2489b8089f69f03f9 Mon Sep 17 00:00:00 2001 From: Fabrice Laporte Date: Sat, 2 Jan 2016 18:34:43 +0100 Subject: [PATCH] fix pyflakes warnings reported in non-test files --- elodie/filesystem.py | 27 +++++++++++++-------------- elodie/geolocation.py | 10 ++++------ elodie/localstorage.py | 6 +++--- elodie/media/media.py | 8 ++------ elodie/media/photo.py | 9 ++------- elodie/media/video.py | 16 ++++++---------- elodie/plist_parser.py | 2 +- 7 files changed, 31 insertions(+), 47 deletions(-) diff --git a/elodie/filesystem.py b/elodie/filesystem.py index 9d56fa8..435d7ff 100644 --- a/elodie/filesystem.py +++ b/elodie/filesystem.py @@ -99,10 +99,10 @@ class FileSystem: # This helps when re-running the program on file which were already # processed. base_name = re.sub( - '^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-', - '', - metadata['base_name'] - ) + '^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-', + '', + metadata['base_name'] + ) if(len(base_name) == 0): base_name = metadata['base_name'] @@ -116,13 +116,12 @@ class FileSystem: base_name = '%s-%s' % (base_name, title_sanitized) file_name = '%s-%s.%s' % ( - time.strftime( - '%Y-%m-%d_%H-%M-%S', - metadata['date_taken'] - ), - base_name, - metadata['extension'] - ) + time.strftime( + '%Y-%m-%d_%H-%M-%S', + metadata['date_taken'] + ), + base_name, + metadata['extension']) return file_name.lower() """ @@ -170,9 +169,9 @@ class FileSystem: if('move' in kwargs): move = kwargs['move'] - allowDuplicate = False + allow_duplicate = False if('allowDuplicate' in kwargs): - allowDuplicate = kwargs['allowDuplicate'] + allow_duplicate = kwargs['allowDuplicate'] metadata = media.get_metadata() @@ -191,7 +190,7 @@ class FileSystem: # If duplicates are not allowed and this hash exists in the db then we # return - if(allowDuplicate is False and db.check_hash(checksum) is True): + if(allow_duplicate is False and db.check_hash(checksum) is True): if(constants.debug is True): print '%s already exists at %s. Skipping...' % ( _file, diff --git a/elodie/geolocation.py b/elodie/geolocation.py index 458b398..54ace59 100644 --- a/elodie/geolocation.py +++ b/elodie/geolocation.py @@ -3,9 +3,7 @@ from ConfigParser import ConfigParser import fractions import pyexiv2 -import math import requests -import sys import urllib from elodie import constants @@ -30,8 +28,8 @@ def coordinates_by_name(name): cached_coordinates = db.get_location_coordinates(name) if(cached_coordinates is not None): return { - 'latitude': cached_coordinates[0], - 'longitude': cached_coordinates[1] + 'latitude': cached_coordinates[0], + 'longitude': cached_coordinates[1] } # If the name is not cached then we go ahead with an API lookup @@ -63,8 +61,8 @@ def coordinates_by_name(name): break return { - 'latitude': use_location['lat'], - 'longitude': use_location['lng'] + 'latitude': use_location['lat'], + 'longitude': use_location['lng'] } return None diff --git a/elodie/localstorage.py b/elodie/localstorage.py index 93080fd..8a9342a 100644 --- a/elodie/localstorage.py +++ b/elodie/localstorage.py @@ -108,10 +108,10 @@ class Db(object): [longitude, latitude, data['long'], data['lat']] ) - R = 6371000 # radius of the earth in m - x = (lon2 - lon1) * cos(0.5*(lat2+lat1)) + r = 6371000 # radius of the earth in m + x = (lon2 - lon1) * cos(0.5 * (lat2 + lat1)) y = lat2 - lat1 - d = R * sqrt(x*x + y*y) + d = r * sqrt(x * x + y * y) # Use if closer then threshold_km reuse lookup if(d <= threshold_m and d < last_d): name = data['name'] diff --git a/elodie/media/media.py b/elodie/media/media.py index 2cb18d0..484305b 100644 --- a/elodie/media/media.py +++ b/elodie/media/media.py @@ -4,18 +4,14 @@ Media package that's a parent class for media objects """ # load modules -from datetime import datetime from distutils.spawn import find_executable from elodie import constants -from fractions import Fraction -from sys import argv import mimetypes import os import pyexiv2 import re import subprocess -import time class Media(object): @@ -241,7 +237,7 @@ class Media(object): stdout=subprocess.PIPE, shell=True ) - streamdata = process_output.communicate()[0] + process_output.communicate() if(process_output.returncode != 0): return False @@ -299,7 +295,7 @@ class Media(object): self.metadata[key] = kwargs[key] @classmethod - def get_class_by_file(Media, _file, classes): + def get_class_by_file(cls, _file, classes): extension = os.path.splitext(_file)[1][1:].lower() for i in classes: diff --git a/elodie/media/photo.py b/elodie/media/photo.py index 3adcaf0..d17501a 100644 --- a/elodie/media/photo.py +++ b/elodie/media/photo.py @@ -3,12 +3,7 @@ Author: Jaisen Mathai Photo package that handles all photo operations """ -# load modules -from datetime import datetime -from sys import argv - import imghdr -import mimetypes import LatLon import os import pyexiv2 @@ -228,5 +223,5 @@ class Photo(Media): @returns, tuple """ @classmethod - def get_valid_extensions(Photo): - return Photo.extensions + def get_valid_extensions(cls): + return cls.extensions diff --git a/elodie/media/video.py b/elodie/media/video.py index ea2d65e..3e7d9bd 100644 --- a/elodie/media/video.py +++ b/elodie/media/video.py @@ -6,10 +6,8 @@ Video package that handles all video operations # load modules from distutils.spawn import find_executable import tempfile -from sys import argv from datetime import datetime -import mimetypes import os import re import shutil @@ -90,7 +88,6 @@ class Video(Media): # conversion in the local timezone # If the time is not found in EXIF we update EXIF seconds_since_epoch = min(os.path.getmtime(source), os.path.getctime(source)) # noqa - time_found_in_exif = False exif_data = self.get_exif() for key in ['Creation Date', 'Media Create Date']: date = re.search('%s +: +([0-9: ]+)' % key, exif_data) @@ -105,7 +102,6 @@ class Video(Media): ) if(exif_seconds_since_epoch < seconds_since_epoch): seconds_since_epoch = exif_seconds_since_epoch - time_found_in_exif = True break except: pass @@ -278,7 +274,7 @@ class Video(Media): stdout=subprocess.PIPE, shell=True ) - streamdata = write_process.communicate()[0] + write_process.communicate() if(write_process.returncode != 0): if(constants.debug is True): print 'Failed to generate plist file' @@ -367,7 +363,7 @@ class Video(Media): stdout=subprocess.PIPE, shell=True ) - streamdata = update_process.communicate()[0] + update_process.communicate() if(update_process.returncode != 0): if(constants.debug is True): print '%s did not complete successfully' % avmetareadwrite_command # noqa @@ -384,8 +380,8 @@ class Video(Media): check_metadata['latitude'] is None and check_metadata['longitude'] is None ) or ( - 'time' in kwargs and - check_metadata['date_taken'] is None + 'time' in kwargs and + check_metadata['date_taken'] is None ) ): if(constants.debug is True): @@ -407,8 +403,8 @@ class Video(Media): @returns, tuple """ @classmethod - def get_valid_extensions(Video): - return Video.extensions + def get_valid_extensions(cls): + return cls.extensions class Transcode(object): diff --git a/elodie/plist_parser.py b/elodie/plist_parser.py index e20d813..530c5d5 100644 --- a/elodie/plist_parser.py +++ b/elodie/plist_parser.py @@ -13,7 +13,7 @@ import plistlib class Plist(object): def __init__(self, source): - if(path.isfile(source) == False): + if not path.isfile(source): raise IOError('Could not load plist file %s' % source) self.source = source