Optimized runner script
This commit is contained in:
+3
-1
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -8,6 +8,7 @@ class Env(object):
|
||||
_encoding = ''
|
||||
_uses_git = False
|
||||
_debug = False
|
||||
_dev = False
|
||||
_settings = Settings()
|
||||
_loader = Loader()
|
||||
_cache = None
|
||||
|
||||
+9
-11
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user