public
Description:
Homepage: http://infogami.org
Clone URL: git://github.com/infogami/infogami.git
infogami / scripts / infobase_server
100755 68 lines (50 sloc) 1.665 kb
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
60
61
62
63
64
65
66
67
68
#! /usr/bin/env python
"""Script to run infobase.
 
USAGE:
 
* Run Infobase http server at port 7070.
 
$ python ./script/infobase_server infobase.yaml 7070
 
* Run Infobase as fastcgi server at port 7070
 
$ python ./script/infobase_server infobase.yaml fastcgi 7070
"""
import sys
import os, os.path
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
 
import yaml
import web
 
import infogami
from infogami.infobase import cache, config, lru, server
 
def setup_infobase():
    plugins = []
    # setup python path and load plugins
    sys.path += config.get('python_path', [])
    for p in config.get('plugins') or []:
        plugins.append(__import__(p, None, None, ["x"]))
        print >> web.debug, "loaded plugin", p
 
    if config.get('cache_size'):
        cache.global_cache = lru.LRU(config.cache_size)
 
    d = config.db_parameters
    web.config.db_parameters = dict(
        dbn=d.get('engine', 'postgres'),
        db=d['database'],
        user=d['username'],
        pw=d.get('password') or ''
    )
 
    if 'host' in d:
        web.config.db_parameters['host'] = d['host']
 
    for p in plugins:
        m = getattr(p, 'init_plugin', None)
        m and m()
 
def main():
    if len(sys.argv) < 2 or sys.argv[1] in ['-h', '--help']:
        print >> sys.stderr, "USAGE: %s configfile [port]" % (sys.argv[0])
        sys.exit(1)
 
    config_file = sys.argv[1]
    sys.argv = sys.argv[1:]
    runtime_config = yaml.load(open(config_file)) or {}
    for k, v in runtime_config.items():
        setattr(config, k, v)
 
    setup_infobase()
 
    from infogami.infobase import server
    server.run()
 
if __name__ == "__main__":
    main()