PageRenderTime 89ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/silversupport/service/couchdb.py

https://bitbucket.org/ianb/silverlining/
Python | 42 lines | 29 code | 9 blank | 4 comment | 5 complexity | 3a76cd3722fecafc1ab2dea5bc4ea931 MD5 | raw file
Possible License(s): GPL-2.0
  1. """CouchDB service support"""
  2. from json import loads
  3. from silversupport.shell import run
  4. from silversupport.abstractservice import AbstractService
  5. class Service(AbstractService):
  6. packages = ['couchdb']
  7. platform_packages = dict(python=['python-couchdb'])
  8. def install(self):
  9. # We lower the name because upper-case db names are not allowed in CouchDB
  10. app_name = self.app_config.app_name.lower()
  11. # Ensure that couchdb is installed
  12. self.install_packages()
  13. # Check to see if the database is present
  14. stdout, stderr, returncode = run(
  15. ['curl', '-s', '-N', 'http://localhost:5984/_all_dbs'],
  16. capture_stdout=True)
  17. dbs = loads(stdout)
  18. if app_name in dbs:
  19. self.output('Database %s already exists' % app_name)
  20. else:
  21. self.output('Database %s does not exist; created.' % app_name)
  22. run(['curl', '-N', '-s', '-X', 'PUT', 'http://localhost:5984/%s' % app_name])
  23. def env_setup(self):
  24. environ = {}
  25. app_name = self.app_config.app_name
  26. environ['CONFIG_COUCHDB_DB'] = app_name
  27. environ['CONFIG_COUCHDB_HOST'] = '127.0.0.1:5984'
  28. if self.devel:
  29. for name, value in self.devel_config.items():
  30. if name.startswith('couchdb.'):
  31. name = name[len('couchdb.'):]
  32. environ['CONFIG_COUCHDB_%s' % name.upper()] = value
  33. return environ