PageRenderTime 91ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 47ms app.codeStats 0ms

/silversupport/service/mongodb.py

https://bitbucket.org/ianb/silverlining/
Python | 40 lines | 18 code | 9 blank | 13 comment | 4 complexity | 6fea15a98a4742041b6bb41d2cb5ab6d MD5 | raw file
 1"""MongoDB support"""
 2
 3from silversupport.shell import run, apt_install
 4from silversupport.abstractservice import AbstractService
 5
 6
 7class Service(AbstractService):
 8
 9    def install(self):
10        #WARNING, this will only work on ubuntu 9.10
11        #since we don't have official ubuntu packages we use 10gen's PPA
12
13        #FIXME, add-apt-repository will duplicate if run twice:
14        run(['add-apt-repository', "deb http://downloads.mongodb.org/distros/ubuntu 9.10 10gen"])
15        run(['apt-get', 'update'])
16        apt_install(['mongodb'])
17
18        #TODO Check to see if the database is present like couch does, seudo code below
19
20    #    app_name = app_config.app_name
21    #    stdout,stderr = run('curl -s -N http://localhost:28017/???'
22    #    dbs = eval(stdout)
23
24    #    if app_name in dbs:
25    #        print 'Database %s already exists' % app_name
26    #    else:
27    #        print 'Database %s does not exist; created.' % app_name
28    #        run('curl -N -s -X PUT http://localhost:28017/???' % app_name,env)
29
30    def env_setup(self):
31        environ = {}
32        app_name = self.app_config.app_name
33        environ['CONFIG_MONGODB_DB'] = app_name
34        environ['CONFIG_MONGODB_HOST'] = '127.0.0.1:5984'
35        if self.devel:
36            for name, value in self.devel_config.items():
37                if name.startswith('mongodb.'):
38                    name = name[len('mongodb.'):]
39                    environ['CONFIG_MONGODB_%s' % name.upper()] = value
40        return environ