diff --git a/couchpotato/core/_base/desktop/__init__.py b/couchpotato/core/_base/desktop/__init__.py new file mode 100644 index 0000000..064492f --- /dev/null +++ b/couchpotato/core/_base/desktop/__init__.py @@ -0,0 +1,6 @@ +from .main import Desktop + +def start(): + return Desktop() + +config = [] diff --git a/couchpotato/core/_base/desktop/main.py b/couchpotato/core/_base/desktop/main.py new file mode 100644 index 0000000..8067d2e --- /dev/null +++ b/couchpotato/core/_base/desktop/main.py @@ -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))) diff --git a/couchpotato/runner.py b/couchpotato/runner.py index a693c4f..1b2f1e6 100644 --- a/couchpotato/runner.py +++ b/couchpotato/runner.py @@ -26,8 +26,8 @@ def getOptions(base_path, args): dest = 'daemonize', help = 'Daemonize the app') parser.add_argument('--quiet', action = 'store_true', dest = 'quiet', help = 'No console logging') - parser.add_argument('--binary', action = 'store_true', - dest = 'binary', help = 'Running from binary build') + parser.add_argument('--binary_port', default = None, + dest = 'binary_port', help = 'Running from binary build') parser.add_argument('--nogit', action = 'store_true', dest = 'nogit', help = 'No git available') @@ -77,7 +77,7 @@ def runCouchPotato(options, base_path, args, handle = None): Env.set('console_log', options.console_log) Env.set('daemonize', options.daemonize) Env.set('quiet', options.quiet) - Env.set('binary', options.binary) + Env.set('binary_port', options.binary_port) Env.set('args', args) Env.set('options', options) @@ -90,7 +90,7 @@ def runCouchPotato(options, base_path, args, handle = None): server_log.disabled = True # Only run once when debugging - if os.environ.get('WERKZEUG_RUN_MAIN') or not debug or options.binary: + if os.environ.get('WERKZEUG_RUN_MAIN') or not debug or options.binary_port: # Logger logger = logging.getLogger() @@ -155,7 +155,7 @@ def runCouchPotato(options, base_path, args, handle = None): from couchpotato import app api_key = Env.setting('api_key') url_base = '/' + Env.setting('url_base').lstrip('/') if Env.setting('url_base') else '' - reloader = debug is True and not options.daemonize and not options.binary + reloader = debug is True and not options.daemonize and not options.binary_port # Basic config app.secret_key = api_key