Skip to content

Commit

Permalink
Docstring fix-up and added logic to handle improperly formatted confi…
Browse files Browse the repository at this point in the history
…guration

file as raised within Issue #34 .
  • Loading branch information
jesseward committed May 9, 2015
1 parent 275c77c commit 5beb6c3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
13 changes: 7 additions & 6 deletions plex_scrobble/plex_monitor.py
Expand Up @@ -11,12 +11,13 @@


def parse_line(log_line):
''' Matches known audio metadata log entries entries against input (log_line)
"""
Matches known audio metadata log entries entries against input (log_line)
:param log_line: plex media server log line
:type log_line: string
:returns: plex media server metadata id
:rtype: integer (or None) '''
:param log_line: a str containing a plex media server log line
:return: plex media server metadata id
:rtype: integer (or None)
"""

logger = logging.getLogger(__name__)

Expand All @@ -36,7 +37,7 @@ def parse_line(log_line):


def fetch_metadata(l_id, config):
''' retrieves the metadata information from the Plex media Server api. '''
""" retrieves the metadata information from the Plex media Server api. """

logger = logging.getLogger(__name__)
url = '{url}/library/metadata/{l_id}'.format(url=config.get('plex-scrobble',
Expand Down
26 changes: 22 additions & 4 deletions plex_scrobble/scrobble_cache.py
Expand Up @@ -6,10 +6,16 @@


class ScrobbleCache(object):
''' provides a light wrapper around Python Shelve. Used to persist
a Python dict to disk. '''
"""
provides a light wrapper around Python Shelve. Used to persist
a Python dict to disk.
"""

def __init__(self, config):
"""
:param config: Configuration object
"""

self.config = config
self.cache = shelve.open(self.config.get('plex-scrobble', 'cache_location'),
Expand All @@ -20,6 +26,14 @@ def length(self):
return len(self.cache)

def add(self, key, value, album, cache_hit=1):
"""
Add missed scrobble to the retry cache.
:param key: a time - timestamp
:param value: a str representing an artist name
:param album: a str representing an album name
:param cache_hit: number of times the item has been retried.
"""

self.logger.info(u'adding \'{key}\' \'{value}\' ({album}) to retry cache.'.format(
key=key, value=value, album=album))
Expand All @@ -28,7 +42,11 @@ def add(self, key, value, album, cache_hit=1):
self.cache.sync()

def remove(self, key):
''' remove an existing entry from cache file. '''
"""
remove an existing entry from cache file.
:param key: a timestamp.
"""

self.logger.info(u'removing \'{key}\': \'{artist}\' - \'{track}\' ({album})from retry cache.'.format(
key=key, artist=self.cache[key][0], track=self.cache[key][1],
Expand All @@ -42,7 +60,7 @@ def close(self):
self.cache.close()

def cache_items(self):
''' debug method to dump cache to stdout. '''
""" debug method to dump cache to stdout. """

for key in self.cache:
print u'time={key}, artist={artist}, track={track}, album={album}age={age}'.format(
Expand Down
20 changes: 14 additions & 6 deletions scripts/plex-scrobble.py
Expand Up @@ -14,11 +14,12 @@
from plex_scrobble.pre_check import PLSSanity

def platform_log_directory():
''' Retrieves the default platform specific default log location.
This is called if the user does not specify a log location in
the configuration file.
github issue https://github.com/jesseward/plex-lastfm-scrobbler/issues/5
'''
"""
Retrieves the default platform specific default log location.
This is called if the user does not specify a log location in
the configuration file.
github issue https://github.com/jesseward/plex-lastfm-scrobbler/issues/5
"""

LOG_DEFAULTS = {
'Darwin': os.path.expanduser('~/Library/Logs/Plex Media Server.log'),
Expand Down Expand Up @@ -97,8 +98,15 @@ def main(config):
'mediaserver_log_location': platform_log_directory(),
'log_file': '/tmp/plex_scrobble.log'
})
config.read(options.config_file)

# ISSUE https://github.com/jesseward/plex-lastfm-scrobbler/issues/34
try:
config.read(options.config_file)
except ConfigParser.Error:
print 'ERROR: unable to parse config file "{file}". Syntax error?'.format(
file=options.config_file)
sys.exit(1)

FORMAT = '%(asctime)-15s [%(process)d] [%(name)s %(funcName)s] [%(levelname)s] %(message)s'
logging.basicConfig(filename=config.get('plex-scrobble',
'log_file'), format=FORMAT, level=logging.DEBUG)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -2,7 +2,7 @@
from distutils.core import setup

NAME = 'plex-lastfm-scrobbler'
VERSION = '1.3.3'
VERSION = '1.3.4'

setup(
name = 'plex_scrobble',
Expand Down

0 comments on commit 5beb6c3

Please sign in to comment.