VirtualMailManager/handler.py
author Pascal Volk <neverseen@users.sourceforge.net>
Sun, 01 Aug 2010 03:55:01 +0000
branchv0.6.x
changeset 334 3f550826b1cc
parent 333 1ed85e696748
child 335 7a471cace3ba
permissions -rw-r--r--
VMM/account: Reworked methods enable/disable in order to accept multiple services.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
bb0aa2102206 Initial import @sf.net
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: 158
diff changeset
     2
# Copyright (c) 2007 - 2010, Pascal Volk
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     3
# See COPYING for distribution information.
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
     4
"""
320
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
     5
   VirtualMailManager.handler
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
     6
   ~~~~~~~~~~~~~~~~~~~~~~~~~~
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     7
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
     8
   A wrapper class. It wraps round all other classes and does some
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
     9
   dependencies checks.
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    10
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    11
   Additionally it communicates with the PostgreSQL database, creates
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    12
   or deletes directories of domains or users.
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    13
"""
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    14
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    15
import os
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    16
import re
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    17
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    18
from shutil import rmtree
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    19
from subprocess import Popen, PIPE
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    20
241
2493453f2c10 VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 240
diff changeset
    21
from pyPgSQL import PgSQL  # python-pgsql - http://pypgsql.sourceforge.net
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    22
320
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
    23
from VirtualMailManager.account import Account
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
    24
from VirtualMailManager.alias import Alias
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
    25
from VirtualMailManager.aliasdomain import AliasDomain
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
    26
from VirtualMailManager.common import exec_ok, lisdir
320
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
    27
from VirtualMailManager.config import Config as Cfg
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
    28
from VirtualMailManager.constants import MIN_GID, MIN_UID, \
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
    29
     ACCOUNT_EXISTS, ALIAS_EXISTS, CONF_NOFILE, CONF_NOPERM, CONF_WRONGPERM, \
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
    30
     DATABASE_ERROR, DOMAINDIR_GROUP_MISMATCH, DOMAIN_INVALID, \
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
    31
     FOUND_DOTS_IN_PATH, INVALID_ARGUMENT, MAILDIR_PERM_MISMATCH, \
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
    32
     NOT_EXECUTABLE, NO_SUCH_ACCOUNT, NO_SUCH_ALIAS, NO_SUCH_BINARY, \
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
    33
     NO_SUCH_DIRECTORY, NO_SUCH_RELOCATED, RELOCATED_EXISTS
320
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
    34
from VirtualMailManager.domain import Domain, get_gid
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
    35
from VirtualMailManager.emailaddress import EmailAddress
285
d30a94f5aef5 VMM/Handler: import the errors before raising them.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 283
diff changeset
    36
from VirtualMailManager.errors import \
d30a94f5aef5 VMM/Handler: import the errors before raising them.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 283
diff changeset
    37
     DomainError, NotRootError, PermissionError, VMMError
309
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 294
diff changeset
    38
from VirtualMailManager.mailbox import new as new_mailbox
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
    39
from VirtualMailManager.pycompat import all, any
320
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
    40
from VirtualMailManager.relocated import Relocated
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
    41
from VirtualMailManager.transport import Transport
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    42
190
1903d4ce97d7 VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 188
diff changeset
    43
283
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
    44
_ = lambda msg: msg
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
    45
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    46
CFG_FILE = 'vmm.cfg'
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    47
CFG_PATH = '/root:/usr/local/etc:/etc'
241
2493453f2c10 VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 240
diff changeset
    48
RE_DOMAIN_SEARCH = """^[a-z0-9-\.]+$"""
251
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
    49
TYPE_ACCOUNT = 0x1
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
    50
TYPE_ALIAS = 0x2
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
    51
TYPE_RELOCATED = 0x4
283
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
    52
OTHER_TYPES = {
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
    53
    TYPE_ACCOUNT: (_(u'an account'), ACCOUNT_EXISTS),
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
    54
    TYPE_ALIAS: (_(u'an alias'), ALIAS_EXISTS),
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
    55
    TYPE_RELOCATED: (_(u'a relocated user'), RELOCATED_EXISTS),
283
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
    56
}
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    57
190
1903d4ce97d7 VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 188
diff changeset
    58
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    59
class Handler(object):
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    60
    """Wrapper class to simplify the access on all the stuff from
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    61
    VirtualMailManager"""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
    62
    __slots__ = ('_cfg', '_cfg_fname', '_dbh', '_warnings')
191
db77501aeaed VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 190
diff changeset
    63
190
1903d4ce97d7 VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 188
diff changeset
    64
    def __init__(self, skip_some_checks=False):
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    65
        """Creates a new Handler instance.
188
cf1b5f22dbd2 VMM/Handler: __init__ accepts now a config_type ('default'||'cli').
Pascal Volk <neverseen@users.sourceforge.net>
parents: 187
diff changeset
    66
190
1903d4ce97d7 VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 188
diff changeset
    67
        ``skip_some_checks`` : bool
1903d4ce97d7 VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 188
diff changeset
    68
            When a derived class knows how to handle all checks this
1903d4ce97d7 VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 188
diff changeset
    69
            argument may be ``True``. By default it is ``False`` and
1903d4ce97d7 VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 188
diff changeset
    70
            all checks will be performed.
188
cf1b5f22dbd2 VMM/Handler: __init__ accepts now a config_type ('default'||'cli').
Pascal Volk <neverseen@users.sourceforge.net>
parents: 187
diff changeset
    71
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 215
diff changeset
    72
        Throws a NotRootError if your uid is greater 0.
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    73
        """
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    74
        self._cfg_fname = ''
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
    75
        self._warnings = []
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    76
        self._cfg = None
196
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
    77
        self._dbh = None
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    78
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    79
        if os.geteuid():
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 215
diff changeset
    80
            raise NotRootError(_(u"You are not root.\n\tGood bye!\n"),
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
    81
                               CONF_NOPERM)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
    82
        if self._check_cfg_file():
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    83
            self._cfg = Cfg(self._cfg_fname)
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    84
            self._cfg.load()
190
1903d4ce97d7 VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 188
diff changeset
    85
        if not skip_some_checks:
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    86
            self._cfg.check()
190
1903d4ce97d7 VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 188
diff changeset
    87
            self._chkenv()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    88
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
    89
    def _find_cfg_file(self):
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    90
        """Search the CFG_FILE in CFG_PATH.
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    91
        Raise a VMMError when no vmm.cfg could be found.
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    92
        """
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    93
        for path in CFG_PATH.split(':'):
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    94
            tmp = os.path.join(path, CFG_FILE)
119
014335f38962 Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
    95
            if os.path.isfile(tmp):
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    96
                self._cfg_fname = tmp
94
0d303d15549e * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 90
diff changeset
    97
                break
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    98
        if not self._cfg_fname:
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
    99
            raise VMMError(_(u"Could not find '%(cfg_file)s' in: "
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   100
                             u"'%(cfg_path)s'") % {'cfg_file': CFG_FILE,
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   101
                           'cfg_path': CFG_PATH}, CONF_NOFILE)
94
0d303d15549e * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 90
diff changeset
   102
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   103
    def _check_cfg_file(self):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   104
        """Checks the configuration file, returns bool"""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   105
        self._find_cfg_file()
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   106
        fstat = os.stat(self._cfg_fname)
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   107
        fmode = int(oct(fstat.st_mode & 0777))
187
38b9a9859749 VMM/{,cli/Cli}Config: Moved interactive stuff to new CliConfig class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 186
diff changeset
   108
        if fmode % 100 and fstat.st_uid != fstat.st_gid or \
285
d30a94f5aef5 VMM/Handler: import the errors before raising them.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 283
diff changeset
   109
           fmode % 10 and fstat.st_uid == fstat.st_gid:
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 285
diff changeset
   110
            raise PermissionError(_(u"wrong permissions for '%(file)s': "
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 285
diff changeset
   111
                                    u"%(perms)s\n`chmod 0600 %(file)s` would "
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   112
                                    u"be great.") % {'file': self._cfg_fname,
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   113
                                  'perms': fmode}, CONF_WRONGPERM)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   114
        else:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   115
            return True
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   116
190
1903d4ce97d7 VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 188
diff changeset
   117
    def _chkenv(self):
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   118
        """Make sure our base_directory is a directory and that all
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   119
        required executables exists and are executable.
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   120
        If not, a VMMError will be raised"""
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   121
        dir_created = False
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   122
        basedir = self._cfg.dget('misc.base_directory')
168
fd496561acc6 vmm.cfg: a few re-renamed configuration options.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 166
diff changeset
   123
        if not os.path.exists(basedir):
28
87da30d30fde * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 24
diff changeset
   124
            old_umask = os.umask(0006)
168
fd496561acc6 vmm.cfg: a few re-renamed configuration options.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 166
diff changeset
   125
            os.makedirs(basedir, 0771)
270
d3389645a91d configuration: Dropped setting misc.gid_mail.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   126
            os.chown(basedir, 0, 0)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   127
            os.umask(old_umask)
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   128
            dir_created = True
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   129
        if not dir_created and not lisdir(basedir):
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   130
            raise VMMError(_(u"'%(path)s' is not a directory.\n(%(cfg_file)s: "
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   131
                             u"section 'misc', option 'base_directory')") %
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   132
                           {'path': basedir, 'cfg_file': self._cfg_fname},
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   133
                           NO_SUCH_DIRECTORY)
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   134
        for opt, val in self._cfg.items('bin'):
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   135
            try:
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   136
                exec_ok(val)
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 285
diff changeset
   137
            except VMMError, err:
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   138
                if err.code is NO_SUCH_BINARY:
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   139
                    raise VMMError(_(u"'%(binary)s' doesn't exist.\n"
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   140
                                     u"(%(cfg_file)s: section 'bin', option "
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   141
                                     u"'%(option)s')") % {'binary': val,
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   142
                                   'cfg_file': self._cfg_fname, 'option': opt},
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   143
                                   err.code)
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   144
                elif err.code is NOT_EXECUTABLE:
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 285
diff changeset
   145
                    raise VMMError(_(u"'%(binary)s' is not executable.\n"
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   146
                                     u"(%(cfg_file)s: section 'bin', option "
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 285
diff changeset
   147
                                     u"'%(option)s')") % {'binary': val,
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   148
                                   'cfg_file': self._cfg_fname, 'option': opt},
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   149
                                   err.code)
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   150
                else:
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   151
                    raise
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   152
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   153
    def _db_connect(self):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   154
        """Creates a pyPgSQL.PgSQL.connection instance."""
196
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   155
        if self._dbh is None or (isinstance(self._dbh, PgSQL.Connection) and
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   156
                                  not self._dbh._isOpen):
83
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   157
            try:
196
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   158
                self._dbh = PgSQL.connect(
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   159
                        database=self._cfg.dget('database.name'),
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   160
                        user=self._cfg.pget('database.user'),
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   161
                        host=self._cfg.dget('database.host'),
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   162
                        password=self._cfg.pget('database.pass'),
83
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   163
                        client_encoding='utf8', unicode_results=True)
196
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   164
                dbc = self._dbh.cursor()
83
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   165
                dbc.execute("SET NAMES 'UTF8'")
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   166
                dbc.close()
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   167
            except PgSQL.libpq.DatabaseError, err:
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   168
                raise VMMError(str(err), DATABASE_ERROR)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   169
251
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   170
    def _chk_other_address_types(self, address, exclude):
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   171
        """Checks if the EmailAddress *address* is known as `TYPE_ACCOUNT`,
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   172
        `TYPE_ALIAS` or `TYPE_RELOCATED`, but not as the `TYPE_*` specified
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   173
        by *exclude*.  If the *address* is known as one of the `TYPE_*`s
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   174
        the according `TYPE_*` constant will be returned.  Otherwise 0 will
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   175
        be returned."""
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   176
        assert exclude in (TYPE_ACCOUNT, TYPE_ALIAS, TYPE_RELOCATED) and \
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   177
                isinstance(address, EmailAddress)
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   178
        if exclude is not TYPE_ACCOUNT:
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   179
            account = Account(self._dbh, address)
283
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   180
            if account:
251
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   181
                return TYPE_ACCOUNT
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   182
        if exclude is not TYPE_ALIAS:
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   183
            alias = Alias(self._dbh, address)
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   184
            if alias:
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   185
                return TYPE_ALIAS
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   186
        if exclude is not TYPE_RELOCATED:
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   187
            relocated = Relocated(self._dbh, address)
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   188
            if relocated:
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   189
                return TYPE_RELOCATED
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   190
        return 0
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   191
283
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   192
    def _is_other_address(self, address, exclude):
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   193
        """Checks if *address* is known for an Account (TYPE_ACCOUNT),
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   194
        Alias (TYPE_ALIAS) or Relocated (TYPE_RELOCATED), except for
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   195
        *exclude*.  Returns `False` if the address is not known for other
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   196
        types.
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   197
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   198
        Raises a `VMMError` if the address is known.
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   199
        """
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   200
        other = self._chk_other_address_types(address, exclude)
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   201
        if not other:
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   202
            return False
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   203
        msg = _(u"There is already %(a_type)s with the address '%(address)s'.")
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   204
        raise VMMError(msg % {'a_type': OTHER_TYPES[other][0],
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   205
                              'address': address}, OTHER_TYPES[other][1])
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   206
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   207
    def _get_account(self, address):
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   208
        """Return an Account instances for the given address (str)."""
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   209
        address = EmailAddress(address)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   210
        self._db_connect()
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   211
        return Account(self._dbh, address)
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   212
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   213
    def _get_alias(self, address):
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   214
        """Return an Alias instances for the given address (str)."""
197
d2712e8c724e VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 196
diff changeset
   215
        address = EmailAddress(address)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   216
        self._db_connect()
196
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   217
        return Alias(self._dbh, address)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   218
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   219
    def _get_relocated(self, address):
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   220
        """Return a Relocated instances for the given address (str)."""
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   221
        address = EmailAddress(address)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   222
        self._db_connect()
197
d2712e8c724e VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 196
diff changeset
   223
        return Relocated(self._dbh, address)
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   224
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   225
    def _get_domain(self, domainname):
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   226
        """Return a Domain instances for the given domain name (str)."""
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   227
        self._db_connect()
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   228
        return Domain(self._dbh, domainname)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   229
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   230
    def _get_disk_usage(self, directory):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   231
        """Estimate file space usage for the given directory.
128
cf8116625866 Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 119
diff changeset
   232
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   233
        Arguments:
40
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   234
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   235
        `directory` : basestring
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   236
          The directory to summarize recursively disk usage for
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   237
        """
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   238
        if lisdir(directory):
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   239
            return Popen([self._cfg.dget('bin.du'), "-hs", directory],
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   240
                         stdout=PIPE).communicate()[0].split('\t')[0]
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   241
        else:
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   242
            self._warnings.append(_('No such directory: %s') % directory)
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   243
            return 0
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   244
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   245
    def _make_domain_dir(self, domain):
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   246
        """Create a directory for the `domain` and its accounts."""
310
644e2cc4a441 VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 309
diff changeset
   247
        cwd = os.getcwd()
644e2cc4a441 VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 309
diff changeset
   248
        hashdir, domdir = domain.directory.split(os.path.sep)[-2:]
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   249
        dir_created = False
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   250
        os.chdir(self._cfg.dget('misc.base_directory'))
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   251
        if not os.path.exists(hashdir):
310
644e2cc4a441 VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 309
diff changeset
   252
            os.mkdir(hashdir, 0711)
644e2cc4a441 VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 309
diff changeset
   253
            os.chown(hashdir, 0, 0)
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   254
            dir_created = True
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   255
        if not dir_created and not lisdir(hashdir):
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   256
            raise VMMError(_(u"'%s' is not a directory.") % hashdir,
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   257
                           NO_SUCH_DIRECTORY)
310
644e2cc4a441 VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 309
diff changeset
   258
        os.mkdir(os.path.join(hashdir, domdir),
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   259
                 self._cfg.dget('domain.directory_mode'))
310
644e2cc4a441 VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 309
diff changeset
   260
        os.chown(domain.directory, 0, domain.gid)
644e2cc4a441 VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 309
diff changeset
   261
        os.chdir(cwd)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   262
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   263
    def _make_home(self, account):
309
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 294
diff changeset
   264
        """Create a home directory for the new Account *account*."""
329
41789df75339 VMM/account: Replaced property domain_directory by domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 327
diff changeset
   265
        domdir = account.domain.directory
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   266
        if not lisdir(domdir):
330
3fe8d6cdbe3a VMM/handler: _make_home() Create the domain directory if it
Pascal Volk <neverseen@users.sourceforge.net>
parents: 329
diff changeset
   267
            self._make_domain_dir(account.domain)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   268
        os.umask(0007)
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   269
        uid = account.uid
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   270
        os.chdir(domdir)
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   271
        os.mkdir('%s' % uid, self._cfg.dget('account.directory_mode'))
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   272
        os.chown('%s' % uid, uid, account.gid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   273
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   274
    def _delete_home(self, domdir, uid, gid):
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   275
        """Delete a user's home directory.
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   276
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   277
        Arguments:
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   278
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   279
        `domdir` : basestring
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   280
          The directory of the domain the user belongs to
329
41789df75339 VMM/account: Replaced property domain_directory by domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 327
diff changeset
   281
          (commonly AccountObj.domain.directory)
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   282
        `uid` : int/long
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   283
          The user's UID (commonly AccountObj.uid)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   284
        `gid` : int/long
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   285
          The user's GID (commonly AccountObj.gid)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   286
        """
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   287
        assert all(isinstance(xid, (long, int)) for xid in (uid, gid)) and \
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   288
                isinstance(domdir, basestring)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   289
        if uid < MIN_UID or gid < MIN_GID:
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   290
            raise VMMError(_(u"UID '%(uid)u' and/or GID '%(gid)u' are less "
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   291
                             u"than %(min_uid)u/%(min_gid)u.") % {'uid': uid,
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   292
                           'gid': gid, 'min_gid': MIN_GID, 'min_uid': MIN_UID},
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   293
                           MAILDIR_PERM_MISMATCH)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   294
        if domdir.count('..'):
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   295
            raise VMMError(_(u'Found ".." in domain directory path: %s') %
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   296
                           domdir, FOUND_DOTS_IN_PATH)
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   297
        if not lisdir(domdir):
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   298
            raise VMMError(_(u"No such directory: %s") % domdir,
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   299
                           NO_SUCH_DIRECTORY)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   300
        os.chdir(domdir)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   301
        userdir = '%s' % uid
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   302
        if not lisdir(userdir):
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   303
            self._warnings.append(_(u"No such directory: %s") %
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   304
                                  os.path.join(domdir, userdir))
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   305
            return
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   306
        mdstat = os.lstat(userdir)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   307
        if (mdstat.st_uid, mdstat.st_gid) != (uid, gid):
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   308
            raise VMMError(_(u'Detected owner/group mismatch in home '
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   309
                             u'directory.'), MAILDIR_PERM_MISMATCH)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   310
        rmtree(userdir, ignore_errors=True)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   311
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   312
    def _delete_domain_dir(self, domdir, gid):
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   313
        """Delete a domain's directory.
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   314
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   315
        Arguments:
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   316
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   317
        `domdir` : basestring
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   318
          The domain's directory (commonly DomainObj.directory)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   319
        `gid` : int/long
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   320
          The domain's GID (commonly DomainObj.gid)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   321
        """
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   322
        assert isinstance(domdir, basestring) and isinstance(gid, (long, int))
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   323
        if gid < MIN_GID:
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   324
            raise VMMError(_(u"GID '%(gid)u' is less than '%(min_gid)u'.") %
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   325
                           {'gid': gid, 'min_gid': MIN_GID},
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   326
                           DOMAINDIR_GROUP_MISMATCH)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   327
        if domdir.count('..'):
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   328
            raise VMMError(_(u'Found ".." in domain directory path: %s') %
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   329
                           domdir, FOUND_DOTS_IN_PATH)
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   330
        if not lisdir(domdir):
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   331
            self._warnings.append(_('No such directory: %s') % domdir)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   332
            return
327
bb9ff81928f1 VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 325
diff changeset
   333
        dirst = os.lstat(domdir)
325
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   334
        if dirst.st_gid != gid:
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   335
            raise VMMError(_(u'Detected group mismatch in domain directory: '
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   336
                             u'%s') % domdir, DOMAINDIR_GROUP_MISMATCH)
06c0457036a0 VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   337
        rmtree(domdir, ignore_errors=True)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   338
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   339
    def has_warnings(self):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   340
        """Checks if warnings are present, returns bool."""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   341
        return bool(len(self._warnings))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   342
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   343
    def get_warnings(self):
221
371ae0b4443d VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   344
        """Returns a list with all available warnings and resets all
371ae0b4443d VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   345
        warnings.
371ae0b4443d VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   346
        """
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   347
        ret_val = self._warnings[:]
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   348
        del self._warnings[:]
221
371ae0b4443d VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   349
        return ret_val
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   350
255
d2ddd4a6528d VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 254
diff changeset
   351
    def cfg_dget(self, option):
d2ddd4a6528d VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 254
diff changeset
   352
        """Get the configured value of the *option* (section.option).
d2ddd4a6528d VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 254
diff changeset
   353
        When the option was not configured its default value will be
d2ddd4a6528d VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 254
diff changeset
   354
        returned."""
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   355
        return self._cfg.dget(option)
40
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   356
255
d2ddd4a6528d VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 254
diff changeset
   357
    def cfg_pget(self, option):
d2ddd4a6528d VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 254
diff changeset
   358
        """Get the configured value of the *option* (section.option)."""
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   359
        return self._cfg.pget(option)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   360
280
db35d2eec518 VMM/{Config,Handler}: moved Config.install() to Handler.cfg_install().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 278
diff changeset
   361
    def cfg_install(self):
db35d2eec518 VMM/{Config,Handler}: moved Config.install() to Handler.cfg_install().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 278
diff changeset
   362
        """Installs the cfg_dget method as ``cfg_dget`` into the built-in
db35d2eec518 VMM/{Config,Handler}: moved Config.install() to Handler.cfg_install().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 278
diff changeset
   363
        namespace."""
db35d2eec518 VMM/{Config,Handler}: moved Config.install() to Handler.cfg_install().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 278
diff changeset
   364
        import __builtin__
db35d2eec518 VMM/{Config,Handler}: moved Config.install() to Handler.cfg_install().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 278
diff changeset
   365
        assert 'cfg_dget' not in __builtin__.__dict__
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   366
        __builtin__.__dict__['cfg_dget'] = self._cfg.dget
280
db35d2eec518 VMM/{Config,Handler}: moved Config.install() to Handler.cfg_install().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 278
diff changeset
   367
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   368
    def domain_add(self, domainname, transport=None):
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   369
        """Wrapper around Domain.set_transport() and Domain.save()"""
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   370
        dom = self._get_domain(domainname)
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   371
        if transport is None:
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   372
            dom.set_transport(Transport(self._dbh,
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   373
                              transport=self._cfg.dget('misc.transport')))
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   374
        else:
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   375
            dom.set_transport(Transport(self._dbh, transport=transport))
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   376
        dom.set_directory(self._cfg.dget('misc.base_directory'))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   377
        dom.save()
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   378
        self._make_domain_dir(dom)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   379
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   380
    def domain_transport(self, domainname, transport, force=None):
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   381
        """Wrapper around Domain.update_transport()"""
18
c98e08791ee8 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   382
        if force is not None and force != 'force':
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   383
            raise DomainError(_(u"Invalid argument: '%s'") % force,
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   384
                              INVALID_ARGUMENT)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   385
        dom = self._get_domain(domainname)
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   386
        trsp = Transport(self._dbh, transport=transport)
18
c98e08791ee8 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   387
        if force is None:
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   388
            dom.update_transport(trsp)
18
c98e08791ee8 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   389
        else:
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   390
            dom.update_transport(trsp, force=True)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   391
331
270b57af85de VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 330
diff changeset
   392
    def domain_delete(self, domainname, force=False):
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   393
        """Wrapper around Domain.delete()"""
331
270b57af85de VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 330
diff changeset
   394
        if not isinstance(force, bool):
270b57af85de VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 330
diff changeset
   395
            raise TypeError('force must be a bool')
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   396
        dom = self._get_domain(domainname)
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   397
        gid = dom.gid
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   398
        domdir = dom.directory
331
270b57af85de VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 330
diff changeset
   399
        if self._cfg.dget('domain.force_deletion') or force:
270b57af85de VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 330
diff changeset
   400
            dom.delete(True)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   401
        else:
331
270b57af85de VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 330
diff changeset
   402
            dom.delete(False)
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   403
        if self._cfg.dget('domain.delete_directory'):
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   404
            self._delete_domain_dir(domdir, gid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   405
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   406
    def domain_info(self, domainname, details=None):
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   407
        """Wrapper around Domain.get_info(), Domain.get_accounts(),
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   408
        Domain.get_aliase_names(), Domain.get_aliases() and
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   409
        Domain.get_relocated."""
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   410
        if details not in [None, 'accounts', 'aliasdomains', 'aliases', 'full',
191
db77501aeaed VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 190
diff changeset
   411
                           'relocated']:
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 215
diff changeset
   412
            raise VMMError(_(u'Invalid argument: “%s”') % details,
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   413
                           INVALID_ARGUMENT)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   414
        dom = self._get_domain(domainname)
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   415
        dominfo = dom.get_info()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   416
        if dominfo['domainname'].startswith('xn--'):
294
7d1bafc6fa30 VMM/Domain: removed functions ace2idna() and idn2ascii().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 293
diff changeset
   417
            dominfo['domainname'] += ' (%s)' % \
7d1bafc6fa30 VMM/Domain: removed functions ace2idna() and idn2ascii().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 293
diff changeset
   418
                                     dominfo['domainname'].decode('idna')
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   419
        if details is None:
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   420
            return dominfo
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   421
        elif details == 'accounts':
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   422
            return (dominfo, dom.get_accounts())
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   423
        elif details == 'aliasdomains':
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   424
            return (dominfo, dom.get_aliase_names())
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   425
        elif details == 'aliases':
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   426
            return (dominfo, dom.get_aliases())
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   427
        elif details == 'relocated':
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   428
            return(dominfo, dom.get_relocated())
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   429
        else:
236
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   430
            return (dominfo, dom.get_aliase_names(), dom.get_accounts(),
084331dd1e4c VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 233
diff changeset
   431
                    dom.get_aliases(), dom.get_relocated())
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   432
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   433
    def aliasdomain_add(self, aliasname, domainname):
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   434
        """Adds an alias domain to the domain.
53
5b50eb306d37 * 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 52
diff changeset
   435
244
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   436
        Arguments:
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   437
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   438
        `aliasname` : basestring
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   439
          The name of the alias domain
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   440
        `domainname` : basestring
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   441
          The name of the target domain
45
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   442
        """
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   443
        dom = self._get_domain(domainname)
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   444
        alias_dom = AliasDomain(self._dbh, aliasname)
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   445
        alias_dom.set_destination(dom)
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   446
        alias_dom.save()
53
5b50eb306d37 * 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 52
diff changeset
   447
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   448
    def aliasdomain_info(self, aliasname):
244
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   449
        """Returns a dict (keys: "alias" and "domain") with the names of
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   450
        the alias domain and its primary domain."""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   451
        self._db_connect()
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   452
        alias_dom = AliasDomain(self._dbh, aliasname)
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   453
        return alias_dom.info()
45
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   454
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   455
    def aliasdomain_switch(self, aliasname, domainname):
78
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   456
        """Modifies the target domain of an existing alias domain.
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   457
244
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   458
        Arguments:
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   459
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   460
        `aliasname` : basestring
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   461
          The name of the alias domain
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   462
        `domainname` : basestring
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   463
          The name of the new target domain
78
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   464
        """
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   465
        dom = self._get_domain(domainname)
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   466
        alias_dom = AliasDomain(self._dbh, aliasname)
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   467
        alias_dom.set_destination(dom)
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   468
        alias_dom.switch()
78
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   469
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   470
    def aliasdomain_delete(self, aliasname):
244
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   471
        """Deletes the given alias domain.
53
5b50eb306d37 * 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 52
diff changeset
   472
244
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   473
        Argument:
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   474
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   475
        `aliasname` : basestring
698ba4208ddc VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 241
diff changeset
   476
          The name of the alias domain
45
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   477
        """
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   478
        self._db_connect()
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   479
        alias_dom = AliasDomain(self._dbh, aliasname)
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   480
        alias_dom.delete()
45
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   481
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   482
    def domain_list(self, pattern=None):
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   483
        """Wrapper around function search() from module Domain."""
320
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
   484
        from VirtualMailManager.domain import search
35
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   485
        like = False
241
2493453f2c10 VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 240
diff changeset
   486
        if pattern and (pattern.startswith('%') or pattern.endswith('%')):
2493453f2c10 VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 240
diff changeset
   487
            like = True
2493453f2c10 VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 240
diff changeset
   488
            if not re.match(RE_DOMAIN_SEARCH, pattern.strip('%')):
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 285
diff changeset
   489
                raise VMMError(_(u"The pattern '%s' contains invalid "
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   490
                                 u"characters.") % pattern, DOMAIN_INVALID)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   491
        self._db_connect()
196
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   492
        return search(self._dbh, pattern=pattern, like=like)
35
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   493
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   494
    def user_add(self, emailaddress, password):
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   495
        """Wrapper around Account.set_password() and Account.save()."""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   496
        acc = self._get_account(emailaddress)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   497
        acc.set_password(password)
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   498
        acc.save()
309
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 294
diff changeset
   499
        oldpwd = os.getcwd()
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   500
        self._make_home(acc)
309
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 294
diff changeset
   501
        mailbox = new_mailbox(acc)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 294
diff changeset
   502
        mailbox.create()
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   503
        folders = self._cfg.dget('mailbox.folders').split(':')
309
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 294
diff changeset
   504
        if any(folders):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 294
diff changeset
   505
            bad = mailbox.add_boxes(folders,
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   506
                                    self._cfg.dget('mailbox.subscribe'))
309
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 294
diff changeset
   507
            if bad:
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   508
                self._warnings.append(_(u"Skipped mailbox folders:") +
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   509
                                      '\n\t- ' + '\n\t- '.join(bad))
309
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 294
diff changeset
   510
        os.chdir(oldpwd)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   511
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   512
    def alias_add(self, aliasaddress, *targetaddresses):
196
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   513
        """Creates a new `Alias` entry for the given *aliasaddress* with
221
371ae0b4443d VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   514
        the given *targetaddresses*."""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   515
        alias = self._get_alias(aliasaddress)
221
371ae0b4443d VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   516
        destinations = [EmailAddress(address) for address in targetaddresses]
371ae0b4443d VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   517
        warnings = []
281
59ff7c719697 VMM/Alias: moved the postconf stuff from the Handlers to Alias class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 280
diff changeset
   518
        destinations = alias.add_destinations(destinations, warnings)
221
371ae0b4443d VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   519
        if warnings:
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   520
            self._warnings.append(_('Ignored destination addresses:'))
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   521
            self._warnings.extend(('  * %s' % w for w in warnings))
221
371ae0b4443d VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   522
        for destination in destinations:
282
28871c1be260 VMM/Handler: fixed destination check in Handler.aliasAdd().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 281
diff changeset
   523
            if get_gid(self._dbh, destination.domainname) and \
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 285
diff changeset
   524
               not self._chk_other_address_types(destination, TYPE_RELOCATED):
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   525
                self._warnings.append(_(u"The destination account/alias '%s' "
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   526
                                        u"doesn't exist.") % destination)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   527
333
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 331
diff changeset
   528
    def user_delete(self, emailaddress, force=False):
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   529
        """Wrapper around Account.delete(...)"""
333
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 331
diff changeset
   530
        if not isinstance(force, bool):
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 331
diff changeset
   531
            raise TypeError('force must be a bool')
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   532
        acc = self._get_account(emailaddress)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   533
        if not acc:
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   534
            raise VMMError(_(u"The account '%s' doesn't exist.") %
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   535
                           acc.address, NO_SUCH_ACCOUNT)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   536
        uid = acc.uid
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   537
        gid = acc.gid
329
41789df75339 VMM/account: Replaced property domain_directory by domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 327
diff changeset
   538
        dom_dir = acc.domain.directory
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   539
        acc_dir = acc.home
333
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 331
diff changeset
   540
        acc.delete(force)
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   541
        if self._cfg.dget('account.delete_directory'):
47
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   542
            try:
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   543
                self._delete_home(dom_dir, uid, gid)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   544
            except VMMError, err:
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   545
                if err.code in (FOUND_DOTS_IN_PATH, MAILDIR_PERM_MISMATCH,
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   546
                                NO_SUCH_DIRECTORY):
47
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   547
                    warning = _(u"""\
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   548
The account has been successfully deleted from the database.
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   549
    But an error occurred while deleting the following directory:
333
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 331
diff changeset
   550
    '%(directory)s'
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 331
diff changeset
   551
    Reason: %(reason)s""") % {'directory': acc_dir, 'reason': err.msg}
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   552
                    self._warnings.append(warning)
47
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   553
                else:
191
db77501aeaed VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 190
diff changeset
   554
                    raise
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   555
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   556
    def alias_info(self, aliasaddress):
196
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   557
        """Returns an iterator object for all destinations (`EmailAddress`
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   558
        instances) for the `Alias` with the given *aliasaddress*."""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   559
        alias = self._get_alias(aliasaddress)
283
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   560
        if alias:
215
33f727efa7c4 PEP-8-ified the work of the last days.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 208
diff changeset
   561
            return alias.get_destinations()
283
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   562
        if not self._is_other_address(alias.address, TYPE_ALIAS):
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   563
            raise VMMError(_(u"The alias '%s' doesn't exist.") %
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   564
                           alias.address, NO_SUCH_ALIAS)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   565
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   566
    def alias_delete(self, aliasaddress, targetaddress=None):
196
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   567
        """Deletes the `Alias` *aliasaddress* with all its destinations from
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   568
        the database. If *targetaddress* is not ``None``, only this
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   569
        destination will be removed from the alias."""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   570
        alias = self._get_alias(aliasaddress)
196
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   571
        if targetaddress is None:
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   572
            alias.delete()
65a3163bd113 VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 192
diff changeset
   573
        else:
215
33f727efa7c4 PEP-8-ified the work of the last days.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 208
diff changeset
   574
            alias.del_destination(EmailAddress(targetaddress))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   575
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   576
    def user_info(self, emailaddress, details=None):
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   577
        """Wrapper around Account.get_info(...)"""
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   578
        if details not in (None, 'du', 'aliases', 'full'):
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   579
            raise VMMError(_(u"Invalid argument: '%s'") % details,
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   580
                           INVALID_ARGUMENT)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   581
        acc = self._get_account(emailaddress)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   582
        if not acc:
283
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   583
            if not self._is_other_address(acc.address, TYPE_ACCOUNT):
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   584
                raise VMMError(_(u"The account '%s' doesn't exist.") %
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   585
                               acc.address, NO_SUCH_ACCOUNT)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   586
        info = acc.get_info()
318
4dc2edf02d11 VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
   587
        if self._cfg.dget('account.disk_usage') or details in ('du', 'full'):
293
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   588
            path = os.path.join(acc.home, acc.mail_location.directory)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   589
            info['disk usage'] = self._get_disk_usage(path)
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   590
            if details in (None, 'du'):
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 88
diff changeset
   591
                return info
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   592
        if details in ('aliases', 'full'):
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   593
            return (info, acc.get_aliases())
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   594
        return info
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   595
255
d2ddd4a6528d VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 254
diff changeset
   596
    def user_by_uid(self, uid):
d2ddd4a6528d VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 254
diff changeset
   597
        """Search for an Account by its *uid*.
d2ddd4a6528d VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 254
diff changeset
   598
        Returns a dict (address, uid and gid) if a user could be found."""
320
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 319
diff changeset
   599
        from VirtualMailManager.account import get_account_by_uid
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   600
        self._db_connect()
255
d2ddd4a6528d VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 254
diff changeset
   601
        return get_account_by_uid(uid, self._dbh)
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 18
diff changeset
   602
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   603
    def user_password(self, emailaddress, password):
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   604
        """Wrapper for Account.modify('password' ...)."""
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   605
        if not isinstance(password, basestring) or not password:
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   606
            raise VMMError(_(u"Could not accept password: '%s'") % password,
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   607
                           INVALID_ARGUMENT)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   608
        acc = self._get_account(emailaddress)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   609
        if not acc:
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   610
            raise VMMError(_(u"The account '%s' doesn't exist.") %
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   611
                           acc.address, NO_SUCH_ACCOUNT)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   612
        acc.modify('password', password)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   613
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   614
    def user_name(self, emailaddress, name):
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   615
        """Wrapper for Account.modify('name', ...)."""
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   616
        if not isinstance(name, basestring) or not name:
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   617
            raise VMMError(_(u"Could not accept name: '%s'") % name,
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   618
                           INVALID_ARGUMENT)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   619
        acc = self._get_account(emailaddress)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   620
        if not acc:
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   621
            raise VMMError(_(u"The account '%s' doesn't exist.") %
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   622
                           acc.address, NO_SUCH_ACCOUNT)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   623
        acc.modify('name', name)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   624
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   625
    def user_transport(self, emailaddress, transport):
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   626
        """Wrapper for Account.modify('transport', ...)."""
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   627
        if not isinstance(transport, basestring) or not transport:
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   628
            raise VMMError(_(u"Could not accept transport: '%s'") % transport,
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   629
                           INVALID_ARGUMENT)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   630
        acc = self._get_account(emailaddress)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   631
        if not acc:
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   632
            raise VMMError(_(u"The account '%s' doesn't exist.") %
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   633
                           acc.address, NO_SUCH_ACCOUNT)
17
fe9be0081e5f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 16
diff changeset
   634
        acc.modify('transport', transport)
fe9be0081e5f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 16
diff changeset
   635
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   636
    def user_disable(self, emailaddress, service=None):
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   637
        """Wrapper for Account.disable(service)"""
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   638
        if service not in (None, 'all', 'imap', 'pop3', 'smtp', 'sieve'):
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   639
            raise VMMError(_(u"Could not accept service: '%s'") % service,
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   640
                           INVALID_ARGUMENT)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   641
        acc = self._get_account(emailaddress)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   642
        if not acc:
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   643
            raise VMMError(_(u"The account '%s' doesn't exist.") %
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   644
                           acc.address, NO_SUCH_ACCOUNT)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   645
        acc.disable(service)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   646
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   647
    def user_enable(self, emailaddress, service=None):
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   648
        """Wrapper for Account.enable(service)"""
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   649
        if service not in (None, 'all', 'imap', 'pop3', 'smtp', 'sieve'):
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 285
diff changeset
   650
            raise VMMError(_(u"Could not accept service: '%s'") % service,
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   651
                           INVALID_ARGUMENT)
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   652
        acc = self._get_account(emailaddress)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   653
        if not acc:
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   654
            raise VMMError(_(u"The account '%s' doesn't exist.") %
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   655
                           acc.address, NO_SUCH_ACCOUNT)
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   656
        acc.enable(service)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   657
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   658
    def relocated_add(self, emailaddress, targetaddress):
197
d2712e8c724e VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 196
diff changeset
   659
        """Creates a new `Relocated` entry in the database. If there is
d2712e8c724e VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 196
diff changeset
   660
        already a relocated user with the given *emailaddress*, only the
d2712e8c724e VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 196
diff changeset
   661
        *targetaddress* for the relocated user will be updated."""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   662
        relocated = self._get_relocated(emailaddress)
215
33f727efa7c4 PEP-8-ified the work of the last days.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 208
diff changeset
   663
        relocated.set_destination(EmailAddress(targetaddress))
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   664
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   665
    def relocated_info(self, emailaddress):
197
d2712e8c724e VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 196
diff changeset
   666
        """Returns the target address of the relocated user with the given
d2712e8c724e VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 196
diff changeset
   667
        *emailaddress*."""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   668
        relocated = self._get_relocated(emailaddress)
283
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   669
        if relocated:
251
0963ad2f5fe2 VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 244
diff changeset
   670
            return relocated.get_info()
283
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   671
        if not self._is_other_address(relocated.address, TYPE_RELOCATED):
ea6d052de24a VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 282
diff changeset
   672
            raise VMMError(_(u"The relocated user '%s' doesn't exist.") %
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 310
diff changeset
   673
                           relocated.address, NO_SUCH_RELOCATED)
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   674
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   675
    def relocated_delete(self, emailaddress):
197
d2712e8c724e VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 196
diff changeset
   676
        """Deletes the relocated user with the given *emailaddress* from
d2712e8c724e VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 196
diff changeset
   677
        the database."""
319
f4956b4ceba1 VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 318
diff changeset
   678
        relocated = self._get_relocated(emailaddress)
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   679
        relocated.delete()
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   680
277
e50ffc0b8468 VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 272
diff changeset
   681
del _