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

45 lines
1.5 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
import os
2014-11-27 19:17:26 +00:00
import textwrap
2014-05-08 16:59:35 +00:00
from django.utils.translation import ugettext_lazy as _
2015-04-05 18:02:36 +00:00
from orchestra.contrib.orchestration import ServiceController, replace
2014-05-08 16:59:35 +00:00
from .. import settings
2014-11-27 19:17:26 +00:00
class DrupalMuBackend(ServiceController):
2015-04-24 11:39:20 +00:00
"""
Creates a Drupal site on a Drupal multisite installation
"""
2014-05-08 16:59:35 +00:00
verbose_name = _("Drupal multisite")
2015-06-09 11:16:36 +00:00
model = 'saas.SaaS'
default_route_match = "saas.service == 'drupal'"
2015-04-24 11:39:20 +00:00
doc_settings = (settings,
('SAAS_DRUPAL_SITES_PATH',)
)
2014-05-08 16:59:35 +00:00
def save(self, webapp):
context = self.get_context(webapp)
2014-11-27 19:17:26 +00:00
self.append(textwrap.dedent("""\
mkdir %(drupal_path)s
chown -R www-data %(drupal_path)s
# the following assumes settings.php to be previously configured
REGEX='^\s*$databases\[.default.\]\[.default.\]\[.prefix.\]'
CONFIG='$databases[\'default\'][\'default\'][\'prefix\'] = \'%(app_name)s_\';'
if [[ ! $(grep $REGEX %(drupal_settings)s) ]]; then
echo $CONFIG >> %(drupal_settings)s
fi""") % context
2014-05-08 16:59:35 +00:00
)
2014-11-27 19:17:26 +00:00
def delete(self, webapp):
2014-05-08 16:59:35 +00:00
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)
2015-04-24 11:39:20 +00:00
context['drupal_path'] = settings.SAAS_DRUPAL_SITES_PATH % context
2014-05-08 16:59:35 +00:00
context['drupal_settings'] = os.path.join(context['drupal_path'], 'settings.php')
2015-04-05 18:02:36 +00:00
return replace(context, "'", '"')