Plugin to send data to desktop CP

This commit is contained in:
Ruud
2012-01-07 22:58:26 +01:00
parent 044a23764d
commit cf581d8f9d
3 changed files with 41 additions and 5 deletions
@@ -0,0 +1,6 @@
from .main import Desktop
def start():
return Desktop()
config = []
+30
View File
@@ -0,0 +1,30 @@
from couchpotato import app
from couchpotato.core.event import fireEvent, addEvent
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
from flask.helpers import url_for
import urllib
log = CPLog(__name__)
class Desktop(Plugin):
def __init__(self):
if not Env.get('binary'):
return
addEvent('app.load', self.settingsToDesktop)
def settingsToDesktop(self):
ctx = app.test_request_context()
ctx.push()
base_url = fireEvent('app.base_url', single = True)
base_url_api = '%s/%s' % (base_url, url_for('api.index'))
ctx.pop()
url_data = '{"host": "%s", "api": "%s"}' % (base_url, base_url_api)
self.urlopen('http://localhost:%s/' % (Env.get('binary_port'), urllib.quote(url_data)))