PageRenderTime 36ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/silversupport/service/mongodb.py

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