Browse Source

Make config file a start parameter

pull/51/merge
Ruud 14 years ago
parent
commit
5b3f6adae0
  1. 6
      CouchPotato.py
  2. 5
      couchpotato/core/_base/_core/__init__.py
  3. 5
      couchpotato/core/logger.py
  4. 32
      couchpotato/runner.py

6
CouchPotato.py

@ -18,7 +18,7 @@ from couchpotato.core.logger import CPLog
log = CPLog(__name__)
# Get options via arg
from couchpotato.cli import getOptions
from couchpotato.runner import getOptions
options = getOptions(base_path, sys.argv[1:])
def start():
@ -38,12 +38,12 @@ def start():
log.critical(e)
return 0
from couchpotato import cli
from couchpotato.runner import runCouchPotato
if __name__ == '__main__':
if os.environ.get('cp_main', 'false') == 'true':
try:
cli.cmd_couchpotato(options, base_path, sys.argv[1:])
runCouchPotato(options, base_path, sys.argv[1:])
except Exception, e:
log.critical(e)
else:

5
couchpotato/core/_base/_core/__init__.py

@ -64,6 +64,11 @@ config = [{
'description': 'Enable debugging.',
},
{
'name': 'data_dir',
'label': 'Data dir',
'description': 'Where cache/logs/etc are stored.',
},
{
'name': 'url_base',
'default': '',
'label': 'Url Base',

5
couchpotato/core/logger.py

@ -33,6 +33,11 @@ class CPLog():
return '[%+25.25s] %s' % (self.context[-25:], self.removePrivateData(msg))
def removePrivateData(self, msg):
try:
msg = unicode(msg)
except:
pass
for replace in self.replace_private:
msg = re.sub('(%s=)[^\&]+' % replace, '%s=xxx' % replace, msg)

32
couchpotato/runner.py

@ -13,8 +13,8 @@ def getOptions(base_path, args):
# Options
parser = ArgumentParser(prog = 'CouchPotato.py')
parser.add_argument('-s', '--datadir', default = os.path.join(base_path, '_data'),
dest = 'data_dir', help = 'Absolute or ~/ path, where settings/logs/database data is saved (default ./_data)')
parser.add_argument('-c', '--config_file', default = os.path.join(base_path, '_data', 'settings.conf'),
dest = 'config_file', help = 'Absolute or ~/ path of the settings file (default ./_data/settings.conf)')
parser.add_argument('-t', '--test', '--debug', action = 'store_true',
dest = 'debug', help = 'Debug mode')
parser.add_argument('-q', '--quiet', action = 'store_true',
@ -26,38 +26,42 @@ def getOptions(base_path, 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
def cmd_couchpotato(options, base_path, args):
'''Commandline entry point.'''
def runCouchPotato(options, base_path, args):
# Load settings
from couchpotato.environment import Env
settings = Env.get('settings')
settings.setFile(options.config_file)
# Create data dir if needed
if not os.path.isdir(options.data_dir):
os.makedirs(options.data_dir)
data_dir = os.path.expanduser(Env.setting('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
log_dir = os.path.join(options.data_dir, 'logs');
log_dir = os.path.join(data_dir, 'logs');
if not os.path.isdir(log_dir):
os.mkdir(log_dir)
# Daemonize app
if options.daemonize:
createDaemon()
# 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('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('db_path', 'sqlite:///' + os.path.join(options.data_dir, 'couchpotato.db'))
Env.set('cache_dir', os.path.join(options.data_dir, 'cache'))
Env.set('db_path', 'sqlite:///' + os.path.join(data_dir, 'couchpotato.db'))
Env.set('cache_dir', os.path.join(data_dir, 'cache'))
Env.set('cache', FileSystemCache(os.path.join(Env.get('cache_dir'), 'python')))
Env.set('quiet', options.quiet)
Env.set('daemonize', options.daemonize)

Loading…
Cancel
Save