Make config file a start parameter
This commit is contained in:
1 parent
9bc7b11210
commit
5b3f6adae0
4 files changed
+31
-17
No files matched your search
+3
-3
@@ -18,7 +18,7 @@ from couchpotato.core.logger import CPLog
|
|||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
# Get options via arg
|
# Get options via arg
|
||||||
from couchpotato.cli import getOptions
|
from couchpotato.runner import getOptions
|
||||||
options = getOptions(base_path, sys.argv[1:])
|
options = getOptions(base_path, sys.argv[1:])
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
@@ -38,12 +38,12 @@ def start():
|
|||||||
log.critical(e)
|
log.critical(e)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
from couchpotato import cli
|
from couchpotato.runner import runCouchPotato
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
if os.environ.get('cp_main', 'false') == 'true':
|
if os.environ.get('cp_main', 'false') == 'true':
|
||||||
try:
|
try:
|
||||||
cli.cmd_couchpotato(options, base_path, sys.argv[1:])
|
runCouchPotato(options, base_path, sys.argv[1:])
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.critical(e)
|
log.critical(e)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ config = [{
|
|||||||
'label': 'Debug',
|
'label': 'Debug',
|
||||||
'description': 'Enable debugging.',
|
'description': 'Enable debugging.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'name': 'data_dir',
|
||||||
|
'label': 'Data dir',
|
||||||
|
'description': 'Where cache/logs/etc are stored.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'name': 'url_base',
|
'name': 'url_base',
|
||||||
'default': '',
|
'default': '',
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ class CPLog():
|
|||||||
return '[%+25.25s] %s' % (self.context[-25:], self.removePrivateData(msg))
|
return '[%+25.25s] %s' % (self.context[-25:], self.removePrivateData(msg))
|
||||||
|
|
||||||
def removePrivateData(self, msg):
|
def removePrivateData(self, msg):
|
||||||
|
try:
|
||||||
|
msg = unicode(msg)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|||||||
+18
-14
@@ -13,8 +13,8 @@ def getOptions(base_path, args):
|
|||||||
|
|
||||||
# Options
|
# Options
|
||||||
parser = ArgumentParser(prog = 'CouchPotato.py')
|
parser = ArgumentParser(prog = 'CouchPotato.py')
|
||||||
parser.add_argument('-s', '--datadir', default = os.path.join(base_path, '_data'),
|
parser.add_argument('-c', '--config_file', default = os.path.join(base_path, '_data', 'settings.conf'),
|
||||||
dest = 'data_dir', help = 'Absolute or ~/ path, where settings/logs/database data is saved (default ./_data)')
|
dest = 'config_file', help = 'Absolute or ~/ path of the settings file (default ./_data/settings.conf)')
|
||||||
parser.add_argument('-t', '--test', '--debug', action = 'store_true',
|
parser.add_argument('-t', '--test', '--debug', action = 'store_true',
|
||||||
dest = 'debug', help = 'Debug mode')
|
dest = 'debug', help = 'Debug mode')
|
||||||
parser.add_argument('-q', '--quiet', action = 'store_true',
|
parser.add_argument('-q', '--quiet', action = 'store_true',
|
||||||
@@ -26,38 +26,42 @@ def getOptions(base_path, args):
|
|||||||
|
|
||||||
options = parser.parse_args(args)
|
options = parser.parse_args(args)
|
||||||
|
|
||||||
options.data_dir = os.path.expanduser(options.data_dir)
|
options.config_file = os.path.expanduser(options.config_file)
|
||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
def cmd_couchpotato(options, base_path, args):
|
def runCouchPotato(options, base_path, args):
|
||||||
'''Commandline entry point.'''
|
|
||||||
|
# Load settings
|
||||||
|
from couchpotato.environment import Env
|
||||||
|
settings = Env.get('settings')
|
||||||
|
settings.setFile(options.config_file)
|
||||||
|
|
||||||
# Create data dir if needed
|
# Create data dir if needed
|
||||||
if not os.path.isdir(options.data_dir):
|
data_dir = os.path.expanduser(Env.setting('data_dir'))
|
||||||
os.makedirs(options.data_dir)
|
if data_dir == '':
|
||||||
|
data_dir = os.path.join(base_path, '_data')
|
||||||
|
if not os.path.isdir(data_dir):
|
||||||
|
os.makedirs(data_dir)
|
||||||
|
|
||||||
# Create logging dir
|
# Create logging dir
|
||||||
log_dir = os.path.join(options.data_dir, 'logs');
|
log_dir = os.path.join(data_dir, 'logs');
|
||||||
if not os.path.isdir(log_dir):
|
if not os.path.isdir(log_dir):
|
||||||
os.mkdir(log_dir)
|
os.mkdir(log_dir)
|
||||||
|
|
||||||
|
|
||||||
# Daemonize app
|
# Daemonize app
|
||||||
if options.daemonize:
|
if options.daemonize:
|
||||||
createDaemon()
|
createDaemon()
|
||||||
|
|
||||||
|
|
||||||
# Register environment settings
|
# Register environment settings
|
||||||
from couchpotato.environment import Env
|
|
||||||
Env.get('settings').setFile(os.path.join(options.data_dir, 'settings.conf'))
|
|
||||||
Env.set('uses_git', not options.git)
|
Env.set('uses_git', not options.git)
|
||||||
Env.set('app_dir', base_path)
|
Env.set('app_dir', base_path)
|
||||||
Env.set('data_dir', options.data_dir)
|
Env.set('data_dir', data_dir)
|
||||||
Env.set('log_path', os.path.join(log_dir, 'CouchPotato.log'))
|
Env.set('log_path', os.path.join(log_dir, 'CouchPotato.log'))
|
||||||
Env.set('db_path', 'sqlite:///' + os.path.join(options.data_dir, 'couchpotato.db'))
|
Env.set('db_path', 'sqlite:///' + os.path.join(data_dir, 'couchpotato.db'))
|
||||||
Env.set('cache_dir', os.path.join(options.data_dir, 'cache'))
|
Env.set('cache_dir', os.path.join(data_dir, 'cache'))
|
||||||
Env.set('cache', FileSystemCache(os.path.join(Env.get('cache_dir'), 'python')))
|
Env.set('cache', FileSystemCache(os.path.join(Env.get('cache_dir'), 'python')))
|
||||||
Env.set('quiet', options.quiet)
|
Env.set('quiet', options.quiet)
|
||||||
Env.set('daemonize', options.daemonize)
|
Env.set('daemonize', options.daemonize)
|
||||||
|
|||||||
Reference in new issue
Block a user