django-orchestra/orchestra/apps/saas/backends/drupalmu.py

36 lines
1.3 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
import os
from django.utils.translation import ugettext_lazy as _
2014-07-09 16:17:43 +00:00
from orchestra.apps.orchestration import ServiceController
2014-05-08 16:59:35 +00:00
from . import SaaSServiceMixin
2014-05-08 16:59:35 +00:00
from .. import settings
class DrupalMuBackend(SaaSServiceMixin, ServiceController):
2014-05-08 16:59:35 +00:00
verbose_name = _("Drupal multisite")
def save(self, webapp):
context = self.get_context(webapp)
self.append("mkdir %(drupal_path)s" % context)
self.append("chown -R www-data %(drupal_path)s" % context)
self.append(
"# the following assumes settings.php to be previously configured\n"
"REGEX='^\s*$databases\[.default.\]\[.default.\]\[.prefix.\]'\n"
"CONFIG='$databases[\'default\'][\'default\'][\'prefix\'] = \'%(app_name)s_\';'\n"
"if [[ ! $(grep $REGEX %(drupal_settings)s) ]]; then\n"
" echo $CONFIG >> %(drupal_settings)s\n"
"fi" % context
)
def selete(self, webapp):
context = self.get_context(webapp)
self.append("rm -fr %(app_path)s" % context)
def get_context(self, webapp):
context = super(DrupalMuBackend, self).get_context(webapp)
context['drupal_path'] = settings.WEBAPPS_DRUPAL_SITES_PATH % context
context['drupal_settings'] = os.path.join(context['drupal_path'], 'settings.php')
return context