django-orchestra/orchestra/contrib/webapps/backends/__init__.py

51 lines
1.6 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
import pkgutil
2014-10-10 14:39:46 +00:00
import textwrap
2014-05-08 16:59:35 +00:00
2015-04-05 18:02:36 +00:00
from orchestra.contrib.orchestration.backends import replace
from .. import settings
2014-05-08 16:59:35 +00:00
class WebAppServiceMixin(object):
model = 'webapps.WebApp'
directive = None
2014-05-08 16:59:35 +00:00
def create_webapp_dir(self, context):
self.append(textwrap.dedent("""\
CREATED=0
[[ ! -e %(app_path)s ]] && CREATED=1
mkdir -p %(app_path)s
chown %(user)s:%(group)s %(app_path)s
""") % context
)
2014-05-08 16:59:35 +00:00
def set_under_construction(self, context):
if context['under_construction_path']:
self.append(textwrap.dedent("""\
if [[ $CREATED == 1 ]]; then
cp -r %(under_construction_path)s %(app_path)s
chown -R %(user)s:%(group)s %(app_path)s
fi""") % context
)
2014-05-08 16:59:35 +00:00
def delete_webapp_dir(self, context):
self.append("rm -fr %(app_path)s" % context)
def get_context(self, webapp):
2015-04-05 18:02:36 +00:00
context = {
2014-10-23 15:38:46 +00:00
'user': webapp.get_username(),
'group': webapp.get_groupname(),
2015-03-04 21:06:16 +00:00
'app_name': webapp.name,
2014-05-08 16:59:35 +00:00
'type': webapp.type,
2014-10-10 14:39:46 +00:00
'app_path': webapp.get_path().rstrip('/'),
2014-05-08 16:59:35 +00:00
'banner': self.get_banner(),
2015-03-27 19:50:54 +00:00
'under_construction_path': settings.settings.WEBAPPS_UNDER_CONSTRUCTION_PATH,
'is_mounted': webapp.content_set.exists(),
2014-05-08 16:59:35 +00:00
}
2015-04-05 18:02:36 +00:00
replace(context, "'", '"')
2014-05-08 16:59:35 +00:00
for __, module_name, __ in pkgutil.walk_packages(__path__):
# sorry for the exec(), but Import module function fails :(
2014-05-08 16:59:35 +00:00
exec('from . import %s' % module_name)