forked from platypush/platypush
Major rewrite for more modularity and maintanability
This commit is contained in:
parent
13023b660e
commit
bbb8bd9020
6 changed files with 136 additions and 24 deletions
lib/plugins
|
@ -1,4 +1,30 @@
|
|||
import os
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
class Plugin(object):
|
||||
def __init__(self):
|
||||
for cls in reversed(self.__class__.mro()):
|
||||
if cls is not object:
|
||||
try:
|
||||
cls._init(self)
|
||||
except AttributeError as e:
|
||||
pass
|
||||
|
||||
|
||||
def _init(self):
|
||||
module_dir = os.path.dirname(sys.modules[self.__module__].__file__)
|
||||
config_file = module_dir + os.sep + 'config.yaml'
|
||||
|
||||
config = {}
|
||||
|
||||
try:
|
||||
with open(config_file, 'r') as f:
|
||||
self.config = yaml.load(f)
|
||||
except FileNotFoundError as e:
|
||||
pass
|
||||
|
||||
|
||||
def run(self, args):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
|
28
lib/plugins/music/__init__.py
Normal file
28
lib/plugins/music/__init__.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from .. import Plugin
|
||||
|
||||
class MusicPlugin(Plugin):
|
||||
def run(self, args):
|
||||
if 'play' in args and self.status()['state'] != 'play':
|
||||
self.play()
|
||||
elif 'pause' in args and self.status()['state'] != 'pause':
|
||||
self.pause()
|
||||
elif 'stop' in args:
|
||||
self.stop()
|
||||
|
||||
return self.status()
|
||||
|
||||
def play(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def pause(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def stop(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def status(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
23
lib/plugins/music/mpd/__init__.py
Normal file
23
lib/plugins/music/mpd/__init__.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
import mpd
|
||||
|
||||
from .. import MusicPlugin
|
||||
|
||||
class MusicMpdPlugin(MusicPlugin):
|
||||
def _init(self):
|
||||
self.client = mpd.MPDClient(use_unicode=True)
|
||||
self.client.connect(self.config['host'], self.config['port'])
|
||||
|
||||
def play(self):
|
||||
self.client.play()
|
||||
|
||||
def pause(self):
|
||||
self.client.pause()
|
||||
|
||||
def stop(self):
|
||||
self.client.stop()
|
||||
|
||||
def status(self):
|
||||
return self.client.status()
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
6
lib/plugins/music/mpd/config.yaml
Normal file
6
lib/plugins/music/mpd/config.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
host: localhost
|
||||
port: 6600
|
||||
|
||||
_deps:
|
||||
- python-mpd2
|
||||
|
|
@ -18,7 +18,7 @@ class ShellPlugin(Plugin):
|
|||
except subprocess.CalledProcessError as e:
|
||||
error = e.output
|
||||
|
||||
return output, error
|
||||
return [output, error]
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue