Crappy restarting

This commit is contained in:
Ruud
2011-11-07 22:19:13 +01:00
parent d0da98a86b
commit 4f0006db9f
2 changed files with 24 additions and 7 deletions
+22 -6
View File
@@ -1,3 +1,4 @@
from couchpotato import app
from couchpotato.api import addApiView from couchpotato.api import addApiView
from couchpotato.core.event import fireEvent, addEvent from couchpotato.core.event import fireEvent, addEvent
from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.helpers.variable import cleanHost
@@ -5,6 +6,7 @@ from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env from couchpotato.environment import Env
from flask import request from flask import request
from flask.helpers import url_for
import os import os
import time import time
import webbrowser import webbrowser
@@ -14,14 +16,24 @@ log = CPLog(__name__)
class Core(Plugin): class Core(Plugin):
ignore_restart = ['Core.crappyRestart']
def __init__(self): def __init__(self):
addApiView('app.shutdown', self.shutdown) addApiView('app.shutdown', self.shutdown)
addApiView('app.restart', self.restart) addApiView('app.restart', self.restart)
addEvent('app.crappy_restart', self.crappyRestart)
addEvent('app.load', self.launchBrowser, priority = 100) addEvent('app.load', self.launchBrowser, priority = 100)
addEvent('app.base_url', self.createBaseUrl)
self.removeRestartFile() self.removeRestartFile()
def crappyRestart(self):
ctx = app.test_request_context()
ctx.push()
self.urlopen('%s%sapp.restart' % (fireEvent('app.base_url', single = True), url_for('api.index')))
ctx.pop()
def shutdown(self): def shutdown(self):
self.initShutdown() self.initShutdown()
return 'shutdown' return 'shutdown'
@@ -39,6 +51,7 @@ class Core(Plugin):
brk = True brk = True
for running in still_running: for running in still_running:
running = list(set(running) - set(self.ignore_restart))
if len(running) > 0: if len(running) > 0:
log.info('Waiting on plugins to finish: %s' % running) log.info('Waiting on plugins to finish: %s' % running)
brk = False brk = False
@@ -69,12 +82,7 @@ class Core(Plugin):
if Env.setting('launch_browser'): if Env.setting('launch_browser'):
log.info('Launching browser') log.info('Launching browser')
host = Env.setting('host') url = self.createBaseUrl()
if host == '0.0.0.0':
host = 'localhost'
port = Env.setting('port')
url = '%s:%d' % (cleanHost(host).rstrip('/'), int(port))
try: try:
webbrowser.open(url, 2, 1) webbrowser.open(url, 2, 1)
except: except:
@@ -82,3 +90,11 @@ class Core(Plugin):
webbrowser.open(url, 1, 1) webbrowser.open(url, 1, 1)
except: except:
log.error('Could not launch a browser.') log.error('Could not launch a browser.')
def createBaseUrl(self):
host = Env.setting('host')
if host == '0.0.0.0':
host = 'localhost'
port = Env.setting('port')
return '%s:%d' % (cleanHost(host).rstrip('/'), int(port))
+2 -1
View File
@@ -79,7 +79,8 @@ class Updater(Plugin):
if local.getDate() < remote.getDate(): if local.getDate() < remote.getDate():
if self.conf('automatic') and not self.update_failed: if self.conf('automatic') and not self.update_failed:
self.doUpdate() if self.doUpdate():
fireEvent('app.crappy_restart')
else: else:
self.update_version = { self.update_version = {
'hash': remote.hash[:8], 'hash': remote.hash[:8],