From 0a522884a7ba8b3b768111a19a32f1c0f3310cce Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 27 Oct 2014 15:15:22 +0000 Subject: [PATCH] Fixes on mailman backend --- orchestra/apps/domains/backends.py | 6 +++--- orchestra/apps/lists/backends.py | 14 ++++++++------ orchestra/apps/orchestration/methods.py | 6 ++++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/orchestra/apps/domains/backends.py b/orchestra/apps/domains/backends.py index c5a1f085..137c5f9a 100644 --- a/orchestra/apps/domains/backends.py +++ b/orchestra/apps/domains/backends.py @@ -40,7 +40,7 @@ class Bind9MasterDomainBackend(ServiceController): self.append(textwrap.dedent("""\ sed '/zone "%(name)s".*/,/^\s*};\s*$/!d' %(conf_path)s | diff -B -I"^\s*//" - <(echo '%(conf)s') || { sed -i -e '/zone\s\s*"%(name)s".*/,/^\s*};/d' \\ - -e 'N; /^\\n$/d; P; D' %(conf_path)s + -e 'N; /^\s*\\n\s*$/d; P; D' %(conf_path)s echo '%(conf)s' >> %(conf_path)s UPDATED=1 }""" % context @@ -48,7 +48,7 @@ class Bind9MasterDomainBackend(ServiceController): # Delete ex-top-domains that are now subdomains self.append(textwrap.dedent("""\ sed -i -e '/zone\s\s*".*\.%(name)s".*/,/^\s*};\s*$/d' \\ - -e 'N; /^\\n$/d; P; D' %(conf_path)s""" % context + -e 'N; /^\s*\\n\s*$/d; P; D' %(conf_path)s""" % context )) if 'zone_path' in context: context['zone_subdomains_path'] = re.sub(r'^(.*/)', r'\1*.', context['zone_path']) @@ -65,7 +65,7 @@ class Bind9MasterDomainBackend(ServiceController): return self.append(textwrap.dedent("""\ sed -e '/zone\s\s*"%(name)s".*/,/^\s*};\s*$/d' \\ - -e 'N; /^\\n$/d; P; D' %(conf_path)s > %(conf_path)s.tmp""" % context + -e 'N; /^\s*\\n\s*$/d; P; D' %(conf_path)s > %(conf_path)s.tmp""" % context )) self.append('diff -B -I"^\s*//" %(conf_path)s.tmp %(conf_path)s || UPDATED=1' % context) self.append('mv %(conf_path)s.tmp %(conf_path)s' % context) diff --git a/orchestra/apps/lists/backends.py b/orchestra/apps/lists/backends.py index 65c5f96b..97aa2ccc 100644 --- a/orchestra/apps/lists/backends.py +++ b/orchestra/apps/lists/backends.py @@ -72,7 +72,8 @@ class MailmanBackend(ServiceController): UPDATED_VIRTUAL_ALIAS=1 else if [[ ! $(grep '^\s*%(address_name)s@%(address_domain)s\s\s*%(name)s\s*$' %(virtual_alias)s) ]]; then - sed -i "/^.*\s%(name)s\s*$/d" %(virtual_alias)s + sed -i -e '/^.*\s%(name)s\(%(address_regex)s\)\s*$/d' \\ + -e 'N; /^\s*\\n\s*$/d; P; D' %(virtual_alias)s echo '# %(banner)s\n%(aliases)s ' >> %(virtual_alias)s UPDATED_VIRTUAL_ALIAS=1 @@ -99,10 +100,10 @@ class MailmanBackend(ServiceController): def delete(self, mail_list): context = self.get_context(mail_list) self.exclude_virtual_alias_domain(context) - self.append('sed -i "/^\s*Generated by.*%(name)s\s*$/d" %(virtual_alias)s' % context) - for address in self.addresses: - context['address'] = address - self.append('sed -i "/^.*\s%(name)s%(address)s\s*$/d" %(virtual_alias)s' % context) + self.append(textwrap.dedent("""\ + sed -i -e '/^.*\s%(name)s\(%(address_regex)s\)\s*$/d' \\ + -e 'N; /^\s*\\n\s*$/d; P; D' %(virtual_alias)s""" % context + )) self.append("rmlist -a %(name)s" % context) def commit(self): @@ -126,12 +127,13 @@ class MailmanBackend(ServiceController): def get_context(self, mail_list): context = self.get_context_files() context.update({ - 'banner': self.get_banner(), + 'banner': self.get_banner(mail_list), 'name': mail_list.name, 'password': mail_list.password, 'domain': mail_list.address_domain or settings.LISTS_DEFAULT_DOMAIN, 'address_name': mail_list.get_address_name(), 'address_domain': mail_list.address_domain, + 'address_regex': '\|'.join(self.addresses), 'admin': mail_list.admin_email, 'mailman_root': settings.LISTS_MAILMAN_ROOT_PATH, }) diff --git a/orchestra/apps/orchestration/methods.py b/orchestra/apps/orchestration/methods.py index 55a96f7f..dd1bf784 100644 --- a/orchestra/apps/orchestration/methods.py +++ b/orchestra/apps/orchestration/methods.py @@ -8,6 +8,7 @@ import select import paramiko from celery.datastructures import ExceptionInfo +from django.conf import settings as djsettings from . import settings @@ -61,12 +62,13 @@ def BashSSH(backend, log, server, cmds): # Execute it context = { 'remote_path': remote_path, - 'digest': digest + 'digest': digest, + 'remove': '' if djsettings.DEBUG else "rm -fr %(remote_path)s\n", } cmd = ( "[[ $(md5sum %(remote_path)s|awk {'print $1'}) == %(digest)s ]] && bash %(remote_path)s\n" "RETURN_CODE=$?\n" - "rm -fr %(remote_path)s\n" + "%(remove)s" "exit $RETURN_CODE" % context ) channel = transport.open_session()