VirtualMailManager/cli/subcommands.py
author Pascal Volk <neverseen@users.sourceforge.net>
Mon, 09 Aug 2010 08:06:38 +0000
branchv0.6.x
changeset 357 095b43faaba5
parent 345 f8d5c8bb8bce
child 361 971577b89d26
permissions -rw-r--r--
man5/vmm.cfg: Added description for new settings in section database.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     1
# -*- coding: UTF-8 -*-
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     2
# Copyright 2007 - 2010, Pascal Volk
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     3
# See COPYING for distribution information.
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     4
"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     5
    VirtualMailManager.cli.subcommands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     6
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     7
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     8
    VirtualMailManager's cli subcommands.
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     9
"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    10
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    11
import locale
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    12
import os
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    13
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    14
from textwrap import TextWrapper
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    15
from time import strftime, strptime
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    16
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    17
from VirtualMailManager import ENCODING
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    18
from VirtualMailManager.account import SERVICES
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    19
from VirtualMailManager.cli import get_winsize, prog, w_err, w_std
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
    20
from VirtualMailManager.common import version_str
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    21
from VirtualMailManager.constants import __copyright__, __date__, \
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    22
     __version__, ACCOUNT_EXISTS, ALIAS_EXISTS, ALIASDOMAIN_ISDOMAIN, \
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    23
     DOMAIN_ALIAS_EXISTS, INVALID_ARGUMENT, EX_MISSING_ARGS, RELOCATED_EXISTS
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    24
from VirtualMailManager.errors import VMMError
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    25
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    26
__all__ = (
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    27
    'Command', 'RunContext', 'cmd_map', 'usage', 'alias_add', 'alias_delete',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    28
    'alias_info', 'aliasdomain_add', 'aliasdomain_delete', 'aliasdomain_info',
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
    29
    'aliasdomain_switch', 'config_get', 'config_set', 'configure',
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
    30
    'domain_add', 'domain_delete',  'domain_info', 'domain_transport',
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
    31
    'get_user', 'help_', 'list_domains', 'relocated_add', 'relocated_delete',
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
    32
    'relocated_info', 'user_add', 'user_delete', 'user_disable', 'user_enable',
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
    33
    'user_info', 'user_name', 'user_password', 'user_transport', 'version',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    34
)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    35
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    36
_ = lambda msg: msg
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    37
txt_wrpr = TextWrapper(width=get_winsize()[1] - 1)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    38
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    39
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    40
class Command(object):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    41
    """Container class for command information."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    42
    __slots__ = ('name', 'alias', 'func', 'args', 'descr')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    43
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    44
    def __init__(self, name, alias, func, args, descr):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    45
        """Create a new Command instance.
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    46
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    47
        Arguments:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    48
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    49
        `name` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    50
          the command name, e.g. ``addalias``
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    51
        `alias` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    52
          the command's short alias, e.g. ``aa``
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    53
        `func` : callable
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    54
          the function to handle the command
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    55
        `args` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    56
          argument placeholders, e.g. ``aliasaddress``
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    57
        `descr` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    58
          short description of the command
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    59
        """
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    60
        self.name = name
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    61
        self.alias = alias
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    62
        self.func = func
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    63
        self.args = args
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    64
        self.descr = descr
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    65
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    66
    @property
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    67
    def usage(self):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    68
        """the command's usage info."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    69
        return u'%s %s %s' % (prog, self.name, self.args)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    70
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    71
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    72
class RunContext(object):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    73
    """Contains all information necessary to run a subcommand."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    74
    __slots__ = ('argc', 'args', 'cget', 'hdlr', 'scmd')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    75
    plan_a_b = _(u'Plan A failed ... trying Plan B: %(subcommand)s %(object)s')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    76
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    77
    def __init__(self, argv, handler, command):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    78
        """Create a new RunContext"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    79
        self.argc = len(argv)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    80
        self.args = [unicode(arg, ENCODING) for arg in argv]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    81
        self.cget = handler.cfg_dget
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    82
        self.hdlr = handler
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    83
        self.scmd = command
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    84
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    85
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    86
def alias_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    87
    """create a new alias e-mail address"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    88
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    89
        usage(EX_MISSING_ARGS, _(u'Missing alias address and destination.'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    90
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    91
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    92
        usage(EX_MISSING_ARGS, _(u'Missing destination address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    93
    ctx.hdlr.alias_add(ctx.args[2].lower(), *ctx.args[3:])
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    94
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    95
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    96
def alias_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    97
    """delete the specified alias e-mail address or one of its destinations"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    98
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    99
        usage(EX_MISSING_ARGS, _(u'Missing alias address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   100
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   101
        ctx.hdlr.alias_delete(ctx.args[2].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   102
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   103
        ctx.hdlr.alias_delete(ctx.args[2].lower(), ctx.args[3])
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   104
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   105
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   106
def alias_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   107
    """show the destination(s) of the specified alias"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   108
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   109
        usage(EX_MISSING_ARGS, _(u'Missing alias address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   110
    address = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   111
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   112
        _print_aliase_info(address, ctx.hdlr.alias_info(address))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   113
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   114
        if err.code is ACCOUNT_EXISTS:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   115
            w_err(0, ctx.plan_a_b % {'subcommand': u'userinfo',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   116
                  'object': address})
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   117
            ctx.args[1] = 'userinfo'
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   118
            user_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   119
        elif err.code is RELOCATED_EXISTS:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   120
            w_std(0, ctx.plan_a_b % {'subcommand': u'relocatedinfo',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   121
                  'object': address})
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   122
            ctx.args[1] = 'relocatedinfo'
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   123
            relocated_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   124
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   125
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   126
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   127
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   128
def aliasdomain_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   129
    """create a new alias for an existing domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   130
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   131
        usage(EX_MISSING_ARGS, _(u'Missing alias domain name and destination '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   132
                                 u'domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   133
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   134
        usage(EX_MISSING_ARGS, _(u'Missing destination domain name.'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   135
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   136
    ctx.hdlr.aliasdomain_add(ctx.args[2].lower(), ctx.args[3].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   137
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   138
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   139
def aliasdomain_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   140
    """delete the specified alias domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   141
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   142
        usage(EX_MISSING_ARGS, _(u'Missing alias domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   143
    ctx.hdlr.aliasdomain_delete(ctx.args[2].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   144
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   145
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   146
def aliasdomain_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   147
    """show the destination of the given alias domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   148
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   149
        usage(EX_MISSING_ARGS, _(u'Missing alias domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   150
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   151
        _print_aliasdomain_info(ctx.hdlr.aliasdomain_info(ctx.args[2].lower()))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   152
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   153
        if err.code is ALIASDOMAIN_ISDOMAIN:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   154
            w_err(0, ctx.plan_a_b % {'subcommand': u'domaininfo',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   155
                  'object': ctx.args[2].lower()})
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   156
            ctx.args[1] = 'domaininfo'
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   157
            domain_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   158
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   159
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   160
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   161
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   162
def aliasdomain_switch(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   163
    """assign the given alias domain to an other domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   164
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   165
        usage(EX_MISSING_ARGS, _(u'Missing alias domain name and destination '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   166
                                 u'domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   167
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   168
        usage(EX_MISSING_ARGS, _(u'Missing destination domain name.'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   169
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   170
    ctx.hdlr.aliasdomain_switch(ctx.args[2].lower(), ctx.args[3].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   171
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   172
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   173
def config_get(ctx):
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   174
    """show the actual value of the configuration option"""
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   175
    if ctx.argc < 3:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   176
        usage(EX_MISSING_ARGS, _(u"Missing option name."), ctx.scmd)
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   177
    option = ctx.args[2].lower()
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   178
    if option != 'misc.dovecot_version':
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   179
        w_std('%s = %s' % (option, ctx.cget(option)))
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   180
    else:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   181
        w_std('%s = %s' % (option, version_str(ctx.cget(option))))
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   182
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   183
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   184
def config_set(ctx):
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   185
    """set a new value for the configuration option"""
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   186
    if ctx.argc < 3:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   187
        usage(EX_MISSING_ARGS, _(u'Missing option and new value.'), ctx.scmd)
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   188
    if ctx.argc < 4:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   189
        usage(EX_MISSING_ARGS, _(u'Missing new configuration value.'),
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   190
              ctx.scmd)
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   191
    ctx.hdlr.cfg_set(ctx.args[2].lower(), ctx.args[3])
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   192
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   193
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   194
def configure(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   195
    """start interactive configuration modus"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   196
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   197
        ctx.hdlr.configure()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   198
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   199
        ctx.hdlr.configure(ctx.args[2].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   200
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   201
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   202
def domain_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   203
    """create a new domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   204
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   205
        usage(EX_MISSING_ARGS, _(u'Missing domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   206
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   207
        ctx.hdlr.domain_add(ctx.args[2].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   208
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   209
        ctx.hdlr.domain_add(ctx.args[2].lower(), ctx.args[3])
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   210
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   211
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   212
def domain_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   213
    """delete the given domain and all its alias domains"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   214
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   215
        usage(EX_MISSING_ARGS, _(u'Missing domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   216
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   217
        ctx.hdlr.domain_delete(ctx.args[2].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   218
    elif ctx.args[3].lower() == 'force':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   219
        ctx.hdlr.domain_delete(ctx.args[2].lower(), True)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   220
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   221
        usage(INVALID_ARGUMENT, _(u"Invalid argument: '%s'") % ctx.args[3],
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   222
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   223
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   224
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   225
def domain_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   226
    """display information about the given domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   227
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   228
        usage(EX_MISSING_ARGS, _(u'Missing domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   229
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   230
        details = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   231
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   232
        details = ctx.args[3].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   233
        if details not in ('accounts', 'aliasdomains', 'aliases', 'full',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   234
                           'relocated'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   235
            usage(INVALID_ARGUMENT, _(u"Invalid argument: '%s'") % details,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   236
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   237
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   238
        info = ctx.hdlr.domain_info(ctx.args[2].lower(), details)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   239
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   240
        if err.code is DOMAIN_ALIAS_EXISTS:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   241
            w_err(0, ctx.plan_a_b % {'subcommand': u'aliasdomaininfo',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   242
                  'object': ctx.args[2].lower()})
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   243
            ctx.args[1] = 'aliasdomaininfo'
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   244
            aliasdomain_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   245
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   246
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   247
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   248
        if not details:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   249
            _print_info(ctx, info, _(u'Domain'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   250
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   251
            _print_info(ctx, info[0], _(u'Domain'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   252
            if details == u'accounts':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   253
                _print_list(info[1], _(u'accounts'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   254
            elif details == u'aliasdomains':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   255
                _print_list(info[1], _(u'alias domains'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   256
            elif details == u'aliases':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   257
                _print_list(info[1], _(u'aliases'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   258
            elif details == u'relocated':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   259
                _print_list(info[1], _(u'relocated users'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   260
            else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   261
                _print_list(info[1], _(u'alias domains'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   262
                _print_list(info[2], _(u'accounts'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   263
                _print_list(info[3], _(u'aliases'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   264
                _print_list(info[4], _(u'relocated users'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   265
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   266
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   267
def domain_transport(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   268
    """update the transport of the specified domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   269
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   270
        usage(EX_MISSING_ARGS, _(u'Missing domain name and new transport.'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   271
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   272
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   273
        usage(EX_MISSING_ARGS, _(u'Missing new transport.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   274
    if ctx.argc < 5:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   275
        ctx.hdlr.domain_transport(ctx.args[2].lower(), ctx.args[3])
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   276
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   277
        force = ctx.args[4].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   278
        if force != 'force':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   279
            usage(INVALID_ARGUMENT, _(u"Invalid argument: '%s'") % force,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   280
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   281
        ctx.hdlr.domain_transport(ctx.args[2].lower(), ctx.args[3], force)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   282
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   283
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   284
def get_user(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   285
    """get the address of the user with the given UID"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   286
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   287
        usage(EX_MISSING_ARGS, _(u'Missing userid.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   288
    _print_info(ctx, ctx.hdlr.user_by_uid(ctx.args[2]), _(u'Account'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   289
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   290
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   291
def help_(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   292
    """print help messgaes."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   293
    if ctx.argc > 2:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   294
        hlptpc = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   295
        if hlptpc in cmd_map:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   296
            topic = hlptpc
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   297
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   298
            for scmd in cmd_map.itervalues():
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   299
                if scmd.alias == hlptpc:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   300
                    topic = scmd.name
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   301
                    break
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   302
            else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   303
                usage(INVALID_ARGUMENT, _(u"Unknown help topic: '%s'") %
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   304
                      ctx.args[2], ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   305
        # FIXME
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   306
        w_err(1, "'help %s' not yet implemented." % topic, 'see also: vmm(1)')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   307
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   308
    old_ii = txt_wrpr.initial_indent
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   309
    old_si = txt_wrpr.subsequent_indent
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   310
    txt_wrpr.initial_indent = ' '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   311
    # len(max(_overview.iterkeys(), key=len)) #Py25
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   312
    txt_wrpr.subsequent_indent = 20 * ' '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   313
    order = cmd_map.keys()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   314
    order.sort()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   315
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   316
    w_std(_(u'List of available subcommands:') + '\n')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   317
    for key in order:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   318
        w_std('\n'.join(txt_wrpr.wrap('%-18s %s' % (key, cmd_map[key].descr))))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   319
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   320
    txt_wrpr.initial_indent = old_ii
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   321
    txt_wrpr.subsequent_indent = old_si
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   322
    txt_wrpr.initial_indent = ''
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   323
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   324
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   325
def list_domains(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   326
    """list all domains / search domains by pattern"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   327
    matching = ctx.argc > 2
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   328
    if matching:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   329
        gids, domains = ctx.hdlr.domain_list(ctx.args[2].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   330
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   331
        gids, domains = ctx.hdlr.domain_list()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   332
    _print_domain_list(gids, domains, matching)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   333
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   334
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   335
def relocated_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   336
    """create a new record for a relocated user"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   337
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   338
        usage(EX_MISSING_ARGS,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   339
              _(u'Missing relocated address and destination.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   340
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   341
        usage(EX_MISSING_ARGS, _(u'Missing destination address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   342
    ctx.hdlr.relocated_add(ctx.args[2].lower(), ctx.args[3])
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   343
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   344
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   345
def relocated_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   346
    """delete the record of the relocated user"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   347
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   348
        usage(EX_MISSING_ARGS, _(u'Missing relocated address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   349
    ctx.hdlr.relocated_delete(ctx.args[2].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   350
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   351
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   352
def relocated_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   353
    """print information about a relocated user"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   354
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   355
        usage(EX_MISSING_ARGS, _(u'Missing relocated address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   356
    relocated = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   357
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   358
        _print_relocated_info(addr=relocated,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   359
                              dest=ctx.hdlr.relocated_info(relocated))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   360
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   361
        if err.code is ACCOUNT_EXISTS:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   362
            w_err(0, ctx.plan_a_b % {'subcommand': u'userinfo',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   363
                  'object': relocated})
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   364
            ctx.args[1] = 'userinfoi'
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   365
            user_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   366
        elif err.code is ALIAS_EXISTS:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   367
            w_err(0, ctx.plan_a_b % {'subcommand': u'aliasinfo',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   368
                  'object': relocated})
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   369
            ctx.args[1] = 'aliasinfo'
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   370
            alias_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   371
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   372
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   373
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   374
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   375
def user_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   376
    """create a new e-mail user with the given address"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   377
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   378
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   379
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   380
        password = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   381
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   382
        password = ctx.args[3]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   383
    ctx.hdlr.user_add(ctx.args[2].lower(), password)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   384
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   385
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   386
def user_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   387
    """delete the specified user"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   388
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   389
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   390
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   391
        ctx.hdlr.user_delete(ctx.args[2].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   392
    elif ctx.args[3].lower() == 'force':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   393
        ctx.hdlr.user_delete(ctx.args[2].lower(), True)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   394
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   395
        usage(INVALID_ARGUMENT, _(u"Invalid argument: '%s'") % ctx.args[3],
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   396
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   397
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   398
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   399
def user_disable(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   400
    """deactivate all/the given service(s) for a user"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   401
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   402
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   403
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   404
        ctx.hdlr.user_disable(ctx.args[2].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   405
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   406
        services = [service.lower() for service in ctx.args[3:]]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   407
        unknown = [service for service in services if service not in SERVICES]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   408
        if unknown:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   409
            usage(INVALID_ARGUMENT, _(u"Invalid service arguments: %s") %
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   410
                  ' '.join(unknown), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   411
        ctx.hdlr.user_disable(ctx.args[2].lower(), services)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   412
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   413
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   414
def user_enable(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   415
    """activate all or the given service(s) for a user"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   416
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   417
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   418
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   419
        ctx.hdlr.user_enable(ctx.args[2].lower())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   420
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   421
        services = [service.lower() for service in ctx.args[3:]]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   422
        unknown = [service for service in services if service not in SERVICES]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   423
        if unknown:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   424
            usage(INVALID_ARGUMENT, _(u"Invalid service arguments: %s") %
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   425
                  ' '.join(unknown), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   426
        ctx.hdlr.user_enable(ctx.args[2].lower(), services)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   427
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   428
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   429
def user_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   430
    """display information about the given address"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   431
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   432
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   433
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   434
        details = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   435
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   436
        details = ctx.args[3].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   437
        if details not in ('aliases', 'du', 'full'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   438
            usage(INVALID_ARGUMENT, _(u"Invalid argument: '%s'") % details,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   439
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   440
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   441
        info = ctx.hdlr.user_info(ctx.args[2].lower(), details)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   442
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   443
        if err.code is ALIAS_EXISTS:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   444
            w_err(0, ctx.plan_a_b % {'subcommand': u'aliasinfo',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   445
                  'object': ctx.args[2].lower()})
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   446
            ctx.args[1] = 'aliasinfo'
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   447
            alias_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   448
        elif err.code is RELOCATED_EXISTS:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   449
            w_err(0, ctx.plan_a_b % {'subcommand': u'relocatedinfo',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   450
                  'object': ctx.args[2].lower()})
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   451
            ctx.args[1] = 'relocatedinfo'
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   452
            relocated_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   453
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   454
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   455
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   456
        if details in (None, 'du'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   457
            _print_info(ctx, info, _(u'Account'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   458
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   459
            _print_info(ctx, info[0], _(u'Account'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   460
            _print_list(info[1], _(u'alias addresses'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   461
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   462
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   463
def user_name(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   464
    """set or update the real name for an address"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   465
    if ctx.argc < 3:
341
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 340
diff changeset
   466
        usage(EX_MISSING_ARGS, _(u"Missing e-mail address and user's name."),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   467
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   468
    if ctx.argc < 4:
341
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 340
diff changeset
   469
        usage(EX_MISSING_ARGS, _(u"Missing user's name."), ctx.scmd)
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   470
    ctx.hdlr.user_name(ctx.args[2].lower(), ctx.args[3])
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   471
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   472
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   473
def user_password(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   474
    """update the password for the given address"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   475
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   476
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   477
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   478
        password = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   479
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   480
        password = ctx.args[3]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   481
    ctx.hdlr.user_password(ctx.args[2].lower(), password)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   482
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   483
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   484
def user_transport(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   485
    """update the transport of the given address"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   486
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   487
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address and transport.'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   488
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   489
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   490
        usage(EX_MISSING_ARGS, _(u'Missing transport.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   491
    ctx.hdlr.user_transport(ctx.args[2].lower(), ctx.args[3])
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   492
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   493
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   494
def usage(errno, errmsg, subcommand=None):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   495
    """print usage message for the given command or all commands.
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   496
    When errno > 0, sys,exit(errno) will interrupt the program.
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   497
    """
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   498
    if subcommand and subcommand in cmd_map:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   499
        w_err(errno, _(u"Error: %s") % errmsg,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   500
              _(u"usage: ") + cmd_map[subcommand].usage)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   501
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   502
    # TP: Please adjust translated words like the original text.
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   503
    # (It's a table header.) Extract from usage text:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   504
    # usage: vmm subcommand arguments
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   505
    #   short long
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   506
    #   subcommand                arguments
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   507
    #
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   508
    #   da    domainadd           fqdn [transport]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   509
    #   dd    domaindelete        fqdn [force]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   510
    u_head = _(u"""usage: %s subcommand arguments
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   511
  short long
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   512
  subcommand                arguments\n""") % prog
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   513
    order = cmd_map.keys()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   514
    order.sort()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   515
    w_err(0, u_head)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   516
    for key in order:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   517
        scmd = cmd_map[key]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   518
        w_err(0, '  %-5s %-19s %s' % (scmd.alias, scmd.name, scmd.args))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   519
    w_err(errno, '', _(u"Error: %s") % errmsg)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   520
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   521
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   522
def version(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   523
    """Write version and copyright information to stdout."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   524
    w_std('%s, %s %s (%s %s)\nPython %s %s %s\n\n%s\n%s %s' % (prog,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   525
    # TP: The words 'from', 'version' and 'on' are used in
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   526
    # the version information, e.g.:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   527
    # vmm, version 0.5.2 (from 09/09/09)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   528
    # Python 2.5.4 on FreeBSD
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   529
        _(u'version'), __version__, _(u'from'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   530
        strftime(locale.nl_langinfo(locale.D_FMT),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   531
            strptime(__date__, '%Y-%m-%d')).decode(ENCODING, 'replace'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   532
        os.sys.version.split()[0], _(u'on'), os.uname()[0],
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   533
        __copyright__, prog,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   534
        _(u'is free software and comes with ABSOLUTELY NO WARRANTY.')))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   535
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   536
cmd = Command
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   537
cmd_map = {  # {{{
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   538
    # Account commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   539
    'getuser': cmd('getuser', 'gu', get_user, 'uid',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   540
                   _(u'get the address of the user with the given UID')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   541
    'useradd': cmd('useradd', 'ua', user_add, 'address [password]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   542
                   _(u'create a new e-mail user with the given address')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   543
    'userdelete': cmd('userdelete', 'ud', user_delete, 'address [force]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   544
                      _(u'delete the specified user')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   545
    'userdisable': cmd('userdisable', 'u0', user_disable,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   546
                       'address [service ...]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   547
                       _(u'deactivate all/the given service(s) for a user')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   548
    'userenable': cmd('userenable', 'u1', user_enable, 'address [service ...]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   549
                      _(u'activate all or the given service(s) for a user')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   550
    'userinfo': cmd('userinfo', 'ui', user_info, 'address [details]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   551
                    _(u'display information about the given address')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   552
    'username': cmd('username', 'un', user_name, 'address name',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   553
                    _(u'set or update the real name for an address')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   554
    'userpassword': cmd('userpassword', 'up', user_password,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   555
                        'address [password]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   556
                        _(u'update the password for the given address')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   557
    'usertransport': cmd('usertransport', 'ut', user_transport,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   558
                         'address transport',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   559
                         _(u'update the transport of the given address')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   560
    # Alias commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   561
    'aliasadd': cmd('aliasadd', 'aa', alias_add, 'address destination ...',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   562
                    _(u'create a new alias e-mail address')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   563
    'aliasdelete': cmd('aliasdelete', 'ad', alias_delete,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   564
                       'address [destination]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   565
                       _(u'delete the specified alias e-mail address or one '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   566
                         u'of its destinations')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   567
    'aliasinfo': cmd('aliasinfo', 'ai', alias_info, 'address',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   568
                     _(u'show the destination(s) of the specified alias')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   569
    # AliasDomain commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   570
    'aliasdomainadd': cmd('aliasdomainadd', 'ada', aliasdomain_add,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   571
                          'fqdn destination',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   572
                          _(u'create a new alias for an existing domain')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   573
    'aliasdomaindelete': cmd('aliasdomaindelete', 'add', aliasdomain_delete,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   574
                             'fqdn', _(u'delete the specified alias domain')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   575
    'aliasdomaininfo': cmd('aliasdomaininfo', 'adi', aliasdomain_info, 'fqdn',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   576
                         _(u'show the destination of the given alias domain')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   577
    'aliasdomainswitch': cmd('aliasdomainswitch', 'ads', aliasdomain_switch,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   578
                             'fqdn destination',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   579
                       _(u'assign the given alias domain to an other domain')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   580
    # Domain commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   581
    'domainadd': cmd('domainadd', 'da', domain_add, 'fqdn [transport]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   582
                     _(u'create a new domain')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   583
    'domaindelete': cmd('domaindelete', 'dd', domain_delete, 'fqdn [force]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   584
                      _(u'delete the given domain and all its alias domains')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   585
    'domaininfo': cmd('domaininfo', 'di', domain_info, 'fqdn [details]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   586
                      _(u'display information about the given domain')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   587
    'domaintransport': cmd('domaintransport', 'dt', domain_transport,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   588
                           'fqdn transport [force]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   589
                           _(u'update the transport of the specified domain')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   590
    'listdomains': cmd('listdomains', 'ld', list_domains, '[pattern]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   591
                       _(u'list all domains / search domains by pattern')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   592
    # Relocated commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   593
    'relocatedadd': cmd('relocatedadd', 'ra', relocated_add,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   594
                        'address newaddress',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   595
                        _(u'create a new record for a relocated user')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   596
    'relocateddelete': cmd('relocateddelete', 'rd', relocated_delete,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   597
                           'address',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   598
                           _(u'delete the record of the relocated user')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   599
    'relocatedinfo': cmd('relocatedinfo', 'ri', relocated_info, 'address',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   600
                         _(u'print information about a relocated user')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   601
    # cli commands
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   602
    'configget': cmd('configget', 'cg', config_get, 'option',
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   603
                     _('show the actual value of the configuration option')),
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   604
    'configset': cmd('configset', 'cs', config_set, 'option value',
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   605
                      _('set a new value for the configuration option')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   606
    'configure': cmd('configure', 'cf', configure, '[section]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   607
                     _(u'start interactive configuration modus')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   608
    'help': cmd('help', 'h', help_, '[subcommand]',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   609
                _(u'show a help overview or help for the given subcommand')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   610
    'version': cmd('version', 'v', version, '',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   611
                   _(u'show version and copyright information')),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   612
}  # }}}
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   613
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   614
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   615
def _get_order(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   616
    """returns a tuple with (key, 1||0) tuples. Used by functions, which
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   617
    get a dict from the handler."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   618
    order = ()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   619
    if ctx.scmd == 'domaininfo':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   620
        order = ((u'domainname', 0), (u'gid', 1), (u'transport', 0),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   621
                 (u'domaindir', 0), (u'aliasdomains', 0), (u'accounts', 0),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   622
                 (u'aliases', 0), (u'relocated', 0))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   623
    elif ctx.scmd == 'userinfo':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   624
        dc12 = ctx.cget('misc.dovecot_version') >= 0x10200b02
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   625
        sieve = (u'managesieve', u'sieve')[dc12]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   626
        if ctx.argc == 4 and ctx.args[3] != u'aliases' or \
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   627
           ctx.cget('account.disk_usage'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   628
            order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   629
                     (u'home', 0), (u'mail_location', 0), (u'disk usage', 0),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   630
                     (u'transport', 0), (u'smtp', 1), (u'pop3', 1),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   631
                     (u'imap', 1), (sieve, 1))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   632
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   633
            order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   634
                     (u'home', 0), (u'mail_location', 0), (u'transport', 0),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   635
                     (u'smtp', 1), (u'pop3', 1), (u'imap', 1), (sieve, 1))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   636
    elif ctx.scmd == 'getuser':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   637
        order = ((u'uid', 1), (u'gid', 1), (u'address', 0))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   638
    return order
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   639
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   640
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   641
def _print_info(ctx, info, title):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   642
    """Print info dicts."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   643
    # TP: used in e.g. 'Domain information' or 'Account information'
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   644
    msg = u'%s %s' % (title, _(u'information'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   645
    w_std(msg, u'-' * len(msg))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   646
    for key, upper in _get_order(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   647
        if upper:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   648
            w_std(u'\t%s: %s' % (key.upper().ljust(15, u'.'), info[key]))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   649
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   650
            w_std(u'\t%s: %s' % (key.title().ljust(15, u'.'), info[key]))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   651
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   652
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   653
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   654
def _print_list(alist, title):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   655
    """Print a list."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   656
    # TP: used in e.g. 'Available alias addresses' or 'Available accounts'
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   657
    msg = u'%s %s' % (_(u'Available'), title)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   658
    w_std(msg, u'-' * len(msg))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   659
    if alist:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   660
        if title != _(u'alias domains'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   661
            w_std(*(u'\t%s' % item for item in alist))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   662
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   663
            for domain in alist:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   664
                if not domain.startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   665
                    w_std(u'\t%s' % domain)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   666
                else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   667
                    w_std(u'\t%s (%s)' % (domain, domain.decode('idna')))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   668
        print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   669
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   670
        w_std(_(u'\tNone'), '')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   671
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   672
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   673
def _print_aliase_info(alias, destinations):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   674
    """Print the alias address and all its destinations"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   675
    title = _(u'Alias information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   676
    w_std(title, u'-' * len(title))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   677
    w_std(_(u'\tMail for %s will be redirected to:') % alias)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   678
    w_std(*(u'\t     * %s' % dest for dest in destinations))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   679
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   680
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   681
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   682
def _print_relocated_info(**kwargs):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   683
    """Print the old and new addresses of a relocated user."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   684
    title = _(u'Relocated information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   685
    w_std(title, u'-' * len(title))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   686
    w_std(_(u"\tUser '%(addr)s' has moved to '%(dest)s'") % kwargs, '')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   687
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   688
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   689
def _format_domain(domain, main=True):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   690
    """format (prefix/convert) the domain name."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   691
    if domain.startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   692
        domain = u'%s (%s)' % (domain, domain.decode('idna'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   693
    if main:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   694
        return u'\t[+] %s' % domain
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   695
    return u'\t[-]     %s' % domain
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   696
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   697
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   698
def _print_domain_list(dids, domains, matching):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   699
    """Print a list of (matching) domains/alias domains."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   700
    if matching:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   701
        title = _(u'Matching domains')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   702
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   703
        title = _(u'Available domains')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   704
    w_std(title, '-' * len(title))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   705
    if domains:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   706
        for did in dids:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   707
            if domains[did][0] is not None:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   708
                w_std(_format_domain(domains[did][0]))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   709
            if len(domains[did]) > 1:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   710
                w_std(*(_format_domain(a, False) for a in domains[did][1:]))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   711
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   712
        w_std(_('\tNone'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   713
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   714
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   715
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   716
def _print_aliasdomain_info(info):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   717
    """Print alias domain information."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   718
    title = _(u'Alias domain information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   719
    for key in ('alias', 'domain'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   720
        if info[key].startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   721
            info[key] = u'%s (%s)' % (info[key], info[key].decode('idna'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   722
    w_std(title, '-' * len(title),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   723
          _('\tThe alias domain %(alias)s belongs to:\n\t    * %(domain)s') %
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   724
          info, '')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   725
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   726
del _