forked from platypush/platypush
Renamed project from notiier to runbullet
This commit is contained in:
parent
2837d0df70
commit
7b5813e151
12 changed files with 30 additions and 1 deletions
runbullet/lib/plugins
32
runbullet/lib/plugins/__init__.py
Normal file
32
runbullet/lib/plugins/__init__.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
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()
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
28
runbullet/lib/plugins/music/__init__.py
Normal file
28
runbullet/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
runbullet/lib/plugins/music/mpd/__init__.py
Normal file
23
runbullet/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
runbullet/lib/plugins/music/mpd/config.yaml
Normal file
6
runbullet/lib/plugins/music/mpd/config.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
host: localhost
|
||||
port: 6600
|
||||
|
||||
_deps:
|
||||
- python-mpd2
|
||||
|
24
runbullet/lib/plugins/shell/__init__.py
Normal file
24
runbullet/lib/plugins/shell/__init__.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import subprocess
|
||||
|
||||
from .. import Plugin
|
||||
|
||||
class ShellPlugin(Plugin):
|
||||
def run(self, args):
|
||||
if 'cmd' not in args:
|
||||
raise RuntimeError('No cmd parameter specified')
|
||||
|
||||
cmd = args['cmd']
|
||||
output = None
|
||||
error = None
|
||||
|
||||
try:
|
||||
output = subprocess.check_output(cmd,
|
||||
stderr=subprocess.STDOUT,
|
||||
shell=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
error = e.output
|
||||
|
||||
return [output, error]
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue