diff --git a/orochi/backends/interface.py b/orochi/backends/interface.py index c9d1ace..984bfd4 100644 --- a/orochi/backends/interface.py +++ b/orochi/backends/interface.py @@ -14,36 +14,39 @@ class Player(object): @abc.abstractmethod def load(self, path): - """Load a file and play it. + """ + Load a file and play it. - Args: - path: - The path (url or filepath) to the file which should be played. + :param path: The path (url or filepath) to the file which should be played. + :type path: string """ @abc.abstractmethod def playpause(self): - """Pause or resume the playback of a song.""" + """ + Pause or resume the playback of a song. + """ @abc.abstractmethod def stop(self): - """Stop playback.""" + """ + Stop playback. + """ @abc.abstractmethod def volume(self, amount): - """Set the playback volume to ``amount`` percent. - - Args: - amount: - The volume level, must be a number between 0 and 100. + """ + Set the playback volume to ``amount`` percent. - Raises: - ValueError: - Raised when ``amount`` is invalid. + :param amount: The volume level, must be a number between 0 and 100. + :type amount: int + :raises ValueError: Raised when ``amount`` is invalid. """ @abc.abstractmethod def terminate(self): - """Terminate the instance.""" + """ + Terminate the instance. + """ diff --git a/orochi/backends/mpd.py b/orochi/backends/mpd.py index 56b1810..51680dd 100644 --- a/orochi/backends/mpd.py +++ b/orochi/backends/mpd.py @@ -23,7 +23,8 @@ def catch_mpd_error(msg): - """Decorator to catch MPD exceptions and convert them into a custom + """ + Decorator to catch MPD exceptions and convert them into a custom ``CommandError``. :param msg: The text to prepend to the exception message. @@ -45,7 +46,8 @@ def wrapper(self, *args, **kwargs): def mpd_client_factory(timeout): - """Helper function to return a connected MPD client instance. + """ + Helper function to return a connected MPD client instance. :param timeout: The number of seconds to wait for a command to finish. Default: 15. :type timeout: int @@ -58,8 +60,9 @@ def mpd_client_factory(timeout): class StatusThread(threading.Thread): - """A thread that runs in the background to check for song ending.""" - + """ + A thread that runs in the background to check for song ending. + """ def __init__(self, host, port, timeout): super(StatusThread, self).__init__() self._stop = False @@ -68,7 +71,9 @@ def __init__(self, host, port, timeout): self.port = port def run(self): - """Start the thread.""" + """ + Start the thread. + """ logger.debug('[status thread] Starting.') # Connect @@ -105,19 +110,24 @@ def run(self): logger.debug('[status thread] Exiting.') def stop(self): - """Stop the thread.""" + """ + Stop the thread. + """ logger.debug('[status thread] Setting stop flag.') self._stop = True def is_stopped(self): - """Return whether the thread is stopped.""" + """ + Return whether the thread is stopped. + """ return self._stop is True class MPDPlayer(Player): def __init__(self, timeout=15, *args, **kwargs): - """Create a new player process. + """ + Create a new player process. :param timeout: The number of seconds to wait for a command to finish. Default: 15. :type timeout: int @@ -137,7 +147,9 @@ def __init__(self, timeout=15, *args, **kwargs): @contextlib.contextmanager def connection(self): - """Context manager to connect to and disconnect from MPD.""" + """ + Context manager to connect to and disconnect from MPD. + """ try: self.client.connect(self.host, self.port) yield @@ -147,7 +159,8 @@ def connection(self): @catch_mpd_error('Could not load & play song.') def load(self, path): - """Load a file and play it. + """ + Load a file and play it. :param path: The path (url or filepath) to the file which should be played. :type path: string @@ -166,21 +179,26 @@ def load(self, path): @catch_mpd_error('Could not play or pause song.') def playpause(self): - """Pause or resume the playback of a song.""" + """ + Pause or resume the playback of a song. + """ logger.debug('[mpd player] Play/Pause.') with self.connection(): self.client.pause() @catch_mpd_error('Could not stop playback.') def stop(self): - """Stop playback.""" + """ + Stop playback. + """ logger.debug('[mpd player] Stop.') with self.connection(): self.client.stop() @catch_mpd_error('Could not set volume.') def volume(self, amount): - """Set the playback volume to ``amount`` percent. + """ + Set the playback volume to ``amount`` percent. :param amount: The volume level, must be a number between 0 and 100. :type amount: int @@ -197,6 +215,8 @@ def volume(self, amount): self.client.setvol(amount) def terminate(self): - """Terminate the instance.""" + """ + Terminate the instance. + """ logger.debug('[mpd player] Terminating.') self.status_thread.stop() diff --git a/orochi/client.py b/orochi/client.py index aade762..507edde 100644 --- a/orochi/client.py +++ b/orochi/client.py @@ -39,7 +39,8 @@ def get_prompt(mix): - """Return a prompt text based on the specified mix dictionary. + """ + Return a prompt text based on the specified mix dictionary. Args: mix: @@ -64,8 +65,10 @@ def get_prompt(mix): class ConfigFile(object): - """Wrap a json based config file. Behave like a dictionary. Persist data on - each write.""" + """ + Wrap a json based config file. Behave like a dictionary. Persist data on + each write. + """ DEFAULT_CONFIG_KEYS = ['mplayer_extra_arguments', 'username', 'password', 'autologin', 'results_per_page', 'results_sorting'] @@ -104,7 +107,9 @@ def __setitem__(self, key, value): self._persist() def _persist(self): - """Write current configuration to file.""" + """ + Write current configuration to file. + """ file_existed = os.path.isfile(self.filename) with open(self.filename, 'w') as configfile: configfile.write(json.dumps(self.config, indent=2)) @@ -118,7 +123,9 @@ def get(self, *args): class CmdExitMixin(object): - """A mixin for a Cmd instance that provides the exit and quit command.""" + """ + A mixin for a Cmd instance that provides the exit and quit command. + """ def do_exit(self, s=''): print('Goodbye.') @@ -172,7 +179,9 @@ def precmd(self, line): return super(Client, self).precmd(line) def cmdloop(self, intro=None): - """Ignore Ctrl+C.""" + """ + Ignore Ctrl+C. + """ if intro is not None: self.intro = intro try: @@ -182,7 +191,9 @@ def cmdloop(self, intro=None): self.cmdloop(intro='') def emptyline(self): - """Don't repeat last command on empty line.""" + """ + Don't repeat last command on empty line. + """ self.lastline_is_empty = True search_commands = ('search', 'search_tags', 'search_user', diff --git a/orochi/errors.py b/orochi/errors.py index b0167aa..62bd5a0 100644 --- a/orochi/errors.py +++ b/orochi/errors.py @@ -3,14 +3,20 @@ class CommandError(RuntimeError): - """Raised when a command could not be passed on to the player, or if an - error occured while executing it.""" + """ + Raised when a command could not be passed on to the player, or if an error + occured while executing it. + """ class TerminatedError(RuntimeError): - """An exception that is raised when interaction with the player is - attempted even if the background thread is already dead.""" + """ + An exception that is raised when interaction with the player is attempted + even if the background thread is already dead. + """ class InitializationError(RuntimeError): - """Raised when initialization of player failed.""" + """ + Raised when initialization of player failed. + """