Skip to content

Commit

Permalink
Changed docstring format
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Nov 12, 2014
1 parent 7b8f577 commit 0e323a2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 41 deletions.
33 changes: 18 additions & 15 deletions orochi/backends/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
48 changes: 34 additions & 14 deletions orochi/backends/mpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
25 changes: 18 additions & 7 deletions orochi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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']
Expand Down Expand Up @@ -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))
Expand All @@ -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.')
Expand Down Expand Up @@ -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:
Expand All @@ -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',
Expand Down
16 changes: 11 additions & 5 deletions orochi/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

0 comments on commit 0e323a2

Please sign in to comment.