-
Notifications
You must be signed in to change notification settings - Fork 2k
/
__init__.py
59 lines (47 loc) · 1.8 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# encoding: utf-8
import os
import click
import logging
from flask import Flask, current_app
from flask.cli import AppGroup, with_appcontext
from werkzeug.serving import run_simple
from ckan.common import config
from ckan.config.environment import load_environment
from ckan.config.middleware import make_app
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s [%(name)s] %(message)s')
click_config_option = click.option(
u'-c',
u'--config',
default=None,
metavar=u'CONFIG',
help=u'Config file to use (default: development.ini)')
def load_config(config=None):
import pdb; pdb.set_trace()
from paste.deploy import appconfig
from paste.script.util.logging_config import fileConfig
log.info("Searching for configuration file")
if config:
filename = os.path.abspath(config)
config_source = u'-c parameter'
elif os.environ.get(u'CKAN_INI'):
filename = os.environ.get(u'CKAN_INI')
config_source = u'$CKAN_INI'
else:
default_filename = u'development.ini'
filename = os.path.join(os.getcwd(), default_filename)
if not os.path.exists(filename):
# give really clear error message for this common situation
msg = u'ERROR: You need to specify the CKAN config (.ini) '\
u'file path.'\
u'\nUse the --config parameter or set environment ' \
u'variable CKAN_INI or have {}\nin the current directory.' \
.format(default_filename)
exit(msg)
if not os.path.exists(filename):
msg = u'Config file not found: %s' % filename
msg += u'\n(Given by: %s)' % config_source
exit(msg)
fileConfig(filename)
return appconfig(u'config:' + filename)