fix pyflakes warnings reported in non-test files

This commit is contained in:
Fabrice Laporte 2016-01-02 18:34:43 +01:00
parent 64695fea08
commit b01b611d26
7 changed files with 31 additions and 47 deletions

View File

@ -99,10 +99,10 @@ class FileSystem:
# This helps when re-running the program on file which were already # This helps when re-running the program on file which were already
# processed. # processed.
base_name = re.sub( base_name = re.sub(
'^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-', '^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-',
'', '',
metadata['base_name'] metadata['base_name']
) )
if(len(base_name) == 0): if(len(base_name) == 0):
base_name = metadata['base_name'] base_name = metadata['base_name']
@ -116,13 +116,12 @@ class FileSystem:
base_name = '%s-%s' % (base_name, title_sanitized) base_name = '%s-%s' % (base_name, title_sanitized)
file_name = '%s-%s.%s' % ( file_name = '%s-%s.%s' % (
time.strftime( time.strftime(
'%Y-%m-%d_%H-%M-%S', '%Y-%m-%d_%H-%M-%S',
metadata['date_taken'] metadata['date_taken']
), ),
base_name, base_name,
metadata['extension'] metadata['extension'])
)
return file_name.lower() return file_name.lower()
""" """
@ -170,9 +169,9 @@ class FileSystem:
if('move' in kwargs): if('move' in kwargs):
move = kwargs['move'] move = kwargs['move']
allowDuplicate = False allow_duplicate = False
if('allowDuplicate' in kwargs): if('allowDuplicate' in kwargs):
allowDuplicate = kwargs['allowDuplicate'] allow_duplicate = kwargs['allowDuplicate']
metadata = media.get_metadata() metadata = media.get_metadata()
@ -191,7 +190,7 @@ class FileSystem:
# If duplicates are not allowed and this hash exists in the db then we # If duplicates are not allowed and this hash exists in the db then we
# return # 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): if(constants.debug is True):
print '%s already exists at %s. Skipping...' % ( print '%s already exists at %s. Skipping...' % (
_file, _file,

View File

@ -3,9 +3,7 @@ from ConfigParser import ConfigParser
import fractions import fractions
import pyexiv2 import pyexiv2
import math
import requests import requests
import sys
import urllib import urllib
from elodie import constants from elodie import constants
@ -30,8 +28,8 @@ def coordinates_by_name(name):
cached_coordinates = db.get_location_coordinates(name) cached_coordinates = db.get_location_coordinates(name)
if(cached_coordinates is not None): if(cached_coordinates is not None):
return { return {
'latitude': cached_coordinates[0], 'latitude': cached_coordinates[0],
'longitude': cached_coordinates[1] 'longitude': cached_coordinates[1]
} }
# If the name is not cached then we go ahead with an API lookup # If the name is not cached then we go ahead with an API lookup
@ -63,8 +61,8 @@ def coordinates_by_name(name):
break break
return { return {
'latitude': use_location['lat'], 'latitude': use_location['lat'],
'longitude': use_location['lng'] 'longitude': use_location['lng']
} }
return None return None

View File

@ -108,10 +108,10 @@ class Db(object):
[longitude, latitude, data['long'], data['lat']] [longitude, latitude, data['long'], data['lat']]
) )
R = 6371000 # radius of the earth in m r = 6371000 # radius of the earth in m
x = (lon2 - lon1) * cos(0.5*(lat2+lat1)) x = (lon2 - lon1) * cos(0.5 * (lat2 + lat1))
y = 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 # Use if closer then threshold_km reuse lookup
if(d <= threshold_m and d < last_d): if(d <= threshold_m and d < last_d):
name = data['name'] name = data['name']

View File

@ -4,18 +4,14 @@ Media package that's a parent class for media objects
""" """
# load modules # load modules
from datetime import datetime
from distutils.spawn import find_executable from distutils.spawn import find_executable
from elodie import constants from elodie import constants
from fractions import Fraction
from sys import argv
import mimetypes import mimetypes
import os import os
import pyexiv2 import pyexiv2
import re import re
import subprocess import subprocess
import time
class Media(object): class Media(object):
@ -241,7 +237,7 @@ class Media(object):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
shell=True shell=True
) )
streamdata = process_output.communicate()[0] process_output.communicate()
if(process_output.returncode != 0): if(process_output.returncode != 0):
return False return False
@ -299,7 +295,7 @@ class Media(object):
self.metadata[key] = kwargs[key] self.metadata[key] = kwargs[key]
@classmethod @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() extension = os.path.splitext(_file)[1][1:].lower()
for i in classes: for i in classes:

View File

@ -3,12 +3,7 @@ Author: Jaisen Mathai <jaisen@jmathai.com>
Photo package that handles all photo operations Photo package that handles all photo operations
""" """
# load modules
from datetime import datetime
from sys import argv
import imghdr import imghdr
import mimetypes
import LatLon import LatLon
import os import os
import pyexiv2 import pyexiv2
@ -228,5 +223,5 @@ class Photo(Media):
@returns, tuple @returns, tuple
""" """
@classmethod @classmethod
def get_valid_extensions(Photo): def get_valid_extensions(cls):
return Photo.extensions return cls.extensions

View File

@ -6,10 +6,8 @@ Video package that handles all video operations
# load modules # load modules
from distutils.spawn import find_executable from distutils.spawn import find_executable
import tempfile import tempfile
from sys import argv
from datetime import datetime from datetime import datetime
import mimetypes
import os import os
import re import re
import shutil import shutil
@ -90,7 +88,6 @@ class Video(Media):
# conversion in the local timezone # conversion in the local timezone
# If the time is not found in EXIF we update EXIF # If the time is not found in EXIF we update EXIF
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
time_found_in_exif = False
exif_data = self.get_exif() exif_data = self.get_exif()
for key in ['Creation Date', 'Media Create Date']: for key in ['Creation Date', 'Media Create Date']:
date = re.search('%s +: +([0-9: ]+)' % key, exif_data) date = re.search('%s +: +([0-9: ]+)' % key, exif_data)
@ -105,7 +102,6 @@ class Video(Media):
) )
if(exif_seconds_since_epoch < seconds_since_epoch): if(exif_seconds_since_epoch < seconds_since_epoch):
seconds_since_epoch = exif_seconds_since_epoch seconds_since_epoch = exif_seconds_since_epoch
time_found_in_exif = True
break break
except: except:
pass pass
@ -278,7 +274,7 @@ class Video(Media):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
shell=True shell=True
) )
streamdata = write_process.communicate()[0] write_process.communicate()
if(write_process.returncode != 0): if(write_process.returncode != 0):
if(constants.debug is True): if(constants.debug is True):
print 'Failed to generate plist file' print 'Failed to generate plist file'
@ -367,7 +363,7 @@ class Video(Media):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
shell=True shell=True
) )
streamdata = update_process.communicate()[0] update_process.communicate()
if(update_process.returncode != 0): if(update_process.returncode != 0):
if(constants.debug is True): if(constants.debug is True):
print '%s did not complete successfully' % avmetareadwrite_command # noqa print '%s did not complete successfully' % avmetareadwrite_command # noqa
@ -384,8 +380,8 @@ class Video(Media):
check_metadata['latitude'] is None and check_metadata['latitude'] is None and
check_metadata['longitude'] is None check_metadata['longitude'] is None
) or ( ) or (
'time' in kwargs and 'time' in kwargs and
check_metadata['date_taken'] is None check_metadata['date_taken'] is None
) )
): ):
if(constants.debug is True): if(constants.debug is True):
@ -407,8 +403,8 @@ class Video(Media):
@returns, tuple @returns, tuple
""" """
@classmethod @classmethod
def get_valid_extensions(Video): def get_valid_extensions(cls):
return Video.extensions return cls.extensions
class Transcode(object): class Transcode(object):

View File

@ -13,7 +13,7 @@ import plistlib
class Plist(object): class Plist(object):
def __init__(self, source): def __init__(self, source):
if(path.isfile(source) == False): if not path.isfile(source):
raise IOError('Could not load plist file %s' % source) raise IOError('Could not load plist file %s' % source)
self.source = source self.source = source