Skip to content

Commit

Permalink
Merge pull request #2005 from ckan/1597-config
Browse files Browse the repository at this point in the history
Allows use of CKAN_INI env-var to locate config
  • Loading branch information
David Read committed Nov 18, 2014
2 parents 5cae303 + 44c8c7c commit 0ddd6fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
22 changes: 16 additions & 6 deletions ckan/lib/cli.py
Expand Up @@ -106,7 +106,7 @@ class CkanCommand(paste.script.command.Command):
'''
parser = paste.script.command.Command.standard_parser(verbose=True)
parser.add_option('-c', '--config', dest='config',
default='development.ini', help='Config file to use.')
help='Config file to use.')
parser.add_option('-f', '--file',
action='store',
dest='file_path',
Expand All @@ -116,12 +116,22 @@ class CkanCommand(paste.script.command.Command):

def _get_config(self):
from paste.deploy import appconfig
if not self.options.config:
msg = 'No config file supplied'
raise self.BadCommand(msg)
self.filename = os.path.abspath(self.options.config)

if self.options.config:
self.filename = os.path.abspath(self.options.config)
config_source = '-c parameter'
elif os.environ.get('CKAN_INI'):
self.filename = os.environ.get('CKAN_INI')
config_source = '$CKAN_INI'
else:
self.filename = 'development.ini'
config_source = 'default value'

if not os.path.exists(self.filename):
raise AssertionError('Config filename %r does not exist.' % self.filename)
msg = 'Config file not found: %s' % self.filename
msg += '\n(Given by: %s)' % config_source
raise self.BadCommand(msg)

fileConfig(self.filename)
return appconfig('config:' + self.filename)

Expand Down
11 changes: 11 additions & 0 deletions doc/maintaining/paster.rst
Expand Up @@ -49,6 +49,17 @@ examples below, this option can be given as ``-c`` for short.
to execute. Most commands have their own subcommands and options. For example,
to print out a list of all of your CKAN site's users do:

.. note::

You may also specify the location of your config file using the CKAN_INI
environment variable. You will no longer need to use --config= or -c= to
tell paster where the config file is:

.. parsed-literal::
export CKAN_INI=\ |development.ini|
.. parsed-literal::
paster user list -c |development.ini|
Expand Down

0 comments on commit 0ddd6fd

Please sign in to comment.