VirtualMailManager/ext/postconf.py
author Pascal Volk <neverseen@users.sourceforge.net>
Mon, 09 Aug 2010 08:25:11 +0000
branchv0.6.x
changeset 358 6fabb9cd212d
parent 320 011066435e6f
child 366 d6573da35b5f
permissions -rw-r--r--
update_config: Set pyPgSQL, maybe there is no psycopg2 installed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     1
# -*- coding: UTF-8 -*-
162
0ac9ef587769 Updated copyright notices to include the year 2010.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 155
diff changeset
     2
# Copyright (c) 2008 - 2010, Pascal Volk
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     3
# See COPYING for distribution information.
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
     4
"""
320
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
     5
    VirtualMailManager.ext.postconf
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
     6
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     7
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
     8
    Wrapper class for Postfix's postconf.
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
     9
    Postconf instances can be used to read actual values of configuration
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    10
    parameters or edit the value of a configuration parameter.
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    11
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    12
    postconf.read(parameter) -> value
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    13
    postconf.edit(parameter, value)
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    14
"""
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    15
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 162
diff changeset
    16
import re
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    17
from subprocess import Popen, PIPE
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    18
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    19
from VirtualMailManager.errors import VMMError
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 311
diff changeset
    20
from VirtualMailManager.constants import VMM_ERROR
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    21
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    22
_ = lambda msg: msg
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    23
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    24
128
cf8116625866 Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    25
class Postconf(object):
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    26
    """Wrapper class for Postfix's postconf."""
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    27
    __slots__ = ('_bin', '_val')
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    28
    _parameter_re = re.compile(r'^\w+$')
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    29
    _variables_re = re.compile(r'\$\b\w+\b')
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    30
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    31
    def __init__(self, postconf_bin):
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    32
        """Creates a new Postconf instance.
128
cf8116625866 Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    33
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    34
        Argument:
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    35
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    36
        `postconf_bin` : str
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    37
          absolute path to the Postfix postconf binary.
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    38
        """
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    39
        self._bin = postconf_bin
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    40
        self._val = ''
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    41
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    42
    def edit(self, parameter, value):
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    43
        """Set the `parameter`'s value to `value`.
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    44
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    45
        Arguments:
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    46
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    47
        `parameter` : str
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    48
          the name of a Postfix configuration parameter
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    49
        `value` : str
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    50
          the parameter's new value.
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    51
        """
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    52
        self._check_parameter(parameter)
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    53
        stdout, stderr = Popen((self._bin, '-e', parameter + '=' + str(value)),
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    54
                               stderr=PIPE).communicate()
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    55
        if stderr:
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    56
            raise VMMError(stderr.strip(), VMM_ERROR)
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    57
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    58
    def read(self, parameter, expand_vars=True):
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    59
        """Returns the parameters value.
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    60
128
cf8116625866 Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    61
        If expand_vars is True (default), all variables in the value will be
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    62
        expanded:
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    63
        e.g. mydestination: mail.example.com, localhost.example.com, localhost
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    64
        Otherwise the value may contain one or more variables.
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    65
        e.g. mydestination: $myhostname, localhost.$mydomain, localhost
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    66
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    67
        Arguments:
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    68
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    69
        `parameter` : str
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    70
          the name of a Postfix configuration parameter.
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    71
        `expand_vars` : bool
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    72
          indicates if variables should be expanded or not, default True
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    73
        """
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    74
        self._check_parameter(parameter)
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    75
        self._val = self._read(parameter)
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    76
        if expand_vars:
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    77
            self._expand_vars()
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    78
        return self._val
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    79
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    80
    def _check_parameter(self, parameter):
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    81
        """Check that the `parameter` looks like a configuration parameter.
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    82
        If not, a VMMError will be raised."""
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    83
        if not self.__class__._parameter_re.match(parameter):
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 223
diff changeset
    84
            raise VMMError(_(u"The value '%s' doesn't look like a valid "
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 223
diff changeset
    85
                             u"postfix configuration parameter name.") %
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    86
                           parameter, VMM_ERROR)
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    87
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    88
    def _expand_vars(self):
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    89
        """Expand the $variables in self._val to their values."""
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    90
        while True:
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    91
            pvars = set(self.__class__._variables_re.findall(self._val))
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    92
            if not pvars:
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    93
                break
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    94
            if len(pvars) > 1:
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    95
                self._expand_multi_vars(self._read_multi(pvars))
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    96
                continue
89
752d3b57ebb6 small fixes/updates
Pascal Volk <neverseen@users.sourceforge.net>
parents: 87
diff changeset
    97
            pvars = pvars.pop()
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    98
            self._val = self._val.replace(pvars, self._read(pvars[1:]))
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    99
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   100
    def _expand_multi_vars(self, old_new):
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   101
        """Replace all $vars in self._val with their values."""
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   102
        for old, new in old_new.iteritems():
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   103
            self._val = self._val.replace('$' + old, new)
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   104
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   105
    def _read(self, parameter):
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   106
        """Ask postconf for the value of a single configuration parameter."""
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   107
        stdout, stderr = Popen([self._bin, '-h', parameter], stdout=PIPE,
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   108
                               stderr=PIPE).communicate()
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   109
        if stderr:
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   110
            raise VMMError(stderr.strip(), VMM_ERROR)
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   111
        return stdout.strip()
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   112
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   113
    def _read_multi(self, parameters):
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   114
        """Ask postconf for multiple configuration parameters. Returns a dict
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   115
        parameter: value items."""
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   116
        cmd = [self._bin]
223
5c7b7cbb01cd replaced some "for x in list …"
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   117
        cmd.extend(parameter[1:] for parameter in parameters)
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   118
        stdout, stderr = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   119
        if stderr:
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   120
            raise VMMError(stderr.strip(), VMM_ERROR)
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   121
        par_val = {}
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   122
        for line in stdout.splitlines():
86
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   123
            par, val = line.split(' = ')
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   124
            par_val[par] = val
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   125
        return par_val
e43e4e7e9ec0 * 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   126
311
a0a10100aee5 VMM/ext/Postconf: Reworked class Postconf. Added method edit().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   127
del _