From 044a23764d684ca388ab79af821171b833c10474 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 7 Jan 2012 22:57:53 +0100 Subject: [PATCH] End plugins before shutdown --- CouchPotato.py | 6 ++++++ couchpotato/core/_base/_core/main.py | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CouchPotato.py b/CouchPotato.py index bf5b1f7..8350ca6 100755 --- a/CouchPotato.py +++ b/CouchPotato.py @@ -6,6 +6,7 @@ from os.path import dirname import os import sys import subprocess +import time # Root path @@ -34,6 +35,8 @@ def start(): subprocess.call(args, env = new_environ) return os.path.isfile(os.path.join(base_path, 'restart')) + except KeyboardInterrupt, e: + pass except Exception, e: log.critical(e) return 0 @@ -52,4 +55,7 @@ if __name__ == '__main__': if not restart: break + from couchpotato.core.event import fireEvent + fireEvent('app.crappy_shutdown', single = True) + time.sleep(1) sys.exit() diff --git a/couchpotato/core/_base/_core/main.py b/couchpotato/core/_base/_core/main.py index 538495a..5de1c13 100644 --- a/couchpotato/core/_base/_core/main.py +++ b/couchpotato/core/_base/_core/main.py @@ -17,13 +17,14 @@ log = CPLog(__name__) class Core(Plugin): - ignore_restart = ['Core.crappyRestart'] + ignore_restart = ['Core.crappyRestart', 'Core.shutdown'] 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_restart', self.crappyRestart) addEvent('app.load', self.launchBrowser, priority = 100) addEvent('app.base_url', self.createBaseUrl) @@ -70,7 +71,7 @@ class Core(Plugin): if brk: break - time.sleep(300) + time.sleep(1) if restart: self.createFile(self.restartFilePath(), 'This is the most suckiest way to register if CP is restarted. Ever...')