class MetaException(Exception):
"""Generic Meta Exception"""
- pass
+
def mbidfilter(func):
def wrapper(*args, **kwargs):
self.log = logging.getLogger(__name__)
if 'name' not in kwargs or not kwargs.get('name'):
raise MetaException('Need a "name" argument (str type)')
- elif not isinstance(kwargs.get('name'), str):
+ if not isinstance(kwargs.get('name'), str):
raise MetaException('"name" argument not a string')
else:
self.__name = kwargs.pop('name')
#if hasattr(other, 'mbid'): # better isinstance?
if isinstance(other, Meta) and self.mbid and other.mbid:
return self.mbid == other.mbid
- elif isinstance(other, Meta):
+ if isinstance(other, Meta):
return bool(self.names & other.names)
- elif getattr(other, '__str__', None):
+ if getattr(other, '__str__', None):
# is other.__str__() in self.__name or self.__aliases
return other.__str__() in self.names
return False
Called when the daemon().run() is called and
right after the player has connected successfully.
"""
- pass
def callback_player(self):
"""
Called on player changes, stopped, paused, skipped
"""
- pass
def callback_player_database(self):
"""
Called on player music library changes
"""
- pass
def callback_playlist(self):
"""
Called on playlist changes
Not returning data
"""
- pass
def callback_next_song(self):
"""
Could be use to scrobble, maintain an history…
Not returning data,
"""
- pass
def callback_need_track(self):
"""
Returns a list of Track objects to add
"""
- pass
def callback_need_track_fb(self):
"""
Called when callback_need_track failled to find tracks to queue
Returns a list of Track objects to add
"""
- pass
def shutdown(self):
"""Called on application shutdown"""
- pass
class AdvancedPlugin(Plugin):
not_queued_artist = alist - queued_artist
duration = self.main_conf.getint('sima', 'history_duration')
hist = []
- for art in self.sdb.get_artists_history(alist,
- duration=duration):
+ for art in self.sdb.get_artists_history(alist, duration=duration):
if art not in hist:
if art not in queued_artist:
hist.insert(0, art)
"""
Exceptions.
"""
- pass
class SimaDBAccessError(SimaDBError):
"""Error on accessing DB file"""
- pass
class SimaDBNoFile(SimaDBError):
"""No DB file present"""
- pass
-class SimaDB(object):
+class SimaDB:
"SQLite management"
def __init__(self, db_path=None):
def __hash__(self):
if self.file:
return hash(self.file)
- else:
- return id(self)
+ return id(self)
def __eq__(self, other):
return hash(self) == hash(other)
"""
duration = self.main_conf.getint('sima', 'history_duration')
tracks_from_db = self.sdb.get_history(duration=duration)
- artists = [tr[0] for tr in tracks_from_db]
- return set(artists)
+ artists = {tr[0] for tr in tracks_from_db}
+ return artists
def filtered_artist(self, artist):
"""Filters artists:
"""
# standard library import
-import random
# third parties components
from musicpd import CommandError
import os
import time
+
class FileLockException(Exception):
"""FileLock Exception"""
- pass
+
class FileLock:
""" A plain file lock whit context-manager"""
def is_valid_file(parser, arg):
if not os.path.exists(arg) or not os.path.isfile(arg):
parser.error('The file "%s" does not exist!' % arg)
- else:
- return arg
+ return arg
def main():
def checks(self):
"""control method
"""
- pass
class Wfile(FileAction):