-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathckanroot
56 lines (44 loc) · 1.67 KB
/
ckanroot
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
#!/usr/lib/ckan/bin/python
import sys
import os
from pkg_resources import load_entry_point
assert os.getuid() in 0, 'need to be root'
paster_commands = ['create', 'help','make-config',
'points','post','request',
'serve','setup-app']
instance = None
config = False
for num, arg in enumerate(sys.argv):
if arg[:2] == '-i':
instance = sys.argv[num + 1]
sys.argv.pop(num)
sys.argv.pop(num)
if arg[:2] == '-c' or arg.startswith('--config'):
config = True
if not config and not instance:
try:
config_file = '/etc/ckan/production.ini'
fh = open(config_file)
except IOError as e:
raise Exception('No production.ini in /etc/ckan/. '
'Either create one from production.ini.temp or use '
'-i instance_name or -c config_file')
if not config and instance:
try:
config_file = '/etc/ckan/{instance}/production.ini'.format(instance=instance)
fh = open(config_file)
except IOError as e:
raise Exception('config file for instance "{instance}" does not exist. '
'It should be located at "{config}"'.format(instance=instance, config=config_file))
if not config and len(sys.argv) > 1:
if sys.argv[1] not in paster_commands:
sys.argv.append('-c')
sys.argv.append(config_file)
# paster commands just accept config file as last arg
if sys.argv[1] in ['serve', 'setup-app']:
sys.argv.append(config_file)
sys.argv.insert(1, '--plugin=ckan')
if __name__ == '__main__':
sys.exit(
load_entry_point('PasteScript', 'console_scripts', 'paster')()
)