mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-20 16:03:59 +01:00
manual pep8 W291,W293,W391 blank lines, trailing whitespace
This commit is contained in:
@@ -33,7 +33,7 @@ class AuthURLOpener(HeadphonesURLopener):
|
|||||||
"""
|
"""
|
||||||
URLOpener class that supports http auth without needing interactive password entry.
|
URLOpener class that supports http auth without needing interactive password entry.
|
||||||
If the provided username/password don't work it simply fails.
|
If the provided username/password don't work it simply fails.
|
||||||
|
|
||||||
user: username to use for HTTP auth
|
user: username to use for HTTP auth
|
||||||
pw: password to use for HTTP auth
|
pw: password to use for HTTP auth
|
||||||
"""
|
"""
|
||||||
@@ -44,7 +44,7 @@ class AuthURLOpener(HeadphonesURLopener):
|
|||||||
|
|
||||||
# remember if we've tried the username/password before
|
# remember if we've tried the username/password before
|
||||||
self.numTries = 0
|
self.numTries = 0
|
||||||
|
|
||||||
# call the base class
|
# call the base class
|
||||||
urllib.FancyURLopener.__init__(self)
|
urllib.FancyURLopener.__init__(self)
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ class AuthURLOpener(HeadphonesURLopener):
|
|||||||
if self.numTries == 0:
|
if self.numTries == 0:
|
||||||
self.numTries = 1
|
self.numTries = 1
|
||||||
return (self.username, self.password)
|
return (self.username, self.password)
|
||||||
|
|
||||||
# if we've tried before then return blank which cancels the request
|
# if we've tried before then return blank which cancels the request
|
||||||
else:
|
else:
|
||||||
return ('', '')
|
return ('', '')
|
||||||
|
|||||||
+15
-17
@@ -198,7 +198,7 @@ class Directory:
|
|||||||
if c.__class__.__name__ == classname:
|
if c.__class__.__name__ == classname:
|
||||||
content.append(c)
|
content.append(c)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def tracks(self, ext=None, split=False):
|
def tracks(self, ext=None, split=False):
|
||||||
content = []
|
content = []
|
||||||
for c in self.content:
|
for c in self.content:
|
||||||
@@ -210,14 +210,14 @@ class Directory:
|
|||||||
if not split or (split and c.split_file):
|
if not split or (split and c.split_file):
|
||||||
content.append(c)
|
content.append(c)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
def check_match(filename):
|
def check_match(filename):
|
||||||
for i in self.content:
|
for i in self.content:
|
||||||
if i.name == filename:
|
if i.name == filename:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def identify_track_number(filename):
|
def identify_track_number(filename):
|
||||||
if 'split-track' in filename:
|
if 'split-track' in filename:
|
||||||
search = re.search('split-track(\d\d)', filename)
|
search = re.search('split-track(\d\d)', filename)
|
||||||
@@ -232,7 +232,7 @@ class Directory:
|
|||||||
return n
|
return n
|
||||||
|
|
||||||
list_dir = glob.glob(os.path.join(self.path, '*'))
|
list_dir = glob.glob(os.path.join(self.path, '*'))
|
||||||
|
|
||||||
# TODO: for some reason removes only one file
|
# TODO: for some reason removes only one file
|
||||||
rem_list = []
|
rem_list = []
|
||||||
for i in self.content:
|
for i in self.content:
|
||||||
@@ -240,7 +240,7 @@ class Directory:
|
|||||||
rem_list.append(i)
|
rem_list.append(i)
|
||||||
for i in rem_list:
|
for i in rem_list:
|
||||||
self.content.remove(i)
|
self.content.remove(i)
|
||||||
|
|
||||||
for i in list_dir:
|
for i in list_dir:
|
||||||
if not check_match(i):
|
if not check_match(i):
|
||||||
# music file
|
# music file
|
||||||
@@ -250,7 +250,7 @@ class Directory:
|
|||||||
self.content.append(WaveFile(self.path + os.sep + i, track_nr=track_nr))
|
self.content.append(WaveFile(self.path + os.sep + i, track_nr=track_nr))
|
||||||
else:
|
else:
|
||||||
self.content.append(WaveFile(self.path + os.sep + i))
|
self.content.append(WaveFile(self.path + os.sep + i))
|
||||||
|
|
||||||
# cue file
|
# cue file
|
||||||
elif os.path.splitext(i)[-1] == '.cue':
|
elif os.path.splitext(i)[-1] == '.cue':
|
||||||
self.content.append(CueFile(self.path + os.sep + i))
|
self.content.append(CueFile(self.path + os.sep + i))
|
||||||
@@ -258,11 +258,11 @@ class Directory:
|
|||||||
# meta file
|
# meta file
|
||||||
elif i == ALBUM_META_FILE_NAME:
|
elif i == ALBUM_META_FILE_NAME:
|
||||||
self.content.append(MetaFile(self.path + os.sep + i))
|
self.content.append(MetaFile(self.path + os.sep + i))
|
||||||
|
|
||||||
# directory
|
# directory
|
||||||
elif os.path.isdir(i):
|
elif os.path.isdir(i):
|
||||||
self.content.append(Directory(self.path + os.sep + i))
|
self.content.append(Directory(self.path + os.sep + i))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.content.append(File(self.path + os.sep + i))
|
self.content.append(File(self.path + os.sep + i))
|
||||||
|
|
||||||
@@ -451,7 +451,7 @@ class MetaFile(File):
|
|||||||
|
|
||||||
content = {}
|
content = {}
|
||||||
content['tracks'] = [None for m in range(100)]
|
content['tracks'] = [None for m in range(100)]
|
||||||
|
|
||||||
for l in self.rawcontent.splitlines():
|
for l in self.rawcontent.splitlines():
|
||||||
parsed_line = re.search('^(.+?)\t(.+?)$', l)
|
parsed_line = re.search('^(.+?)\t(.+?)$', l)
|
||||||
if parsed_line:
|
if parsed_line:
|
||||||
@@ -464,11 +464,11 @@ class MetaFile(File):
|
|||||||
content['tracks'][int(parsed_track.group(1))][parsed_track.group(2)] = parsed_line.group(2)
|
content['tracks'][int(parsed_track.group(1))][parsed_track.group(2)] = parsed_line.group(2)
|
||||||
else:
|
else:
|
||||||
content[parsed_line.group(1)] = parsed_line.group(2)
|
content[parsed_line.group(1)] = parsed_line.group(2)
|
||||||
|
|
||||||
content['tracks'] = check_list(content['tracks'], ignore=1)
|
content['tracks'] = check_list(content['tracks'], ignore=1)
|
||||||
|
|
||||||
self.content = content
|
self.content = content
|
||||||
|
|
||||||
def flac_tags(self, track_nr):
|
def flac_tags(self, track_nr):
|
||||||
common_tags = dict()
|
common_tags = dict()
|
||||||
freeform_tags = dict()
|
freeform_tags = dict()
|
||||||
@@ -494,7 +494,7 @@ class MetaFile(File):
|
|||||||
artist = self.content['artist']
|
artist = self.content['artist']
|
||||||
album = self.content['date'] + ' - ' + self.content['title'] + ' (' + self.content['label'] + ' - ' + self.content['catalog'] + ')'
|
album = self.content['date'] + ' - ' + self.content['title'] + ' (' + self.content['label'] + ' - ' + self.content['catalog'] + ')'
|
||||||
return artist, album
|
return artist, album
|
||||||
|
|
||||||
def complete(self):
|
def complete(self):
|
||||||
'''Check MetaFile for containing all data'''
|
'''Check MetaFile for containing all data'''
|
||||||
self.__init__(self.path)
|
self.__init__(self.path)
|
||||||
@@ -502,7 +502,7 @@ class MetaFile(File):
|
|||||||
if re.search('^[0-9A-Za-z]+?\t$', l):
|
if re.search('^[0-9A-Za-z]+?\t$', l):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def count_tracks(self):
|
def count_tracks(self):
|
||||||
'''Returns tracks count'''
|
'''Returns tracks count'''
|
||||||
return len(self.content['tracks']) - self.content['tracks'].count(None)
|
return len(self.content['tracks']) - self.content['tracks'].count(None)
|
||||||
@@ -518,7 +518,7 @@ class WaveFile(File):
|
|||||||
def filename(self, ext=None, cmd=False):
|
def filename(self, ext=None, cmd=False):
|
||||||
title = meta.content['tracks'][self.track_nr]['title']
|
title = meta.content['tracks'][self.track_nr]['title']
|
||||||
|
|
||||||
if ext:
|
if ext:
|
||||||
if ext[0] != '.':
|
if ext[0] != '.':
|
||||||
ext = '.' + ext
|
ext = '.' + ext
|
||||||
else:
|
else:
|
||||||
@@ -673,5 +673,3 @@ def split(albumpath):
|
|||||||
# Rename original file
|
# Rename original file
|
||||||
os.rename(wave.name, wave.name + '.original')
|
os.rename(wave.name, wave.name + '.original')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -62,14 +62,14 @@ class DBConnection:
|
|||||||
return
|
return
|
||||||
|
|
||||||
sqlResult = None
|
sqlResult = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with self.connection as c:
|
with self.connection as c:
|
||||||
if args == None:
|
if args == None:
|
||||||
sqlResult = c.execute(query)
|
sqlResult = c.execute(query)
|
||||||
else:
|
else:
|
||||||
sqlResult = c.execute(query, args)
|
sqlResult = c.execute(query, args)
|
||||||
|
|
||||||
except sqlite3.OperationalError, e:
|
except sqlite3.OperationalError, e:
|
||||||
if "unable to open database file" in e.message or "database is locked" in e.message:
|
if "unable to open database file" in e.message or "database is locked" in e.message:
|
||||||
logger.warn('Database Error: %s', e)
|
logger.warn('Database Error: %s', e)
|
||||||
@@ -80,13 +80,13 @@ class DBConnection:
|
|||||||
except sqlite3.DatabaseError, e:
|
except sqlite3.DatabaseError, e:
|
||||||
logger.error('Fatal Error executing %s :: %s', query, e)
|
logger.error('Fatal Error executing %s :: %s', query, e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return sqlResult
|
return sqlResult
|
||||||
|
|
||||||
def select(self, query, args=None):
|
def select(self, query, args=None):
|
||||||
|
|
||||||
sqlResults = self.action(query, args).fetchall()
|
sqlResults = self.action(query, args).fetchall()
|
||||||
|
|
||||||
if sqlResults == None or sqlResults == [None]:
|
if sqlResults == None or sqlResults == [None]:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -95,11 +95,11 @@ def sendNZB(nzb):
|
|||||||
except httplib.InvalidURL, e:
|
except httplib.InvalidURL, e:
|
||||||
logger.error(u"Invalid SAB host, check your config. Current host: %s" % headphones.CONFIG.SAB_HOST)
|
logger.error(u"Invalid SAB host, check your config. Current host: %s" % headphones.CONFIG.SAB_HOST)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error(u"Error: " + str(e))
|
logger.error(u"Error: " + str(e))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if f == None:
|
if f == None:
|
||||||
logger.info(u"No data returned from SABnzbd, NZB not sent")
|
logger.info(u"No data returned from SABnzbd, NZB not sent")
|
||||||
return False
|
return False
|
||||||
@@ -127,12 +127,12 @@ def sendNZB(nzb):
|
|||||||
else:
|
else:
|
||||||
logger.info(u"Unknown failure sending NZB to sab. Return text is: " + sabText)
|
logger.info(u"Unknown failure sending NZB to sab. Return text is: " + sabText)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def checkConfig():
|
def checkConfig():
|
||||||
|
|
||||||
params = { 'mode': 'get_config',
|
params = { 'mode': 'get_config',
|
||||||
'section': 'misc'
|
'section': 'misc'
|
||||||
}
|
}
|
||||||
|
|
||||||
if headphones.CONFIG.SAB_USERNAME:
|
if headphones.CONFIG.SAB_USERNAME:
|
||||||
@@ -147,18 +147,18 @@ def checkConfig():
|
|||||||
|
|
||||||
if headphones.CONFIG.SAB_HOST.endswith('/'):
|
if headphones.CONFIG.SAB_HOST.endswith('/'):
|
||||||
headphones.CONFIG.SAB_HOST = headphones.CONFIG.SAB_HOST[0:len(headphones.CONFIG.SAB_HOST)-1]
|
headphones.CONFIG.SAB_HOST = headphones.CONFIG.SAB_HOST[0:len(headphones.CONFIG.SAB_HOST)-1]
|
||||||
|
|
||||||
url = headphones.CONFIG.SAB_HOST + "/" + "api?" + urllib.urlencode(params)
|
url = headphones.CONFIG.SAB_HOST + "/" + "api?" + urllib.urlencode(params)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = urllib.urlopen(url).read()
|
f = urllib.urlopen(url).read()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.warn("Unable to read SABnzbd config file - cannot determine renaming options (might affect auto & forced post processing)")
|
logger.warn("Unable to read SABnzbd config file - cannot determine renaming options (might affect auto & forced post processing)")
|
||||||
return (0, 0)
|
return (0, 0)
|
||||||
|
|
||||||
config_options = ast.literal_eval(f)
|
config_options = ast.literal_eval(f)
|
||||||
|
|
||||||
replace_spaces = config_options['misc']['replace_spaces']
|
replace_spaces = config_options['misc']['replace_spaces']
|
||||||
replace_dots = config_options['misc']['replace_dots']
|
replace_dots = config_options['misc']['replace_dots']
|
||||||
|
|
||||||
return (replace_spaces, replace_dots)
|
return (replace_spaces, replace_dots)
|
||||||
|
|||||||
@@ -347,4 +347,3 @@ class Rutracker():
|
|||||||
except Exception:
|
except Exception:
|
||||||
logger.exception('Error adding file to utorrent')
|
logger.exception('Error adding file to utorrent')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -260,4 +260,3 @@ def getSettingsDirectories():
|
|||||||
if 'dir_completed_download' in settings:
|
if 'dir_completed_download' in settings:
|
||||||
completed = settings['dir_completed_download'][2]
|
completed = settings['dir_completed_download'][2]
|
||||||
return active, completed
|
return active, completed
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user