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):
|
class Loader(object):
|
||||||
|
|
||||||
do_restart = True
|
do_restart = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
@@ -50,6 +50,8 @@ class Loader(object):
|
|||||||
try:
|
try:
|
||||||
from couchpotato.runner import runCouchPotato
|
from couchpotato.runner import runCouchPotato
|
||||||
runCouchPotato(self.options, base_path, sys.argv[1:])
|
runCouchPotato(self.options, base_path, sys.argv[1:])
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.log.critical(e)
|
self.log.critical(e)
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class Updater(Plugin):
|
|||||||
return
|
return
|
||||||
|
|
||||||
log.info('Checking for new version on github for %s' % self.repo_name)
|
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()
|
self.repo.fetch()
|
||||||
|
|
||||||
current_branch = self.repo.getCurrentBranch().name
|
current_branch = self.repo.getCurrentBranch().name
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class CPLog(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
from couchpotato.environment import Env
|
from couchpotato.environment import Env
|
||||||
if not Env.setting('development'):
|
if not Env.get('dev'):
|
||||||
|
|
||||||
for replace in self.replace_private:
|
for replace in self.replace_private:
|
||||||
msg = re.sub('(%s=)[^\&]+' % replace, '%s=xxx' % replace, msg)
|
msg = re.sub('(%s=)[^\&]+' % replace, '%s=xxx' % replace, msg)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Automation(Plugin):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
if not Env.setting('development'):
|
if not Env.get('dev'):
|
||||||
addEvent('app.load', self.addMovies)
|
addEvent('app.load', self.addMovies)
|
||||||
|
|
||||||
def addMovies(self):
|
def addMovies(self):
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ class Plugin(object):
|
|||||||
def getCache(self, cache_key, url = None, timeout = 300):
|
def getCache(self, cache_key, url = None, timeout = 300):
|
||||||
cache = Env.get('cache').get(cache_key)
|
cache = Env.get('cache').get(cache_key)
|
||||||
if cache:
|
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
|
return cache
|
||||||
|
|
||||||
if url:
|
if url:
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class Manage(Plugin):
|
|||||||
addEvent('manage.update', self.updateLibrary)
|
addEvent('manage.update', self.updateLibrary)
|
||||||
addApiView('manage.update', self.updateLibraryView)
|
addApiView('manage.update', self.updateLibraryView)
|
||||||
|
|
||||||
if not Env.setting('development'):
|
if not Env.get('dev'):
|
||||||
addEvent('app.load', self.updateLibrary)
|
addEvent('app.load', self.updateLibrary)
|
||||||
|
|
||||||
def updateLibraryView(self):
|
def updateLibraryView(self):
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class Env(object):
|
|||||||
_encoding = ''
|
_encoding = ''
|
||||||
_uses_git = False
|
_uses_git = False
|
||||||
_debug = False
|
_debug = False
|
||||||
|
_dev = False
|
||||||
_settings = Settings()
|
_settings = Settings()
|
||||||
_loader = Loader()
|
_loader = Loader()
|
||||||
_cache = None
|
_cache = None
|
||||||
|
|||||||
+9
-11
@@ -11,7 +11,6 @@ import logging
|
|||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
|
||||||
|
|
||||||
def getOptions(base_path, args):
|
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')
|
debug = options.debug or Env.setting('debug', default = False, type = 'bool')
|
||||||
Env.set('debug', debug)
|
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)
|
atexit.register(cleanup)
|
||||||
|
|
||||||
|
# Use reloader
|
||||||
|
reloader = debug is True and development and not Env.get('desktop') and not options.daemon
|
||||||
|
|
||||||
# Disable server access log
|
# Disable server access log
|
||||||
logging.getLogger('werkzeug').setLevel(logging.WARNING)
|
logging.getLogger('werkzeug').setLevel(logging.WARNING)
|
||||||
|
|
||||||
# Only run once when debugging
|
# Only run once when debugging
|
||||||
fire_load = False
|
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
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
@@ -168,7 +173,6 @@ def runCouchPotato(options, base_path, args, desktop = None):
|
|||||||
from couchpotato import app
|
from couchpotato import app
|
||||||
api_key = Env.setting('api_key')
|
api_key = Env.setting('api_key')
|
||||||
url_base = '/' + Env.setting('url_base').lstrip('/') if Env.setting('url_base') else ''
|
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
|
# Basic config
|
||||||
app.secret_key = api_key
|
app.secret_key = api_key
|
||||||
@@ -194,10 +198,4 @@ def runCouchPotato(options, base_path, args, desktop = None):
|
|||||||
if fire_load: fireEventAsync('app.load')
|
if fire_load: fireEventAsync('app.load')
|
||||||
|
|
||||||
# Go go go!
|
# Go go go!
|
||||||
try:
|
app.run(**config)
|
||||||
app.run(**config)
|
|
||||||
except (KeyboardInterrupt, SystemExit):
|
|
||||||
raise
|
|
||||||
except:
|
|
||||||
log.error('Failed starting: %s' % traceback.format_exc())
|
|
||||||
raise
|
|
||||||
|
|||||||
Reference in New Issue
Block a user