Merge branch 'develop'

This commit is contained in:
Remy
2011-08-09 16:39:51 -07:00
9 changed files with 51 additions and 44 deletions

View File

@@ -188,9 +188,9 @@ table#history_table { background-color: white; width: 100%; }
table#log_table { background-color: white; }
table#log_table th#timestamp { text-align: left; min-width: 165px; }
table#log_table th#level { text-align: left; min-width: 75px; }
table#log_table th#message { text-align: left; min-width: 200px; }
table#log_table th#timestamp { text-align: left; min-width: 150px; }
table#log_table th#level { text-align: left; min-width: 60px; }
table#log_table th#message { text-align: left; min-width: 500px; }
table#upcoming_table th#albumart { text-align: center; min-width: 50px; }
table#upcoming_table th#albumname { text-align: center; min-width: 200px; }

View File

@@ -15,23 +15,18 @@
<tbody>
%for line in lineList:
<%
out_tuple = helpers.extract_logline(line)
timestamp, message, level, threadname = line
if level == 'WARNING' or level == 'ERROR':
grade = 'X'
else:
grade = 'Z'
%>
%if out_tuple:
<%
if out_tuple[1] == 'DEBUG':
continue
elif out_tuple[1] == 'WARNING' or out_tuple[1] == 'ERROR':
grade = 'X'
else:
grade = 'Z'
%>
<tr class="grade${grade}">
<td id="timestamp">${out_tuple[0]}</td>
<td id="level">${out_tuple[1]}</td>
<td id="message">${out_tuple[3].decode('utf-8')}</td>
<td id="timestamp">${timestamp}</td>
<td id="level">${level}</td>
<td id="message">${message}</td>
</tr>
%endif
%endfor
</tbody>
</table>

View File

@@ -37,6 +37,8 @@ CFG = None
DB_FILE = None
LOG_DIR = None
LOG_LIST = []
CACHE_DIR = None
HTTP_PORT = None
@@ -74,6 +76,7 @@ INCLUDE_EXTRAS = False
NZB_SEARCH_INTERVAL = 360
LIBRARYSCAN_INTERVAL = 60
DOWNLOAD_SCAN_INTERVAL = 5
SAB_HOST = None
SAB_USERNAME = None
@@ -156,7 +159,7 @@ def initialize():
CURRENT_VERSION, LATEST_VERSION, MUSIC_DIR, DESTINATION_DIR, PREFERRED_QUALITY, PREFERRED_BITRATE, DETECT_BITRATE, \
CORRECT_METADATA, MOVE_FILES, RENAME_FILES, FOLDER_FORMAT, FILE_FORMAT, CLEANUP_FILES, INCLUDE_EXTRAS, \
ADD_ALBUM_ART, EMBED_ALBUM_ART, DOWNLOAD_DIR, BLACKHOLE, BLACKHOLE_DIR, USENET_RETENTION, NZB_SEARCH_INTERVAL, \
LIBRARYSCAN_INTERVAL, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \
LIBRARYSCAN_INTERVAL, DOWNLOAD_SCAN_INTERVAL, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \
NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, \
NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, LASTFM_USERNAME
@@ -209,6 +212,7 @@ def initialize():
NZB_SEARCH_INTERVAL = check_setting_int(CFG, 'General', 'nzb_search_interval', 360)
LIBRARYSCAN_INTERVAL = check_setting_int(CFG, 'General', 'libraryscan_interval', 180)
DOWNLOAD_SCAN_INTERVAL = check_setting_int(CFG, 'General', 'download_scan_interval', 5)
SAB_HOST = check_setting_str(CFG, 'SABnzbd', 'sab_host', '')
SAB_USERNAME = check_setting_str(CFG, 'SABnzbd', 'sab_username', '')
@@ -369,6 +373,7 @@ def config_write():
new_config['General']['nzb_search_interval'] = NZB_SEARCH_INTERVAL
new_config['General']['libraryscan_interval'] = LIBRARYSCAN_INTERVAL
new_config['General']['download_scan_interval'] = DOWNLOAD_SCAN_INTERVAL
new_config['SABnzbd'] = {}
new_config['SABnzbd']['sab_host'] = SAB_HOST
@@ -414,7 +419,7 @@ def start():
SCHED.add_interval_job(searcher.searchNZB, minutes=NZB_SEARCH_INTERVAL)
SCHED.add_interval_job(importer.scanMusic, minutes=LIBRARYSCAN_INTERVAL)
SCHED.add_interval_job(versioncheck.checkGithub, minutes=300)
SCHED.add_interval_job(postprocessor.checkFolder, minutes=5)
SCHED.add_interval_job(postprocessor.checkFolder, minutes=DOWNLOAD_SCAN_INTERVAL)
SCHED.start()

View File

@@ -5,8 +5,6 @@ import re
import headphones
from headphones import logger
def multikeysort(items, columns):
comparers = [ ((itemgetter(col[1:].strip()), -1) if col.startswith('-') else (itemgetter(col.strip()), 1)) for col in columns]
@@ -91,6 +89,10 @@ def today():
yyyymmdd = datetime.date.isoformat(today)
return yyyymmdd
def now():
now = datetime.datetime.now()
return now.strftime("%Y-%m-%d %H:%M:%S")
def bytes_to_mb(bytes):
mb = int(bytes)/1048576
@@ -103,6 +105,9 @@ def replace_all(text, dic):
return text
def extract_data(s):
from headphones import logger
#headphones default format
pattern = re.compile(r'(?P<name>.*?)\s\-\s(?P<album>.*?)\s\[(?P<year>.*?)\]', re.VERBOSE)
match = pattern.match(s)

View File

@@ -215,8 +215,11 @@ def addArtisttoDB(artistid, extrasonly=False):
myDB.upsert("albums", newValueDict, controlValueDict)
lastfm.getAlbumDescription(rg['id'], artist['artist_name'], rg['title'])
try:
lastfm.getAlbumDescription(rg['id'], artist['artist_name'], rg['title'])
except Exception, e:
logger.error('Attempt to retrieve album description from Last.fm failed: %s' % e)
# I changed the albumid from releaseid -> rgid, so might need to delete albums that have a releaseid
for release in release_dict['releaselist']:
myDB.action('DELETE from albums WHERE AlbumID=?', [release['releaseid']])

View File

@@ -4,6 +4,7 @@ import logging
from logging import handlers
import headphones
from headphones import helpers
MAX_SIZE = 1000000 # 1mb
MAX_FILES = 5
@@ -45,33 +46,36 @@ class RotatingLogger(object):
l.addHandler(consolehandler)
def log(self, message, level):
logger = logging.getLogger('headphones')
threadname = threading.currentThread().getName()
message = threadname + ' : ' + message
if level == 'debug':
if level != 'DEBUG':
headphones.LOG_LIST.insert(0, (helpers.now(), message, level, threadname))
message = threadname + ' : ' + message
if level == 'DEBUG':
logger.debug(message)
elif level == 'info':
elif level == 'INFO':
logger.info(message)
elif level == 'warn':
elif level == 'WARN':
logger.warn(message)
else:
logger.error(message)
headphones_log = RotatingLogger('headphones.log', MAX_SIZE, MAX_FILES)
def debug(message):
headphones_log.log(message, level='debug')
headphones_log.log(message, level='DEBUG')
def info(message):
headphones_log.log(message, level='info')
headphones_log.log(message, level='INFO')
def warn(message):
headphones_log.log(message, level='warn')
headphones_log.log(message, level='WARN')
def error(message):
headphones_log.log(message, level='error')
headphones_log.log(message, level='ERROR')

View File

@@ -306,7 +306,7 @@ def moveFiles(albumpath, release, tracks):
os.chmod(temp_f, 0755)
except Exception, e:
logger.error('Could not create folder for %s. Not moving' % release['AlbumName'])
logger.error('Could not create folder for %s. Not moving: %s' % (release['AlbumTitle'], e))
return albumpath
for r,d,f in os.walk(albumpath):

View File

@@ -418,6 +418,7 @@ def searchNZB(albumid=None, new=False):
f = open(download_path, 'w')
f.write(data)
f.close()
logger.info('File saved to: %s' % nzb_name)
except Exception, e:
logger.error('Couldn\'t write NZB file: %s' % e)
break
@@ -449,12 +450,12 @@ def getresultNZB(result):
try:
nzb = urllib.urlopen(url, data=params).read()
except urllib2.URLError, e:
logger.warn('Error fetching nzb from url: ' + url + ' %s' % e)
logger.warn('Error fetching nzb from url: %s. Error: %s' % (url, e))
else:
try:
nzb = urllib2.urlopen(result[2], timeout=20).read()
except:
logger.warn('Error fetching nzb from url: ' + result[2] + ' %s' % e)
except Exception, e:
logger.warn('Error fetching nzb from url: %s. Error: %s' % (result[2], e))
return nzb
def preprocess(resultlist):

View File

@@ -231,13 +231,7 @@ class WebInterface(object):
history.exposed = True
def logs(self):
log_file = os.path.join(headphones.LOG_DIR, 'headphones.log')
if os.path.isfile(log_file):
fileHandle = open(log_file)
lineList = fileHandle.readlines()
fileHandle.close()
lineList.reverse()
return serve_template(templatename="logs.html", title="Log", lineList=lineList[0:500])
return serve_template(templatename="logs.html", title="Log", lineList=headphones.LOG_LIST)
logs.exposed = True
def clearhistory(self, type=None):