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