From 4e2b511c06985698bd52aa9ad7879e7c42b1218c Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 12 Feb 2012 17:59:44 +0100 Subject: [PATCH] Optimized runner script --- CouchPotato.py | 4 +++- couchpotato/core/_base/updater/main.py | 2 +- couchpotato/core/logger.py | 2 +- couchpotato/core/plugins/automation/main.py | 2 +- couchpotato/core/plugins/base.py | 2 +- couchpotato/core/plugins/manage/main.py | 2 +- couchpotato/environment.py | 1 + couchpotato/runner.py | 20 +++++++++----------- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CouchPotato.py b/CouchPotato.py index 8b095bd..4529f7c 100755 --- a/CouchPotato.py +++ b/CouchPotato.py @@ -15,7 +15,7 @@ sys.path.insert(0, os.path.join(base_path, 'libs')) class Loader(object): - do_restart = True + do_restart = False def __init__(self): @@ -50,6 +50,8 @@ class Loader(object): try: from couchpotato.runner import runCouchPotato runCouchPotato(self.options, base_path, sys.argv[1:]) + except KeyboardInterrupt: + pass except Exception, e: self.log.critical(e) diff --git a/couchpotato/core/_base/updater/main.py b/couchpotato/core/_base/updater/main.py index a99013c..1ef2b00 100644 --- a/couchpotato/core/_base/updater/main.py +++ b/couchpotato/core/_base/updater/main.py @@ -64,7 +64,7 @@ class Updater(Plugin): return log.info('Checking for new version on github for %s' % self.repo_name) - if not Env.setting('development'): + if not Env.get('dev'): self.repo.fetch() current_branch = self.repo.getCurrentBranch().name diff --git a/couchpotato/core/logger.py b/couchpotato/core/logger.py index 6bfe197..97d0206 100644 --- a/couchpotato/core/logger.py +++ b/couchpotato/core/logger.py @@ -35,7 +35,7 @@ class CPLog(object): pass from couchpotato.environment import Env - if not Env.setting('development'): + if not Env.get('dev'): for replace in self.replace_private: msg = re.sub('(%s=)[^\&]+' % replace, '%s=xxx' % replace, msg) diff --git a/couchpotato/core/plugins/automation/main.py b/couchpotato/core/plugins/automation/main.py index 64a4c51..713b97a 100644 --- a/couchpotato/core/plugins/automation/main.py +++ b/couchpotato/core/plugins/automation/main.py @@ -10,7 +10,7 @@ class Automation(Plugin): def __init__(self): - if not Env.setting('development'): + if not Env.get('dev'): addEvent('app.load', self.addMovies) def addMovies(self): diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 6eb1d02..49b7322 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -174,7 +174,7 @@ class Plugin(object): def getCache(self, cache_key, url = None, timeout = 300): cache = Env.get('cache').get(cache_key) if cache: - if not Env.setting('development'): log.debug('Getting cache %s' % cache_key) + if not Env.get('dev'): log.debug('Getting cache %s' % cache_key) return cache if url: diff --git a/couchpotato/core/plugins/manage/main.py b/couchpotato/core/plugins/manage/main.py index 9184338..6810199 100644 --- a/couchpotato/core/plugins/manage/main.py +++ b/couchpotato/core/plugins/manage/main.py @@ -23,7 +23,7 @@ class Manage(Plugin): addEvent('manage.update', self.updateLibrary) addApiView('manage.update', self.updateLibraryView) - if not Env.setting('development'): + if not Env.get('dev'): addEvent('app.load', self.updateLibrary) def updateLibraryView(self): diff --git a/couchpotato/environment.py b/couchpotato/environment.py index 0b86657..a4d5074 100644 --- a/couchpotato/environment.py +++ b/couchpotato/environment.py @@ -8,6 +8,7 @@ class Env(object): _encoding = '' _uses_git = False _debug = False + _dev = False _settings = Settings() _loader = Loader() _cache = None diff --git a/couchpotato/runner.py b/couchpotato/runner.py index 88313f2..513e86e 100644 --- a/couchpotato/runner.py +++ b/couchpotato/runner.py @@ -11,7 +11,6 @@ import logging import os.path import sys import time -import traceback def getOptions(base_path, args): @@ -95,15 +94,21 @@ def runCouchPotato(options, base_path, args, desktop = None): debug = options.debug or Env.setting('debug', default = False, type = 'bool') Env.set('debug', debug) - if not Env.setting('development'): + # Development + development = Env.setting('development', default = False, type = 'bool') + Env.set('dev', development) + if not development: atexit.register(cleanup) + # Use reloader + reloader = debug is True and development and not Env.get('desktop') and not options.daemon + # Disable server access log logging.getLogger('werkzeug').setLevel(logging.WARNING) # Only run once when debugging fire_load = False - if os.environ.get('WERKZEUG_RUN_MAIN') or not debug or Env.get('desktop') or options.daemon: + if os.environ.get('WERKZEUG_RUN_MAIN') or not reloader: # Logger logger = logging.getLogger() @@ -168,7 +173,6 @@ def runCouchPotato(options, base_path, args, desktop = 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 Env.setting('development') and not Env.get('desktop') and not options.daemon # Basic config app.secret_key = api_key @@ -194,10 +198,4 @@ def runCouchPotato(options, base_path, args, desktop = None): if fire_load: fireEventAsync('app.load') # Go go go! - try: - app.run(**config) - except (KeyboardInterrupt, SystemExit): - raise - except: - log.error('Failed starting: %s' % traceback.format_exc()) - raise + app.run(**config)