Proper loading of plugins on debug

Restarting functions
This commit is contained in:
Ruud committed 2011-08-29 18:07:19 +02:00
1 parent f9c70d46fe
commit 9ff4d0bc91
7 files changed
+140 -32

No files matched your search

+2 -1
View File
@@ -1,7 +1,8 @@
from .main import Core
from uuid import uuid4
def start():
pass
return Core()
config = [{
'name': 'core',
+54
View File
@@ -0,0 +1,54 @@
from couchpotato.api import addApiView
from couchpotato.core.event import fireEvent
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
from flask import request
import os
log = CPLog(__name__)
class Core(Plugin):
def __init__(self):
addApiView('app.shutdown', self.shutdown)
addApiView('app.restart', self.restart)
self.removeRestartFile()
def shutdown(self):
self.initShutdown()
return 'shutdown'
def restart(self):
self.initShutdown(restart = True)
return 'restarting'
def initShutdown(self, restart = False):
fireEvent('app.shutdown')
if restart:
self.writeRestartFile()
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
def removeRestartFile(self):
try:
os.remove(self.restartFilePath())
except:
pass
def writeRestartFile(self):
try:
with open(self.restartFilePath(), 'w') as f:
f.write('This is the most suckiest way to register if CP is restarted. Ever...')
except Exception, e:
log.error('Could not write shutdown file: %s' % e)
def restartFilePath(self):
return os.path.join(Env.get('data_dir'), 'restart')
+1
View File
@@ -20,6 +20,7 @@ class Scheduler(Plugin):
addEvent('schedule.restart', self.start)
addEvent('app.load', self.start)
addEvent('app.shutdown', self.stop)
self.sched = Sched(misfire_grace_time = 60)
+1
View File
@@ -81,6 +81,7 @@ class Loader:
def loadPlugins(self, module, name):
try:
klass = module.start()
klass.registerPlugin()
if klass and getattr(klass, 'auto_register_static'):
klass.registerStatic(module.__file__)
+16 -1
View File
@@ -1,5 +1,5 @@
from couchpotato import addView
from couchpotato.core.event import fireEvent
from couchpotato.core.event import fireEvent, addEvent
from couchpotato.core.helpers.variable import getExt
from couchpotato.core.logger import CPLog
from couchpotato.environment import Env
@@ -16,6 +16,11 @@ class Plugin(object):
enabled_option = 'enabled'
auto_register_static = True
needs_shutdown = False
def registerPlugin(self):
addEvent('app.shutdown', self.doShutdown)
def conf(self, attr, default = None):
return Env.setting(attr, self.getName().lower(), default = default)
@@ -60,6 +65,16 @@ class Plugin(object):
except Exception, e:
log.error('Unable to create folder "%s": %s' % (path, e))
def doShutdown(self):
self.shuttingDown(True)
def shuttingDown(self, value = None):
if value is None:
return self.needs_shutdown
self.needs_shutdown = value
def isDisabled(self):
return not self.isEnabled()