Desktop App classes
This commit is contained in:
1 parent
20d564ad93
commit
261794a562
3 files changed
+35
-31
No files matched your search
@@ -18,14 +18,14 @@ log = CPLog(__name__)
|
||||
|
||||
class Core(Plugin):
|
||||
|
||||
ignore_restart = ['Core.crappyRestart', 'Core.shutdown']
|
||||
ignore_restart = ['Core.crappyRestart', 'Core.crappyShutdown']
|
||||
|
||||
def __init__(self):
|
||||
addApiView('app.shutdown', self.shutdown)
|
||||
addApiView('app.restart', self.restart)
|
||||
addApiView('app.available', self.available)
|
||||
|
||||
addEvent('app.crappy_shutdown', self.shutdown)
|
||||
addEvent('app.crappy_shutdown', self.crappyShutdown)
|
||||
addEvent('app.crappy_restart', self.crappyRestart)
|
||||
addEvent('app.load', self.launchBrowser, priority = 1)
|
||||
addEvent('app.base_url', self.createBaseUrl)
|
||||
@@ -42,6 +42,12 @@ class Core(Plugin):
|
||||
'succes': True
|
||||
})
|
||||
|
||||
def crappyShutdown(self):
|
||||
ctx = app.test_request_context()
|
||||
ctx.push()
|
||||
self.urlopen('%s%sapp.shutdown' % (fireEvent('app.base_url', single = True), url_for('api.index')))
|
||||
ctx.pop()
|
||||
|
||||
def crappyRestart(self):
|
||||
ctx = app.test_request_context()
|
||||
ctx.push()
|
||||
@@ -77,18 +83,14 @@ class Core(Plugin):
|
||||
if restart:
|
||||
self.createFile(self.restartFilePath(), 'This is the most suckiest way to register if CP is restarted. Ever...')
|
||||
|
||||
log.debug('Save to shutdown/restart')
|
||||
|
||||
try:
|
||||
request.environ.get('werkzeug.server.shutdown')()
|
||||
except:
|
||||
try:
|
||||
ctx = app.test_request_context()
|
||||
ctx.push()
|
||||
request.environ.get('werkzeug.server.shutdown')()
|
||||
ctx.pop()
|
||||
except TypeError:
|
||||
pass
|
||||
except:
|
||||
log.error('Failed shutting down the server: %s' % traceback.format_exc())
|
||||
log.error('Failed shutting down the server: %s' % traceback.format_exc())
|
||||
|
||||
fireEvent('app.after_shutdown', restart = restart)
|
||||
|
||||
def removeRestartFile(self):
|
||||
try:
|
||||
|
||||
@@ -2,24 +2,31 @@ 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 urllib import quote
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
if Env.get('desktop'):
|
||||
|
||||
class Desktop(Plugin):
|
||||
#import os
|
||||
#import sys
|
||||
import wx
|
||||
|
||||
def __init__(self):
|
||||
class Desktop(Plugin):
|
||||
|
||||
if not Env.get('binary_port'):
|
||||
return
|
||||
def __init__(self):
|
||||
|
||||
addEvent('app.load', self.settingsToDesktop, priority = 2)
|
||||
desktop = Env.get('desktop')
|
||||
desktop.setSettings({
|
||||
'url': fireEvent('app.base_url', single = True)
|
||||
})
|
||||
|
||||
def settingsToDesktop(self):
|
||||
def onClose(event):
|
||||
return fireEvent('app.crappy_shutdown')
|
||||
desktop.close_handler = onClose
|
||||
|
||||
base_url = fireEvent('app.base_url', single = True)
|
||||
base_url_api = '%s/%s' % (base_url, Env.setting('api_key'))
|
||||
addEvent('app.after_shutdown', desktop.afterShutdown)
|
||||
|
||||
url_data = '{"host": "%s", "api": "%s"}' % (base_url, base_url_api)
|
||||
self.urlopen('http://localhost:%s/%s' % (Env.get('binary_port'), quote(url_data)))
|
||||
else:
|
||||
|
||||
class Desktop(Plugin):
|
||||
pass
|
||||
@@ -26,8 +26,6 @@ def getOptions(base_path, args):
|
||||
dest = 'console_log', help = "Log to console")
|
||||
parser.add_argument('--quiet', action = 'store_true',
|
||||
dest = 'quiet', help = 'No console logging')
|
||||
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')
|
||||
|
||||
@@ -38,16 +36,13 @@ def getOptions(base_path, args):
|
||||
return options
|
||||
|
||||
|
||||
def runCouchPotato(options, base_path, args, handle = None):
|
||||
def runCouchPotato(options, base_path, args, desktop = None):
|
||||
|
||||
# Load settings
|
||||
from couchpotato.environment import Env
|
||||
settings = Env.get('settings')
|
||||
settings.setFile(options.config_file)
|
||||
|
||||
if handle:
|
||||
handle(Env)
|
||||
|
||||
# Create data dir if needed
|
||||
data_dir = os.path.expanduser(Env.setting('data_dir'))
|
||||
if data_dir == '':
|
||||
@@ -72,7 +67,7 @@ def runCouchPotato(options, base_path, args, handle = None):
|
||||
Env.set('cache', FileSystemCache(os.path.join(Env.get('cache_dir'), 'python')))
|
||||
Env.set('console_log', options.console_log)
|
||||
Env.set('quiet', options.quiet)
|
||||
Env.set('binary_port', options.binary_port)
|
||||
Env.set('desktop', desktop)
|
||||
Env.set('args', args)
|
||||
Env.set('options', options)
|
||||
|
||||
@@ -86,7 +81,7 @@ def runCouchPotato(options, base_path, args, handle = None):
|
||||
|
||||
# Only run once when debugging
|
||||
fire_load = False
|
||||
if os.environ.get('WERKZEUG_RUN_MAIN') or not debug or options.binary_port:
|
||||
if os.environ.get('WERKZEUG_RUN_MAIN') or not debug or Env.get('desktop'):
|
||||
|
||||
# Logger
|
||||
logger = logging.getLogger()
|
||||
@@ -151,7 +146,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.binary_port
|
||||
reloader = debug is True and not Env.get('desktop')
|
||||
|
||||
# Basic config
|
||||
app.secret_key = api_key
|
||||
|
||||
Reference in new issue
Block a user