First attempt to replace logger methods with lazy evaluating version

Forgot to format the message
This commit is contained in:
Bas Stottelaar
2014-04-01 14:33:34 +02:00
parent 89aff6e199
commit 2add9fa264
11 changed files with 84 additions and 87 deletions
+2 -2
View File
@@ -146,7 +146,7 @@ def main():
# Force the http port if neccessary # Force the http port if neccessary
if args.port: if args.port:
http_port = args.port http_port = args.port
logger.info('Using forced port: %i' % http_port) logger.info('Using forced port: %i', http_port)
else: else:
http_port = int(headphones.HTTP_PORT) http_port = int(headphones.HTTP_PORT)
@@ -176,7 +176,7 @@ def main():
except KeyboardInterrupt: except KeyboardInterrupt:
headphones.SIGNAL = 'shutdown' headphones.SIGNAL = 'shutdown'
else: else:
logger.info('Received signal: ' + headphones.SIGNAL) logger.info('Received signal: %d', headphones.SIGNAL)
if headphones.SIGNAL == 'shutdown': if headphones.SIGNAL == 'shutdown':
headphones.shutdown() headphones.shutdown()
elif headphones.SIGNAL == 'restart': elif headphones.SIGNAL == 'restart':
+14 -16
View File
@@ -306,7 +306,7 @@ def check_setting_int(config, cfg_name, item_name, def_val):
except: except:
config[cfg_name] = {} config[cfg_name] = {}
config[cfg_name][item_name] = my_val config[cfg_name][item_name] = my_val
logger.debug(item_name + " -> " + str(my_val)) logger.debug("%s -> %s", item_name, my_val)
return my_val return my_val
################################################################################ ################################################################################
@@ -323,10 +323,7 @@ def check_setting_str(config, cfg_name, item_name, def_val, log=True):
config[cfg_name] = {} config[cfg_name] = {}
config[cfg_name][item_name] = my_val config[cfg_name][item_name] = my_val
if log: logger.debug("%s -> %s", item_name, my_val if log else "******")
logger.debug(item_name + " -> " + my_val)
else:
logger.debug(item_name + " -> ******")
return my_val return my_val
def initialize(): def initialize():
@@ -702,7 +699,7 @@ def initialize():
try: try:
os.makedirs(CACHE_DIR) os.makedirs(CACHE_DIR)
except OSError: except OSError:
logger.error('Could not create cache dir. Check permissions of datadir: ' + DATA_DIR) logger.error('Could not create cache dir. Check permissions of datadir: %s', DATA_DIR)
# Sanity check for search interval. Set it to at least 6 hours # Sanity check for search interval. Set it to at least 6 hours
if SEARCH_INTERVAL < 360: if SEARCH_INTERVAL < 360:
@@ -714,7 +711,7 @@ def initialize():
try: try:
dbcheck() dbcheck()
except Exception, e: except Exception, e:
logger.error("Can't connect to the database: %s" % e) logger.error("Can't connect to the database: %s", e)
# Get the currently installed version - returns None, 'win32' or the git hash # Get the currently installed version - returns None, 'win32' or the git hash
# Also sets INSTALL_TYPE variable to 'win', 'git' or 'source' # Also sets INSTALL_TYPE variable to 'win', 'git' or 'source'
@@ -751,7 +748,7 @@ def daemonize():
if pid != 0: if pid != 0:
sys.exit(0) sys.exit(0)
except OSError, e: except OSError, e:
raise RuntimeError("1st fork failed: %s [%d]" % (e.strerror, e.errno)) raise RuntimeError("1st fork failed: %s [%d]", e.strerror, e.errno)
os.setsid() os.setsid()
@@ -765,7 +762,7 @@ def daemonize():
if pid != 0: if pid != 0:
sys.exit(0) sys.exit(0)
except OSError, e: except OSError, e:
raise RuntimeError("2nd fork failed: %s [%d]" % (e.strerror, e.errno)) raise RuntimeError("2nd fork failed: %s [%d]", e.strerror, e.errno)
dev_null = file('/dev/null', 'r') dev_null = file('/dev/null', 'r')
os.dup2(dev_null.fileno(), sys.stdin.fileno()) os.dup2(dev_null.fileno(), sys.stdin.fileno())
@@ -782,8 +779,9 @@ def daemonize():
logger.info('Daemonized to PID: %s' % pid) logger.info('Daemonized to PID: %s' % pid)
if CREATEPID: if CREATEPID:
logger.info("Writing PID " + pid + " to " + str(PIDFILE)) logger.info("Writing PID %d to %s", pid, PIDFILE)
file(PIDFILE, 'w').write("%s\n" % pid) with file(PIDFILE, 'w') as fp:
fp.write("%s\n" % pid)
def launch_browser(host, port, root): def launch_browser(host, port, root):
@@ -798,7 +796,7 @@ def launch_browser(host, port, root):
try: try:
webbrowser.open('%s://%s:%i%s' % (protocol, host, port, root)) webbrowser.open('%s://%s:%i%s' % (protocol, host, port, root))
except Exception, e: except Exception, e:
logger.error('Could not launch browser: %s' % e) logger.error('Could not launch browser: %s', e)
def config_write(): def config_write():
@@ -1082,7 +1080,7 @@ def start():
def sig_handler(signum=None, frame=None): def sig_handler(signum=None, frame=None):
if type(signum) != type(None): if type(signum) != type(None):
logger.info("Signal %i caught, saving and exiting..." % int(signum)) logger.info("Signal %i caught, saving and exiting...", signum)
shutdown() shutdown()
def dbcheck(): def dbcheck():
@@ -1301,10 +1299,10 @@ def shutdown(restart=False, update=False):
try: try:
versioncheck.update() versioncheck.update()
except Exception, e: except Exception, e:
logger.warn('Headphones failed to update: %s. Restarting.' % e) logger.warn('Headphones failed to update: %s. Restarting.', e)
if CREATEPID : if CREATEPID :
logger.info ('Removing pidfile %s' % PIDFILE) logger.info ('Removing pidfile %s', PIDFILE)
os.remove(PIDFILE) os.remove(PIDFILE)
if restart: if restart:
@@ -1313,7 +1311,7 @@ def shutdown(restart=False, update=False):
popen_list += ARGS popen_list += ARGS
if '--nolaunch' not in popen_list: if '--nolaunch' not in popen_list:
popen_list += ['--nolaunch'] popen_list += ['--nolaunch']
logger.info('Restarting Headphones with ' + str(popen_list)) logger.info('Restarting Headphones with %s', popen_list)
subprocess.Popen(popen_list, cwd=os.getcwd()) subprocess.Popen(popen_list, cwd=os.getcwd())
os._exit(0) os._exit(0)
+1 -1
View File
@@ -44,7 +44,7 @@ def getCachedArt(albumid):
artwork = urllib2.urlopen(artwork_path, timeout=20).read() artwork = urllib2.urlopen(artwork_path, timeout=20).read()
return artwork return artwork
except: except:
logger.warn("Unable to open url: " + artwork_path) logger.warn("Unable to open url: %s", artwork_path)
return None return None
else: else:
artwork = open(artwork_path, "r").read() artwork = open(artwork_path, "r").read()
+2 -2
View File
@@ -78,8 +78,8 @@ class Api(object):
def fetchData(self): def fetchData(self):
if self.data == 'OK': if self.data == 'OK':
logger.info('Recieved API command: ' + self.cmd) logger.info('Recieved API command: %s', self.cmd)
methodToCall = getattr(self, "_" + self.cmd) methodToCall = getattr(self, "_" + self.cmd)
result = methodToCall(**self.kwargs) result = methodToCall(**self.kwargs)
if 'callback' not in self.kwargs: if 'callback' not in self.kwargs:
+32 -32
View File
@@ -218,12 +218,12 @@ class Cache(object):
} }
url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(params) url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(params)
logger.debug('Retrieving artist information from: ' + url) logger.debug('Retrieving artist information from: %s', url)
try: try:
result = urllib2.urlopen(url, timeout=20).read() result = urllib2.urlopen(url, timeout=20).read()
except: except:
logger.warn('Could not open url: ' + url) logger.warn('Could not open url: %s', url)
return return
if result: if result:
@@ -231,18 +231,18 @@ class Cache(object):
try: try:
data = simplejson.JSONDecoder().decode(result) data = simplejson.JSONDecoder().decode(result)
except: except:
logger.warn('Could not parse data from url: ' + url) logger.warn('Could not parse data from url: %s', url)
return return
try: try:
image_url = data['artist']['image'][-1]['#text'] image_url = data['artist']['image'][-1]['#text']
except Exception: except Exception:
logger.debug('No artist image found on url: ' + url) logger.debug('No artist image found on url: %s', url)
image_url = None image_url = None
thumb_url = self._get_thumb_url(data) thumb_url = self._get_thumb_url(data)
if not thumb_url: if not thumb_url:
logger.debug('No artist thumbnail image found on url: ' + url) logger.debug('No artist thumbnail image found on url: %s', url)
else: else:
@@ -255,12 +255,12 @@ class Cache(object):
} }
url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(params) url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(params)
logger.debug('Retrieving album information from: ' + url) logger.debug('Retrieving album information from: %s', url)
try: try:
result = urllib2.urlopen(url, timeout=20).read() result = urllib2.urlopen(url, timeout=20).read()
except: except:
logger.warn('Could not open url: ' + url) logger.warn('Could not open url: %s', url)
return return
if result: if result:
@@ -268,19 +268,19 @@ class Cache(object):
try: try:
data = simplejson.JSONDecoder().decode(result) data = simplejson.JSONDecoder().decode(result)
except: except:
logger.warn('Could not parse data from url: ' + url) logger.warn('Could not parse data from url: %s', url)
return return
try: try:
image_url = data['artist']['image'][-1]['#text'] image_url = data['artist']['image'][-1]['#text']
except Exception: except Exception:
logger.debug('No artist image found on url: ' + url) logger.debug('No artist image found on url: %s', url)
image_url = None image_url = None
thumb_url = self._get_thumb_url(data) thumb_url = self._get_thumb_url(data)
if not thumb_url: if not thumb_url:
logger.debug('No artist thumbnail image found on url: ' + url) logger.debug('No artist thumbnail image found on url: %s', url)
image_dict = {'artwork' : image_url, 'thumbnail' : thumb_url } image_dict = {'artwork' : image_url, 'thumbnail' : thumb_url }
return image_dict return image_dict
@@ -301,12 +301,12 @@ class Cache(object):
} }
url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(params) url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(params)
logger.debug('Retrieving artist information from: ' + url) logger.debug('Retrieving artist information from: %s', url)
try: try:
result = urllib2.urlopen(url, timeout=20).read() result = urllib2.urlopen(url, timeout=20).read()
except: except:
logger.warn('Could not open url: ' + url) logger.warn('Could not open url: %s', url)
return return
if result: if result:
@@ -314,27 +314,27 @@ class Cache(object):
try: try:
data = simplejson.JSONDecoder().decode(result) data = simplejson.JSONDecoder().decode(result)
except: except:
logger.warn('Could not parse data from url: ' + url) logger.warn('Could not parse data from url: %s', url)
return return
try: try:
self.info_summary = data['artist']['bio']['summary'] self.info_summary = data['artist']['bio']['summary']
except Exception: except Exception:
logger.debug('No artist bio summary found on url: ' + url) logger.debug('No artist bio summary found on url: %s', url)
self.info_summary = None self.info_summary = None
try: try:
self.info_content = data['artist']['bio']['content'] self.info_content = data['artist']['bio']['content']
except Exception: except Exception:
logger.debug('No artist bio found on url: ' + url) logger.debug('No artist bio found on url: %s', url)
self.info_content = None self.info_content = None
try: try:
image_url = data['artist']['image'][-1]['#text'] image_url = data['artist']['image'][-1]['#text']
except Exception: except Exception:
logger.debug('No artist image found on url: ' + url) logger.debug('No artist image found on url: %s', url)
image_url = None image_url = None
thumb_url = self._get_thumb_url(data) thumb_url = self._get_thumb_url(data)
if not thumb_url: if not thumb_url:
logger.debug('No artist thumbnail image found on url: ' + url) logger.debug('No artist thumbnail image found on url: %s', url)
else: else:
@@ -349,39 +349,39 @@ class Cache(object):
url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(params) url = "http://ws.audioscrobbler.com/2.0/?" + urllib.urlencode(params)
logger.debug('Retrieving artist information from: ' + url) logger.debug('Retrieving artist information from: %s', url)
try: try:
result = urllib2.urlopen(url, timeout=20).read() result = urllib2.urlopen(url, timeout=20).read()
except: except:
logger.warn('Could not open url: ' + url) logger.warn('Could not open url: %s', url)
return return
if result: if result:
try: try:
data = simplejson.JSONDecoder().decode(result) data = simplejson.JSONDecoder().decode(result)
except: except:
logger.warn('Could not parse data from url: ' + url) logger.warn('Could not parse data from url: %s', url)
return return
try: try:
self.info_summary = data['album']['wiki']['summary'] self.info_summary = data['album']['wiki']['summary']
except Exception: except Exception:
logger.debug('No album summary found from: ' + url) logger.debug('No album summary found from: %s', url)
self.info_summary = None self.info_summary = None
try: try:
self.info_content = data['album']['wiki']['content'] self.info_content = data['album']['wiki']['content']
except Exception: except Exception:
logger.debug('No album infomation found from: ' + url) logger.debug('No album infomation found from: %s', url)
self.info_content = None self.info_content = None
try: try:
image_url = data['album']['image'][-1]['#text'] image_url = data['album']['image'][-1]['#text']
except Exception: except Exception:
logger.debug('No album image link found on url: ' + url) logger.debug('No album image link found on url: %s', url)
image_url = None image_url = None
thumb_url = self._get_thumb_url(data) thumb_url = self._get_thumb_url(data)
if not thumb_url: if not thumb_url:
logger.debug('No album thumbnail image found on url: ' + url) logger.debug('No album thumbnail image found on url: %s', url)
#Save the content & summary to the database no matter what if we've opened up the url #Save the content & summary to the database no matter what if we've opened up the url
if self.id_type == 'artist': if self.id_type == 'artist':
@@ -414,7 +414,7 @@ class Cache(object):
try: try:
artwork = urllib2.urlopen(image_url, timeout=20).read() artwork = urllib2.urlopen(image_url, timeout=20).read()
except Exception, e: except Exception, e:
logger.error('Unable to open url "' + image_url + '". Error: ' + str(e)) logger.error('Unable to open url "%s". Error: %s', image_url, e)
artwork = None artwork = None
if artwork: if artwork:
@@ -424,7 +424,7 @@ class Cache(object):
try: try:
os.makedirs(self.path_to_art_cache) os.makedirs(self.path_to_art_cache)
except Exception, e: except Exception, e:
logger.error('Unable to create artwork cache dir. Error: ' + str(e)) logger.error('Unable to create artwork cache dir. Error: %s', e)
self.artwork_errors = True self.artwork_errors = True
self.artwork_url = image_url self.artwork_url = image_url
@@ -433,7 +433,7 @@ class Cache(object):
try: try:
os.remove(artwork_file) os.remove(artwork_file)
except: except:
logger.error('Error deleting file from the cache: ' + artwork_file) logger.error('Error deleting file from the cache: %s', artwork_file)
ext = os.path.splitext(image_url)[1] ext = os.path.splitext(image_url)[1]
@@ -443,7 +443,7 @@ class Cache(object):
f.write(artwork) f.write(artwork)
f.close() f.close()
except Exception, e: except Exception, e:
logger.error('Unable to write to the cache dir: ' + str(e)) logger.error('Unable to write to the cache dir: %s', e)
self.artwork_errors = True self.artwork_errors = True
self.artwork_url = image_url self.artwork_url = image_url
@@ -453,7 +453,7 @@ class Cache(object):
try: try:
artwork = urllib2.urlopen(thumb_url, timeout=20).read() artwork = urllib2.urlopen(thumb_url, timeout=20).read()
except Exception, e: except Exception, e:
logger.error('Unable to open url "' + thumb_url + '". Error: ' + str(e)) logger.error('Unable to open url "%s". Error: %s', thumb_url, e)
artwork = None artwork = None
if artwork: if artwork:
@@ -463,7 +463,7 @@ class Cache(object):
try: try:
os.makedirs(self.path_to_art_cache) os.makedirs(self.path_to_art_cache)
except Exception, e: except Exception, e:
logger.error('Unable to create artwork cache dir. Error: ' + str(e)) logger.error('Unable to create artwork cache dir. Error: %s' + e)
self.thumb_errors = True self.thumb_errors = True
self.thumb_url = thumb_url self.thumb_url = thumb_url
@@ -472,7 +472,7 @@ class Cache(object):
try: try:
os.remove(thumb_file) os.remove(thumb_file)
except: except:
logger.error('Error deleting file from the cache: ' + thumb_file) logger.error('Error deleting file from the cache: %s', thumb_file)
ext = os.path.splitext(image_url)[1] ext = os.path.splitext(image_url)[1]
@@ -482,7 +482,7 @@ class Cache(object):
f.write(artwork) f.write(artwork)
f.close() f.close()
except Exception, e: except Exception, e:
logger.error('Unable to write to the cache dir: ' + str(e)) logger.error('Unable to write to the cache dir: %s', e)
self.thumb_errors = True self.thumb_errors = True
self.thumb_url = image_url self.thumb_url = image_url
+3 -3
View File
@@ -73,14 +73,14 @@ class DBConnection:
break break
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)
attempt += 1 attempt += 1
time.sleep(1) time.sleep(1)
else: else:
logger.error('Database error: %s' % e) logger.error('Database error: %s', e)
raise raise
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
+13 -13
View File
@@ -341,7 +341,7 @@ def extract_song_data(s):
year = match.group("year") year = match.group("year")
return (name, album, year) return (name, album, year)
else: else:
logger.info("Couldn't parse " + s + " into a valid default format") logger.info("Couldn't parse %s into a valid default format", s)
#newzbin default format #newzbin default format
pattern = re.compile(r'(?P<name>.*?)\s\-\s(?P<album>.*?)\s\((?P<year>\d+?\))', re.VERBOSE) pattern = re.compile(r'(?P<name>.*?)\s\-\s(?P<album>.*?)\s\((?P<year>\d+?\))', re.VERBOSE)
@@ -352,7 +352,7 @@ def extract_song_data(s):
year = match.group("year") year = match.group("year")
return (name, album, year) return (name, album, year)
else: else:
logger.info("Couldn't parse " + s + " into a valid Newbin format") logger.info("Couldn't parse %s into a valid Newbin format", s)
return (name, album, year) return (name, album, year)
def smartMove(src, dest, delete=True): def smartMove(src, dest, delete=True):
@@ -363,7 +363,7 @@ def smartMove(src, dest, delete=True):
filename = os.path.basename(src) filename = os.path.basename(src)
if os.path.isfile(os.path.join(dest, filename)): if os.path.isfile(os.path.join(dest, filename)):
logger.info('Destination file exists: %s' % os.path.join(dest, filename).decode(headphones.SYS_ENCODING, 'replace')) logger.info('Destination file exists: %s', os.path.join(dest, filename).decode(headphones.SYS_ENCODING, 'replace'))
title = os.path.splitext(filename)[0] title = os.path.splitext(filename)[0]
ext = os.path.splitext(filename)[1] ext = os.path.splitext(filename)[1]
i = 1 i = 1
@@ -372,12 +372,12 @@ def smartMove(src, dest, delete=True):
if os.path.isfile(os.path.join(dest, newfile)): if os.path.isfile(os.path.join(dest, newfile)):
i += 1 i += 1
else: else:
logger.info('Renaming to %s' % newfile) logger.info('Renaming to %s', newfile)
try: try:
os.rename(src, os.path.join(source_dir, newfile)) os.rename(src, os.path.join(source_dir, newfile))
filename = newfile filename = newfile
except Exception, e: except Exception, e:
logger.warn('Error renaming %s: %s' % (src.decode(headphones.SYS_ENCODING, 'replace'), str(e).decode(headphones.SYS_ENCODING, 'replace'))) logger.warn('Error renaming %s: %s', src.decode(headphones.SYS_ENCODING, 'replace'), e)
break break
try: try:
@@ -387,7 +387,7 @@ def smartMove(src, dest, delete=True):
shutil.copy(os.path.join(source_dir, filename), os.path.join(dest, filename)) shutil.copy(os.path.join(source_dir, filename), os.path.join(dest, filename))
return True return True
except Exception, e: except Exception, e:
logger.warn('Error moving file %s: %s' % (filename.decode(headphones.SYS_ENCODING, 'replace'), str(e).decode(headphones.SYS_ENCODING, 'replace'))) logger.warn('Error moving file %s: %s', filename.decode(headphones.SYS_ENCODING, 'replace'), e)
######################### #########################
#Sab renaming functions # #Sab renaming functions #
@@ -453,12 +453,12 @@ def create_https_certificates(ssl_cert, ssl_key):
Create self-signed HTTPS certificares and store in paths 'ssl_cert' and 'ssl_key' Create self-signed HTTPS certificares and store in paths 'ssl_cert' and 'ssl_key'
""" """
from headphones import logger from headphones import logger
try: try:
from OpenSSL import crypto #@UnresolvedImport from OpenSSL import crypto
from lib.certgen import createKeyPair, createCertRequest, createCertificate, TYPE_RSA, serial #@UnresolvedImport from lib.certgen import createKeyPair, createCertRequest, createCertificate, TYPE_RSA, serial
except: except:
logger.warn(u"pyopenssl module missing, please install for https access") logger.warn("pyOpenSSL module missing, please install to enable HTTPS")
return False return False
# Create the CA Certificate # Create the CA Certificate
@@ -475,8 +475,8 @@ def create_https_certificates(ssl_cert, ssl_key):
try: try:
open(ssl_key, 'w').write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey)) open(ssl_key, 'w').write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey))
open(ssl_cert, 'w').write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert)) open(ssl_cert, 'w').write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
except: except Exception, e:
logger.error(u"Error creating SSL key and certificate") logger.error("Error creating SSL key and certificate: %s", e)
return False return False
return True return True
+4 -4
View File
@@ -521,10 +521,10 @@ def addReleaseById(rid):
try: try:
release_dict = mb.getRelease(rid) release_dict = mb.getRelease(rid)
except Exception, e: except Exception, e:
logger.info('Unable to get release information for Release: ' + str(rid) + " " + str(e)) logger.info('Unable to get release information for Release %s: %s', rid, e)
return return
if not release_dict: if not release_dict:
logger.info('Unable to get release information for Release: ' + str(rid) + " no dict") logger.info('Unable to get release information for Release %s: no dict', rid)
return return
rgid = release_dict['rgid'] rgid = release_dict['rgid']
@@ -664,7 +664,7 @@ def getHybridRelease(fullreleaselist):
'2xVinyl': '2', '2xVinyl': '2',
'Vinyl': '2', 'Vinyl': '2',
'CD': '0', 'CD': '0',
'Cassette': '3', 'Cassette': '3',
'2xCD': '1', '2xCD': '1',
'Digital Media': '0' 'Digital Media': '0'
} }
@@ -681,7 +681,7 @@ def getHybridRelease(fullreleaselist):
format = 3 format = 3
try: try:
country = int(countries[release['Country']]) country = int(countries[release['Country']])
except: except:
country = 3 country = 3
+11 -12
View File
@@ -82,7 +82,7 @@ def getSimilar():
myDB.action('''DELETE from lastfmcloud''') myDB.action('''DELETE from lastfmcloud''')
for tuple in top_list: for tuple in top_list:
artist_name, artist_mbid = tuple[0] artist_name, artist_mbid = tuple[0]
count = tuple[1] count = tuple[1]
myDB.action('INSERT INTO lastfmcloud VALUES( ?, ?, ?)', [artist_name, artist_mbid, count]) myDB.action('INSERT INTO lastfmcloud VALUES( ?, ?, ?)', [artist_name, artist_mbid, count])
def getArtists(): def getArtists():
@@ -96,7 +96,7 @@ def getArtists():
else: else:
username = headphones.LASTFM_USERNAME username = headphones.LASTFM_USERNAME
logger.info("Starting Last.FM artists import with username '%s'" % username) logger.info("Starting Last.FM artists import with username '%s'", username)
url = 'http://ws.audioscrobbler.com/2.0/?method=library.getartists&limit=10000&api_key=%s&user=%s' % (api_key, username) url = 'http://ws.audioscrobbler.com/2.0/?method=library.getartists&limit=10000&api_key=%s&user=%s' % (api_key, username)
data = urllib2.urlopen(url, timeout=20).read() data = urllib2.urlopen(url, timeout=20).read()
@@ -108,7 +108,7 @@ def getArtists():
return return
artists = d.getElementsByTagName("artist") artists = d.getElementsByTagName("artist")
logger.info("Fetched %d artists from Last.FM" % len(artists)) logger.info("Fetched %d artists from Last.FM", len(artists))
artistlist = [] artistlist = []
@@ -129,7 +129,7 @@ def getArtists():
for artistid in artistlist: for artistid in artistlist:
importer.addArtisttoDB(artistid) importer.addArtisttoDB(artistid)
logger.info("Imported %d new artists from Last.FM" % len(artistid)) logger.info("Imported %d new artists from Last.FM", len(artistid))
def getTagTopArtists(tag, limit=50): def getTagTopArtists(tag, limit=50):
myDB = db.DBConnection() myDB = db.DBConnection()
@@ -141,7 +141,7 @@ def getTagTopArtists(tag, limit=50):
try: try:
d = minidom.parseString(data) d = minidom.parseString(data)
except: except:
logger.error("Could not parse artist list from last.fm data") logger.error("Could not parse artist list from Last.FM data")
return return
artists = d.getElementsByTagName("artist") artists = d.getElementsByTagName("artist")
@@ -205,6 +205,7 @@ def getAlbumDescription(rgid, artist, album):
myDB.upsert("descriptions", newValueDict, controlValueDict) myDB.upsert("descriptions", newValueDict, controlValueDict)
except: except:
logger.exception("Unhandled exception")
return return
def getAlbumDescriptionOld(rgid, releaselist): def getAlbumDescriptionOld(rgid, releaselist):
@@ -213,7 +214,7 @@ def getAlbumDescriptionOld(rgid, releaselist):
because I may use it to fetch and cache album art because I may use it to fetch and cache album art
""" """
myDB = db.DBConnection() myDB = db.DBConnection()
result = myDB.select('SELECT Summary from descriptions WHERE ReleaseGroupID=?', [rgid]) result = myDB.select('SELECT Summary from descriptions WHERE ReleaseGroupID=?', [rgid])
if result: if result:
@@ -240,15 +241,13 @@ def getAlbumDescriptionOld(rgid, releaselist):
summary = node.data summary = node.data
for node in contentnode: for node in contentnode:
content = node.data content = node.data
controlValueDict = {'ReleaseGroupID': rgid} controlValueDict = {'ReleaseGroupID': rgid}
newValueDict = {'ReleaseID': mbid, newValueDict = {'ReleaseID': mbid,
'Summary': summary, 'Summary': summary,
'Content': content} 'Content': content}
myDB.upsert("descriptions", newValueDict, controlValueDict) myDB.upsert("descriptions", newValueDict, controlValueDict)
break break
except: except:
continue logger.exception("Unhandled exception")
continue
+1 -1
View File
@@ -34,7 +34,7 @@ class LogListHandler(logging.Handler):
""" """
def emit(self, record): def emit(self, record):
headphones.LOG_LIST.insert(0, (helpers.now(), record.msg, record.levelname, record.threadName)) headphones.LOG_LIST.insert(0, (helpers.now(), self.format(record), record.levelname, record.threadName))
def initLogger(verbose=1): def initLogger(verbose=1):
""" """
+1 -1
View File
@@ -62,7 +62,7 @@ def initialize(options={}):
else: else:
protocol = "http" protocol = "http"
logger.info(u"Starting Headphones on " + protocol + "://" + str(options['http_host']) + ":" + str(options['http_port']) + "/") logger.info("Starting Headphones on %s://%s:%d/", protocol, options['http_host'], options['http_port'])
cherrypy.config.update(options_dict) cherrypy.config.update(options_dict)
conf = { conf = {