Fix more pylint violations
This commit is contained in:
parent
c3e9100fc4
commit
cf1fbda387
@ -8,7 +8,7 @@ def get_mpd_protocol_version():
|
||||
|
||||
class MopidyException(Exception):
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
self._message = message
|
||||
|
||||
@property
|
||||
def message(self):
|
||||
|
||||
@ -15,7 +15,7 @@ from mopidy.utils import get_class, get_or_create_dotdir
|
||||
logger = logging.getLogger('mopidy.main')
|
||||
|
||||
def main():
|
||||
options, args = _parse_options()
|
||||
options = _parse_options()
|
||||
_setup_logging(options.verbosity_level)
|
||||
get_or_create_dotdir('~/.mopidy/')
|
||||
core_queue = multiprocessing.Queue()
|
||||
@ -32,7 +32,7 @@ def _parse_options():
|
||||
parser.add_option('-v', '--verbose',
|
||||
action='store_const', const=2, dest='verbosity_level',
|
||||
help='more output (debug level)')
|
||||
return parser.parse_args()
|
||||
return parser.parse_args()[0]
|
||||
|
||||
def _setup_logging(verbosity_level):
|
||||
if verbosity_level == 0:
|
||||
|
||||
@ -79,7 +79,7 @@ class BaseCurrentPlaylistController(object):
|
||||
|
||||
def __init__(self, backend):
|
||||
self.backend = backend
|
||||
self.playlist = Playlist()
|
||||
self._playlist = Playlist()
|
||||
|
||||
@property
|
||||
def playlist(self):
|
||||
@ -242,12 +242,12 @@ class BaseLibraryController(object):
|
||||
def __init__(self, backend):
|
||||
self.backend = backend
|
||||
|
||||
def find_exact(self, type, query):
|
||||
def find_exact(self, field, query):
|
||||
"""
|
||||
Find tracks in the library where ``type`` matches ``query`` exactly.
|
||||
Find tracks in the library where ``field`` matches ``query`` exactly.
|
||||
|
||||
:param type: 'track', 'artist', or 'album'
|
||||
:type type: string
|
||||
:param field: 'track', 'artist', or 'album'
|
||||
:type field: string
|
||||
:param query: the search query
|
||||
:type query: string
|
||||
:rtype: :class:`mopidy.models.Playlist`
|
||||
@ -273,12 +273,12 @@ class BaseLibraryController(object):
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def search(self, type, query):
|
||||
def search(self, field, query):
|
||||
"""
|
||||
Search the library for tracks where ``type`` contains ``query``.
|
||||
Search the library for tracks where ``field`` contains ``query``.
|
||||
|
||||
:param type: 'track', 'artist', 'album', 'uri', and 'any'
|
||||
:type type: string
|
||||
:param field: 'track', 'artist', 'album', 'uri', and 'any'
|
||||
:type field: string
|
||||
:param query: the search query
|
||||
:type query: string
|
||||
:rtype: :class:`mopidy.models.Playlist`
|
||||
|
||||
@ -72,13 +72,13 @@ class DespotifyLibraryController(BaseLibraryController):
|
||||
track = self.backend.spotify.lookup(uri.encode(ENCODING))
|
||||
return DespotifyTranslator.to_mopidy_track(track)
|
||||
|
||||
def search(self, type, what):
|
||||
if type == u'track':
|
||||
type = u'title'
|
||||
if type == u'any':
|
||||
def search(self, field, what):
|
||||
if field == u'track':
|
||||
field = u'title'
|
||||
if field == u'any':
|
||||
query = what
|
||||
else:
|
||||
query = u'%s:%s' % (type, what)
|
||||
query = u'%s:%s' % (field, what)
|
||||
result = self.backend.spotify.search(query.encode(ENCODING))
|
||||
if (result is None or result.playlist.tracks[0].get_uri() ==
|
||||
'spotify:track:0000000000000000000000'):
|
||||
|
||||
@ -30,7 +30,7 @@ class DummyLibraryController(BaseLibraryController):
|
||||
if matches:
|
||||
return matches[0]
|
||||
|
||||
def search(self, type, query):
|
||||
def search(self, field, query):
|
||||
return Playlist()
|
||||
|
||||
find_exact = search
|
||||
|
||||
@ -67,11 +67,11 @@ class LibspotifyLibraryController(BaseLibraryController):
|
||||
spotify_track = Link.from_string(uri).as_track()
|
||||
return LibspotifyTranslator.to_mopidy_track(spotify_track)
|
||||
|
||||
def search(self, type, what):
|
||||
if type is u'any':
|
||||
def search(self, field, what):
|
||||
if field is u'any':
|
||||
query = what
|
||||
else:
|
||||
query = u'%s:%s' % (type, what)
|
||||
query = u'%s:%s' % (field, what)
|
||||
my_end, other_end = multiprocessing.Pipe()
|
||||
self.backend.spotify.search(query.encode(ENCODING), other_end)
|
||||
my_end.poll(None)
|
||||
|
||||
@ -573,15 +573,13 @@ class MpdFrontend(object):
|
||||
"""
|
||||
return [('songs', 0), ('playtime', 0)] # TODO
|
||||
|
||||
@handle_pattern(r'^find (?P<type>(album|artist|title)) '
|
||||
@handle_pattern(r'^find (?P<field>([Aa]lbum|[Aa]rtist|[Tt]itle)) '
|
||||
r'"(?P<what>[^"]+)"$')
|
||||
@handle_pattern(r'^find (?P<type>(Album|Artist|Title)) '
|
||||
@handle_pattern(r'^find "(?P<field>(album|artist|title))" '
|
||||
r'"(?P<what>[^"]+)"$')
|
||||
@handle_pattern(r'^find "(?P<type>(album|artist|title))" '
|
||||
r'"(?P<what>[^"]+)"$')
|
||||
@handle_pattern(r'^find (?P<type>(album)) '
|
||||
@handle_pattern(r'^find (?P<field>(album)) '
|
||||
r'"(?P<what>[^"]+)" artist "([^"]+)"$')
|
||||
def _music_db_find(self, type, what):
|
||||
def _music_db_find(self, field, what):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
|
||||
@ -592,24 +590,24 @@ class MpdFrontend(object):
|
||||
|
||||
*GMPC:*
|
||||
|
||||
- does not add quotes around the type argument.
|
||||
- does not add quotes around the field argument.
|
||||
- also uses ``find album "[ALBUM]" artist "[ARTIST]"`` to list album
|
||||
tracks.
|
||||
|
||||
*ncmpc:*
|
||||
|
||||
- does not add quotes around the type argument.
|
||||
- does not add quotes around the field argument.
|
||||
- capitalizes the type argument.
|
||||
"""
|
||||
type = type.lower()
|
||||
if type == u'title':
|
||||
type = u'track'
|
||||
return self.backend.library.find_exact(type, what).mpd_format(
|
||||
field = field.lower()
|
||||
if field == u'title':
|
||||
field = u'track'
|
||||
return self.backend.library.find_exact(field, what).mpd_format(
|
||||
search_result=True)
|
||||
|
||||
@handle_pattern(r'^findadd "(?P<type>(album|artist|title))" '
|
||||
@handle_pattern(r'^findadd "(?P<field>(album|artist|title))" '
|
||||
r'"(?P<what>[^"]+)"$')
|
||||
def _music_db_findadd(self, type, what):
|
||||
def _music_db_findadd(self, field, what):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
|
||||
@ -619,14 +617,13 @@ class MpdFrontend(object):
|
||||
current playlist. ``TYPE`` can be any tag supported by MPD.
|
||||
``WHAT`` is what to find.
|
||||
"""
|
||||
result = self._music_db_find(type, what)
|
||||
result = self._music_db_find(field, what)
|
||||
# TODO Add result to current playlist
|
||||
#return result
|
||||
|
||||
@handle_pattern(r'^list "(?P<type>artist)"$')
|
||||
@handle_pattern(r'^list (?P<type>Artist)$')
|
||||
@handle_pattern(r'^list "(?P<type>album)"( "(?P<artist>[^"]+)")*$')
|
||||
def _music_db_list(self, type, artist=None):
|
||||
@handle_pattern(r'^list "(?P<field>[Aa]rtist)"$')
|
||||
@handle_pattern(r'^list "(?P<field>album)"( "(?P<artist>[^"]+)")*$')
|
||||
def _music_db_list(self, field, artist=None):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
|
||||
@ -640,10 +637,10 @@ class MpdFrontend(object):
|
||||
|
||||
*ncmpc:*
|
||||
|
||||
- does not add quotes around the type argument.
|
||||
- capitalizes the type argument.
|
||||
- does not add quotes around the field argument.
|
||||
- capitalizes the field argument.
|
||||
"""
|
||||
type = type.lower()
|
||||
field = field.lower()
|
||||
# TODO
|
||||
|
||||
@handle_pattern(r'^listall "(?P<uri>[^"]+)"')
|
||||
@ -698,13 +695,12 @@ class MpdFrontend(object):
|
||||
"""
|
||||
return self._music_db_update(uri, rescan_unmodified_files=True)
|
||||
|
||||
@handle_pattern(r'^search (?P<type>(album|artist|filename|title|any)) '
|
||||
@handle_pattern(r'^search '
|
||||
r'(?P<field>([Aa]lbum|[Aa]rtist|[Ff]ilename|[Tt]itle|[Aa]ny)) '
|
||||
r'"(?P<what>[^"]+)"$')
|
||||
@handle_pattern(r'^search (?P<type>(Album|Artist|Filename|Title|Any)) '
|
||||
@handle_pattern(r'^search "(?P<field>(album|artist|filename|title|any))" '
|
||||
r'"(?P<what>[^"]+)"$')
|
||||
@handle_pattern(r'^search "(?P<type>(album|artist|filename|title|any))" '
|
||||
r'"(?P<what>[^"]+)"$')
|
||||
def _music_db_search(self, type, what):
|
||||
def _music_db_search(self, field, what):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
|
||||
@ -716,22 +712,22 @@ class MpdFrontend(object):
|
||||
|
||||
*GMPC:*
|
||||
|
||||
- does not add quotes around the type argument.
|
||||
- uses the undocumented type ``any``.
|
||||
- does not add quotes around the field argument.
|
||||
- uses the undocumented field ``any``.
|
||||
- searches for multiple words like this::
|
||||
|
||||
search any "foo" any "bar" any "baz"
|
||||
|
||||
*ncmpc:*
|
||||
|
||||
- does not add quotes around the type argument.
|
||||
- capitalizes the type argument.
|
||||
- does not add quotes around the field argument.
|
||||
- capitalizes the field argument.
|
||||
"""
|
||||
# TODO Support GMPC multi-word search
|
||||
type = type.lower()
|
||||
if type == u'title':
|
||||
type = u'track'
|
||||
return self.backend.library.search(type, what).mpd_format(
|
||||
field = field.lower()
|
||||
if field == u'title':
|
||||
field = u'track'
|
||||
return self.backend.library.search(field, what).mpd_format(
|
||||
search_result=True)
|
||||
|
||||
@handle_pattern(r'^update( "(?P<uri>[^"]+)")*$')
|
||||
@ -1264,9 +1260,9 @@ class MpdFrontend(object):
|
||||
def __status_status_xfade(self):
|
||||
return 0 # TODO
|
||||
|
||||
@handle_pattern(r'^sticker delete "(?P<type>[^"]+)" '
|
||||
@handle_pattern(r'^sticker delete "(?P<field>[^"]+)" '
|
||||
r'"(?P<uri>[^"]+)"( "(?P<name>[^"]+)")*$')
|
||||
def _sticker_delete(self, type, uri, name=None):
|
||||
def _sticker_delete(self, field, uri, name=None):
|
||||
"""
|
||||
*musicpd.org, sticker section:*
|
||||
|
||||
@ -1277,9 +1273,9 @@ class MpdFrontend(object):
|
||||
"""
|
||||
raise MpdNotImplemented # TODO
|
||||
|
||||
@handle_pattern(r'^sticker find "(?P<type>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
@handle_pattern(r'^sticker find "(?P<field>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
r'"(?P<name>[^"]+)"$')
|
||||
def _sticker_find(self, type, uri, name):
|
||||
def _sticker_find(self, field, uri, name):
|
||||
"""
|
||||
*musicpd.org, sticker section:*
|
||||
|
||||
@ -1291,9 +1287,9 @@ class MpdFrontend(object):
|
||||
"""
|
||||
raise MpdNotImplemented # TODO
|
||||
|
||||
@handle_pattern(r'^sticker get "(?P<type>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
@handle_pattern(r'^sticker get "(?P<field>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
r'"(?P<name>[^"]+)"$')
|
||||
def _sticker_get(self, type, uri, name):
|
||||
def _sticker_get(self, field, uri, name):
|
||||
"""
|
||||
*musicpd.org, sticker section:*
|
||||
|
||||
@ -1303,8 +1299,8 @@ class MpdFrontend(object):
|
||||
"""
|
||||
raise MpdNotImplemented # TODO
|
||||
|
||||
@handle_pattern(r'^sticker list "(?P<type>[^"]+)" "(?P<uri>[^"]+)"$')
|
||||
def _sticker_list(self, type, uri):
|
||||
@handle_pattern(r'^sticker list "(?P<field>[^"]+)" "(?P<uri>[^"]+)"$')
|
||||
def _sticker_list(self, field, uri):
|
||||
"""
|
||||
*musicpd.org, sticker section:*
|
||||
|
||||
@ -1314,9 +1310,9 @@ class MpdFrontend(object):
|
||||
"""
|
||||
raise MpdNotImplemented # TODO
|
||||
|
||||
@handle_pattern(r'^sticker set "(?P<type>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
@handle_pattern(r'^sticker set "(?P<field>[^"]+)" "(?P<uri>[^"]+)" '
|
||||
r'"(?P<name>[^"]+)" "(?P<value>[^"]+)"$')
|
||||
def _sticker_set(self, type, uri, name, value):
|
||||
def _sticker_set(self, field, uri, name, value):
|
||||
"""
|
||||
*musicpd.org, sticker section:*
|
||||
|
||||
|
||||
@ -753,18 +753,18 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
|
||||
self.b.current_playlist.load(Playlist(tracks=[
|
||||
Track(name='a'), Track(name='b'), Track(name='c'),
|
||||
Track(name='d'), Track(name='e'), Track(name='f')]))
|
||||
self.assertEquals(self.b.current_playlist.version, 2)
|
||||
self.assertEquals(self.b.current_playlist.version, 1)
|
||||
result = self.h.handle_request(u'shuffle')
|
||||
self.assertEquals(self.b.current_playlist.version, 3)
|
||||
self.assertEquals(self.b.current_playlist.version, 2)
|
||||
self.assert_(u'OK' in result)
|
||||
|
||||
def test_shuffle_with_open_range(self):
|
||||
self.b.current_playlist.load(Playlist(tracks=[
|
||||
Track(name='a'), Track(name='b'), Track(name='c'),
|
||||
Track(name='d'), Track(name='e'), Track(name='f')]))
|
||||
self.assertEquals(self.b.current_playlist.version, 2)
|
||||
self.assertEquals(self.b.current_playlist.version, 1)
|
||||
result = self.h.handle_request(u'shuffle "4:"')
|
||||
self.assertEquals(self.b.current_playlist.version, 3)
|
||||
self.assertEquals(self.b.current_playlist.version, 2)
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[0].name, 'a')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[1].name, 'b')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[2].name, 'c')
|
||||
@ -775,9 +775,9 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
|
||||
self.b.current_playlist.load(Playlist(tracks=[
|
||||
Track(name='a'), Track(name='b'), Track(name='c'),
|
||||
Track(name='d'), Track(name='e'), Track(name='f')]))
|
||||
self.assertEquals(self.b.current_playlist.version, 2)
|
||||
self.assertEquals(self.b.current_playlist.version, 1)
|
||||
result = self.h.handle_request(u'shuffle "1:3"')
|
||||
self.assertEquals(self.b.current_playlist.version, 3)
|
||||
self.assertEquals(self.b.current_playlist.version, 2)
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[0].name, 'a')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[3].name, 'd')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[4].name, 'e')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user