VirtualMailManager/cli/subcommands.py
author Pascal Volk <neverseen@users.sourceforge.net>
Thu, 03 Nov 2011 05:07:17 +0000
branchv0.6.x
changeset 445 b8c94e06cd46
parent 429 9842650569c2
child 446 18b75e6a39d5
permissions -rw-r--r--
VMM/cli/subcommands: Added subcommand domainservices (ds). Replaced subcommands userdisable and userenable by userservices (us).
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 -*-
366
d6573da35b5f Updated copyright notices to include the year 2011.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 362
diff changeset
     2
# Copyright 2007 - 2011, Pascal Volk
340
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.cli import get_winsize, prog, w_err, w_std
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
    19
from VirtualMailManager.common import human_size, size_in_bytes, version_str
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    20
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
    21
     __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
    22
     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
    23
from VirtualMailManager.errors import VMMError
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
    24
from VirtualMailManager.serviceset import SERVICES
340
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',
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
    30
    'domain_add', 'domain_delete',  'domain_info', 'domain_quota',
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
    31
    'domain_services', 'domain_transport', 'get_user', 'help_', 'list_domains',
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
    32
    'relocated_add', 'relocated_delete', 'relocated_info', 'user_add',
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
    33
    'user_delete', 'user_info', 'user_name', 'user_password', 'user_quota',
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
    34
    'user_services', 'user_transport', 'version',
340
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
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    37
_ = lambda msg: msg
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    38
txt_wrpr = TextWrapper(width=get_winsize()[1] - 1)
420
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
    39
cmd_map = {}
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    40
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    41
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    42
class Command(object):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    43
    """Container class for command information."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    44
    __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
    45
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    46
    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
    47
        """Create a new Command instance.
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
        Arguments:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    50
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    51
        `name` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    52
          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
    53
        `alias` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    54
          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
    55
        `func` : callable
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    56
          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
    57
        `args` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    58
          argument placeholders, e.g. ``aliasaddress``
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    59
        `descr` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    60
          short description of the command
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    61
        """
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    62
        self.name = name
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    63
        self.alias = alias
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    64
        self.func = func
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    65
        self.args = args
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    66
        self.descr = descr
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    67
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    68
    @property
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    69
    def usage(self):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    70
        """the command's usage info."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    71
        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
    72
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    73
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    74
class RunContext(object):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    75
    """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
    76
    __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
    77
    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
    78
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    79
    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
    80
        """Create a new RunContext"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    81
        self.argc = len(argv)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    82
        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
    83
        self.cget = handler.cfg_dget
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    84
        self.hdlr = handler
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    85
        self.scmd = command
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    86
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    87
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    88
def alias_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    89
    """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
    90
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    91
        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
    92
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    93
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    94
        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
    95
    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
    96
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    97
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    98
def alias_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    99
    """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
   100
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   101
        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
   102
    elif ctx.argc < 4:
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())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   104
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   105
        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
   106
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   107
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   108
def alias_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   109
    """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
   110
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   111
        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
   112
    address = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   113
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   114
        _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
   115
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   116
        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
   117
            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
   118
                  'object': address})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   119
            ctx.scmd = ctx.args[1] = 'userinfo'
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   120
            user_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   121
        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
   122
            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
   123
                  'object': address})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   124
            ctx.scmd = ctx.args[1] = 'relocatedinfo'
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   125
            relocated_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   126
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   127
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   128
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   129
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   130
def aliasdomain_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   131
    """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
   132
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   133
        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
   134
                                 u'domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   135
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   136
        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
   137
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   138
    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
   139
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   140
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   141
def aliasdomain_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   142
    """delete the specified alias domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   143
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   144
        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
   145
    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
   146
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   147
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   148
def aliasdomain_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   149
    """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
   150
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   151
        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
   152
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   153
        _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
   154
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   155
        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
   156
            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
   157
                  'object': ctx.args[2].lower()})
409
54a89c19e534 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 408
diff changeset
   158
            ctx.scmd = ctx.args[1] = 'domaininfo'
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   159
            domain_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   160
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   161
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   162
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   163
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   164
def aliasdomain_switch(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   165
    """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
   166
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   167
        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
   168
                                 u'domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   169
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   170
        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
   171
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   172
    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
   173
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   174
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   175
def config_get(ctx):
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   176
    """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
   177
    if ctx.argc < 3:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   178
        usage(EX_MISSING_ARGS, _(u"Missing option name."), ctx.scmd)
397
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   179
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   180
    noop = lambda option: option
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   181
    opt_formater = {
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   182
        'misc.dovecot_version': version_str,
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   183
        'misc.quota_bytes': human_size,
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   184
    }
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   185
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   186
    option = ctx.args[2].lower()
397
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   187
    w_std('%s = %s' % (option, opt_formater.get(option,
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   188
                       noop)(ctx.cget(option))))
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   189
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   190
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   191
def config_set(ctx):
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   192
    """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
   193
    if ctx.argc < 3:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   194
        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
   195
    if ctx.argc < 4:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   196
        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
   197
              ctx.scmd)
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   198
    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
   199
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   200
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   201
def configure(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   202
    """start interactive configuration modus"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   203
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   204
        ctx.hdlr.configure()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   205
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   206
        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
   207
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   208
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   209
def domain_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   210
    """create a new domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   211
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   212
        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
   213
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   214
        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
   215
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   216
        ctx.hdlr.domain_add(ctx.args[2].lower(), ctx.args[3])
362
c2e8eab2616d VMM/cli/subcommands: Added 'auto postmaster' to domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 361
diff changeset
   217
    if not ctx.cget('domain.auto_postmaster'):
c2e8eab2616d VMM/cli/subcommands: Added 'auto postmaster' to domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 361
diff changeset
   218
        return
c2e8eab2616d VMM/cli/subcommands: Added 'auto postmaster' to domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 361
diff changeset
   219
    ctx.scmd = 'useradd'
c2e8eab2616d VMM/cli/subcommands: Added 'auto postmaster' to domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 361
diff changeset
   220
    ctx.args = [prog, ctx.scmd, u'postmaster@' + ctx.args[2].lower()]
c2e8eab2616d VMM/cli/subcommands: Added 'auto postmaster' to domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 361
diff changeset
   221
    ctx.argc = 3
c2e8eab2616d VMM/cli/subcommands: Added 'auto postmaster' to domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 361
diff changeset
   222
    user_add(ctx)
340
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_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   226
    """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
   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
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   230
        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
   231
    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
   232
        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
   233
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   234
        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
   235
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   236
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   237
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   238
def domain_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   239
    """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
   240
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   241
        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
   242
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   243
        details = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   244
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   245
        details = ctx.args[3].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   246
        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
   247
                           'relocated'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   248
            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
   249
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   250
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   251
        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
   252
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   253
        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
   254
            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
   255
                  'object': ctx.args[2].lower()})
409
54a89c19e534 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 408
diff changeset
   256
            ctx.scmd = ctx.args[1] = 'aliasdomaininfo'
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   257
            aliasdomain_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   258
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   259
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   260
    else:
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   261
        q_limit = u'Storage: %(bytes)s; Messages: %(messages)s'
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   262
        if not details:
408
f6e55b27fe07 VMM/cli/subcommands: Fixed a msgid issue (format string with unnamed arguments).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 406
diff changeset
   263
            info['bytes'] = human_size(info['bytes'])
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   264
            info['messages'] = locale.format('%d', info['messages'], True)
408
f6e55b27fe07 VMM/cli/subcommands: Fixed a msgid issue (format string with unnamed arguments).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 406
diff changeset
   265
            info['quota limit'] = q_limit % info
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   266
            _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
   267
        else:
408
f6e55b27fe07 VMM/cli/subcommands: Fixed a msgid issue (format string with unnamed arguments).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 406
diff changeset
   268
            info[0]['bytes'] = human_size(info[0]['bytes'])
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   269
            info[0]['messages'] = locale.format('%d', info[0]['messages'],
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   270
                                                True)
408
f6e55b27fe07 VMM/cli/subcommands: Fixed a msgid issue (format string with unnamed arguments).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 406
diff changeset
   271
            info[0]['quota limit'] = q_limit % info[0]
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   272
            _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
   273
            if details == u'accounts':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   274
                _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
   275
            elif details == u'aliasdomains':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   276
                _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
   277
            elif details == u'aliases':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   278
                _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
   279
            elif details == u'relocated':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   280
                _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
   281
            else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   282
                _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
   283
                _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
   284
                _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
   285
                _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
   286
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   287
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   288
def domain_quota(ctx):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   289
    """update the quota limit of the specified domain"""
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   290
    if ctx.argc < 3:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   291
        usage(EX_MISSING_ARGS, _(u'Missing domain name and storage value.'),
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   292
              ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   293
    if ctx.argc < 4:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   294
        usage(EX_MISSING_ARGS, _(u'Missing storage value.'), ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   295
    messages = 0
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   296
    force = None
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   297
    try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   298
        bytes_ = size_in_bytes(ctx.args[3])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   299
    except (ValueError, TypeError):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   300
        usage(INVALID_ARGUMENT, _(u"Invalid storage value: '%s'") %
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   301
              ctx.args[3], ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   302
    if ctx.argc < 5:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   303
        pass
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   304
    elif ctx.argc < 6:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   305
        try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   306
            messages = int(ctx.args[4])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   307
        except ValueError:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   308
            if ctx.args[4].lower() != 'force':
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   309
                usage(INVALID_ARGUMENT,
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   310
                      _(u"Neither a valid number of messages nor the keyword "
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   311
                        u"'force': '%s'") % ctx.args[4], ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   312
            force = 'force'
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   313
    else:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   314
        try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   315
            messages = int(ctx.args[4])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   316
        except ValueError:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   317
            usage(INVALID_ARGUMENT,
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   318
                  _(u"Not a valid number of messages: '%s'") % ctx.args[4],
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   319
                  ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   320
        if ctx.args[5].lower() != 'force':
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   321
            usage(INVALID_ARGUMENT, _(u"Invalid argument: '%s'") % ctx.args[5],
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   322
                  ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   323
        force = 'force'
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   324
    ctx.hdlr.domain_quotalimit(ctx.args[2].lower(), bytes_, messages, force)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   325
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   326
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   327
def domain_services(ctx):
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   328
    """allow all named service and block the uncredited."""
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   329
    if ctx.argc < 3:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   330
        usage(EX_MISSING_ARGS, _(u'Missing domain name.'), ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   331
    services = []
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   332
    force = False
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   333
    if ctx.argc is 4:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   334
        arg = ctx.args[3].lower()
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   335
        if arg in SERVICES:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   336
            services.append(arg)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   337
        elif arg == 'force':
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   338
            force = True
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   339
        else:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   340
            usage(INVALID_ARGUMENT, _(u"Invalid argument: '%s'") % arg,
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   341
                  ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   342
    else:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   343
        services.extend([service.lower() for service in ctx.args[3:-1]])
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   344
        arg = ctx.args[-1].lower()
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   345
        if arg == 'force':
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   346
            force = True
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   347
        else:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   348
            services.append(arg)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   349
        unknown = [service for service in services if service not in SERVICES]
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   350
        if unknown:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   351
            usage(INVALID_ARGUMENT, _(u'Invalid service arguments: %s') %
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   352
                  ' '.join(unknown), ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   353
    ctx.hdlr.domain_services(ctx.args[2].lower(), (None, 'force')[force],
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   354
                             *services)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   355
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   356
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   357
def domain_transport(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   358
    """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
   359
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   360
        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
   361
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   362
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   363
        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
   364
    if ctx.argc < 5:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   365
        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
   366
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   367
        force = ctx.args[4].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   368
        if force != 'force':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   369
            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
   370
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   371
        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
   372
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
def get_user(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   375
    """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
   376
    if ctx.argc < 3:
417
8209da83e256 VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 414
diff changeset
   377
        usage(EX_MISSING_ARGS, _(u'Missing UID.'), ctx.scmd)
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   378
    _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
   379
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   380
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   381
def help_(ctx):
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   382
    """print help messages."""
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   383
    if ctx.argc > 2:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   384
        hlptpc = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   385
        if hlptpc in cmd_map:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   386
            topic = hlptpc
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   387
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   388
            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
   389
                if scmd.alias == hlptpc:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   390
                    topic = scmd.name
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   391
                    break
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   392
            else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   393
                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
   394
                      ctx.args[2], ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   395
        # FIXME
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   396
        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
   397
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   398
    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
   399
    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
   400
    txt_wrpr.initial_indent = ' '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   401
    # 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
   402
    txt_wrpr.subsequent_indent = 20 * ' '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   403
    order = cmd_map.keys()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   404
    order.sort()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   405
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   406
    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
   407
    for key in order:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   408
        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
   409
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   410
    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
   411
    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
   412
    txt_wrpr.initial_indent = ''
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
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   415
def list_domains(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   416
    """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
   417
    matching = ctx.argc > 2
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   418
    if matching:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   419
        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
   420
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   421
        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
   422
    _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
   423
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   424
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   425
def relocated_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   426
    """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
   427
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   428
        usage(EX_MISSING_ARGS,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   429
              _(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
   430
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   431
        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
   432
    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
   433
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   434
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   435
def relocated_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   436
    """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
   437
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   438
        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
   439
    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
   440
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   441
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   442
def relocated_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   443
    """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
   444
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   445
        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
   446
    relocated = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   447
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   448
        _print_relocated_info(addr=relocated,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   449
                              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
   450
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   451
        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
   452
            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
   453
                  'object': relocated})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   454
            ctx.scmd = ctx.args[1] = 'userinfoi'
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   455
            user_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   456
        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
   457
            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
   458
                  'object': relocated})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   459
            ctx.scmd = ctx.args[1] = 'aliasinfo'
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   460
            alias_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   461
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   462
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   463
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   464
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   465
def user_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   466
    """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
   467
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   468
        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
   469
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   470
        password = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   471
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   472
        password = ctx.args[3]
361
971577b89d26 VMM/cli/handler: Added support for random passwords in user_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 345
diff changeset
   473
    gen_pass = ctx.hdlr.user_add(ctx.args[2].lower(), password)
423
a43a2e20de71 VMM/cli/subcommands: user_add() show only generated passwords - not the given.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 420
diff changeset
   474
    if ctx.argc < 4 and gen_pass:
361
971577b89d26 VMM/cli/handler: Added support for random passwords in user_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 345
diff changeset
   475
        w_std(_(u"Generated password: %s") % gen_pass)
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   476
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   477
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   478
def user_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   479
    """delete the specified user"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   480
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   481
        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
   482
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   483
        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
   484
    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
   485
        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
   486
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   487
        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
   488
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   489
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   490
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   491
def user_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   492
    """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
   493
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   494
        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
   495
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   496
        details = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   497
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   498
        details = ctx.args[3].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   499
        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
   500
            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
   501
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   502
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   503
        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
   504
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   505
        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
   506
            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
   507
                  'object': ctx.args[2].lower()})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   508
            ctx.scmd = ctx.args[1] = 'aliasinfo'
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   509
            alias_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   510
        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
   511
            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
   512
                  'object': ctx.args[2].lower()})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   513
            ctx.scmd = ctx.args[1] = 'relocatedinfo'
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   514
            relocated_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   515
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   516
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   517
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   518
        if details in (None, 'du'):
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   519
            info['quota storage'] = _format_quota_usage(info['ql_bytes'],
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   520
                    info['uq_bytes'], True)
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   521
            info['quota messages'] = _format_quota_usage(info['ql_messages'],
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   522
                    info['uq_messages'])
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   523
            _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
   524
        else:
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   525
            info[0]['quota storage'] = _format_quota_usage(info[0]['ql_bytes'],
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   526
                    info['uq_bytes'], True)
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   527
            info[0]['quota messages'] = _format_quota_usage(
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   528
                    info[0]['ql_messages'], info[0]['uq_messages'])
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   529
            _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
   530
            _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
   531
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   532
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   533
def user_name(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   534
    """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
   535
    if ctx.argc < 3:
341
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 340
diff changeset
   536
        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
   537
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   538
    if ctx.argc < 4:
341
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 340
diff changeset
   539
        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
   540
    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
   541
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   542
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   543
def user_password(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   544
    """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
   545
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   546
        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
   547
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   548
        password = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   549
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   550
        password = ctx.args[3]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   551
    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
   552
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   553
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   554
def user_quota(ctx):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   555
    """update the quota limit for the given address"""
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   556
    if ctx.argc < 3:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   557
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address and storage value.'),
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   558
              ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   559
    elif ctx.argc < 4:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   560
        usage(EX_MISSING_ARGS, _(u'Missing storage value.'), ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   561
    try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   562
        bytes_ = size_in_bytes(ctx.args[3])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   563
    except (ValueError, TypeError):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   564
        usage(INVALID_ARGUMENT, _(u"Invalid storage value: '%s'") %
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   565
              ctx.args[3], ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   566
    if ctx.argc < 5:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   567
        messages = 0
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   568
    else:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   569
        try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   570
            messages = int(ctx.args[4])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   571
        except ValueError:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   572
            usage(INVALID_ARGUMENT,
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   573
                  _(u"Not a valid number of messages: '%s'") % ctx.args[4],
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   574
                  ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   575
    ctx.hdlr.user_quotalimit(ctx.args[2].lower(), bytes_, messages)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   576
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   577
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   578
def user_services(ctx):
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   579
    """allow all named service and block the uncredited."""
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   580
    if ctx.argc < 3:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   581
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address.'), ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   582
    services = []
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   583
    if ctx.argc >= 4:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   584
        services.extend([service.lower() for service in ctx.args[3:]])
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   585
        unknown = [service for service in services if service not in SERVICES]
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   586
        if unknown:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   587
            usage(INVALID_ARGUMENT, _(u'Invalid service arguments: %s') %
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   588
                  ' '.join(unknown), ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   589
    ctx.hdlr.user_services(ctx.args[2].lower(), *services)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   590
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   591
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   592
def user_transport(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   593
    """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
   594
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   595
        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
   596
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   597
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   598
        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
   599
    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
   600
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   601
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   602
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
   603
    """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
   604
    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
   605
    """
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   606
    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
   607
        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
   608
              _(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
   609
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   610
    # 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
   611
    # (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
   612
    # usage: vmm subcommand arguments
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   613
    #   short long
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   614
    #   subcommand                arguments
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   615
    #
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   616
    #   da    domainadd           fqdn [transport]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   617
    #   dd    domaindelete        fqdn [force]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   618
    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
   619
  short long
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   620
  subcommand                arguments\n""") % prog
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   621
    order = cmd_map.keys()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   622
    order.sort()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   623
    w_err(0, u_head)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   624
    for key in order:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   625
        scmd = cmd_map[key]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   626
        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
   627
    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
   628
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   629
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   630
def version(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   631
    """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
   632
    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
   633
    # 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
   634
    # the version information, e.g.:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   635
    # 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
   636
    # 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
   637
        _(u'version'), __version__, _(u'from'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   638
        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
   639
            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
   640
        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
   641
        __copyright__, prog,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   642
        _(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
   643
420
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   644
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   645
def update_cmd_map():
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   646
    """Update the cmd_map, after gettext's _ was installed."""
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   647
    cmd = Command
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   648
    cmd_map.update({
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   649
    # Account commands
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   650
    'getuser': cmd('getuser', 'gu', get_user, _(u'uid'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   651
                   _(u'get the address of the user with the given UID')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   652
    'useradd': cmd('useradd', 'ua', user_add, _(u'address [password]'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   653
                   _(u'create a new e-mail user with the given address')),
418
542a4d23a9f0 VMM/cli/subcommands: The keyword 'force' is no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 417
diff changeset
   654
    'userdelete': cmd('userdelete', 'ud', user_delete,
420
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   655
                      _(u'address') + ' [force]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   656
                      _(u'delete the specified user')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   657
    'userinfo': cmd('userinfo', 'ui', user_info, _(u'address [details]'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   658
                    _(u'display information about the given address')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   659
    'username': cmd('username', 'un', user_name, _(u'address name'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   660
                    _(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
   661
    'userpassword': cmd('userpassword', 'up', user_password,
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   662
                        _(u'address [password]'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   663
                        _(u'update the password for the given address')),
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   664
    'userquota': cmd('userquota', 'uq', user_quota,
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   665
                     _(u'address storage [messages]'),
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   666
                     _(u'update the quota limit for the given address')),
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   667
    'userservices': cmd('userservices', 'us', user_services,
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   668
                        _(u'address [service ...]'),
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   669
                        _(u'enables the specified services and disables all '
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   670
                          u'not specified services')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   671
    'usertransport': cmd('usertransport', 'ut', user_transport,
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   672
                         _(u'address transport'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   673
                         _(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
   674
    # Alias commands
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   675
    'aliasadd': cmd('aliasadd', 'aa', alias_add, _(u'address destination ...'),
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   676
                    _(u'create a new alias e-mail address with one or more '
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   677
                      u'destinations')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   678
    'aliasdelete': cmd('aliasdelete', 'ad', alias_delete,
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   679
                       _(u'address [destination]'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   680
                       _(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
   681
                         u'of its destinations')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   682
    'aliasinfo': cmd('aliasinfo', 'ai', alias_info, _(u'address'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   683
                     _(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
   684
    # AliasDomain commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   685
    'aliasdomainadd': cmd('aliasdomainadd', 'ada', aliasdomain_add,
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   686
                          _(u'fqdn destination'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   687
                          _(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
   688
    'aliasdomaindelete': cmd('aliasdomaindelete', 'add', aliasdomain_delete,
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   689
                             _(u'fqdn'),
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   690
                             _(u'delete the specified alias domain')),
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   691
    'aliasdomaininfo': cmd('aliasdomaininfo', 'adi', aliasdomain_info,
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   692
                         _(u'fqdn'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   693
                         _(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
   694
    'aliasdomainswitch': cmd('aliasdomainswitch', 'ads', aliasdomain_switch,
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   695
                       _(u'fqdn destination'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   696
                       _(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
   697
    # Domain commands
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   698
    'domainadd': cmd('domainadd', 'da', domain_add, _(u'fqdn [transport]'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   699
                     _(u'create a new domain')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   700
    'domaindelete': cmd('domaindelete', 'dd', domain_delete,
418
542a4d23a9f0 VMM/cli/subcommands: The keyword 'force' is no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 417
diff changeset
   701
                      _(u'fqdn') + ' [force]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   702
                      _(u'delete the given domain and all its alias domains')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   703
    'domaininfo': cmd('domaininfo', 'di', domain_info, _(u'fqdn [details]'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   704
                      _(u'display information about the given domain')),
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   705
    'domainquota': cmd('domainquota', 'dq', domain_quota,
418
542a4d23a9f0 VMM/cli/subcommands: The keyword 'force' is no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 417
diff changeset
   706
                       _(u'fqdn storage [messages]') + ' [force]',
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   707
                       _(u'update the quota limit of the specified domain')),
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   708
    'domainservices': cmd('domainservices', 'ds', domain_services,
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   709
                          _(u'fqdn [service ...]') + ' [force]',
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   710
                        _(u'enables the specified services and disables all '
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   711
                          u'not specified services of the given domain')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   712
    'domaintransport': cmd('domaintransport', 'dt', domain_transport,
418
542a4d23a9f0 VMM/cli/subcommands: The keyword 'force' is no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 417
diff changeset
   713
                           _(u'fqdn transport') + ' [force]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   714
                           _(u'update the transport of the specified domain')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   715
    'listdomains': cmd('listdomains', 'ld', list_domains, _(u'[pattern]'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   716
                       _(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
   717
    # Relocated commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   718
    'relocatedadd': cmd('relocatedadd', 'ra', relocated_add,
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   719
                        _(u'address newaddress'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   720
                        _(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
   721
    'relocateddelete': cmd('relocateddelete', 'rd', relocated_delete,
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   722
                           _(u'address'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   723
                           _(u'delete the record of the relocated user')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   724
    'relocatedinfo': cmd('relocatedinfo', 'ri', relocated_info, _('address'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   725
                         _(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
   726
    # cli commands
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   727
    'configget': cmd('configget', 'cg', config_get, _(u'option'),
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   728
                     _('show the actual value of the configuration option')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   729
    'configset': cmd('configset', 'cs', config_set, _('option value'),
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   730
                      _('set a new value for the configuration option')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   731
    'configure': cmd('configure', 'cf', configure, _(u'[section]'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   732
                     _(u'start interactive configuration modus')),
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   733
    'help': cmd('help', 'h', help_, _(u'[subcommand]'),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   734
                _(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
   735
    'version': cmd('version', 'v', version, '',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   736
                   _(u'show version and copyright information')),
420
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   737
    })
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   738
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   739
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   740
def _get_order(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   741
    """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
   742
    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
   743
    order = ()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   744
    if ctx.scmd == 'domaininfo':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   745
        order = ((u'domainname', 0), (u'gid', 1), (u'transport', 0),
398
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   746
                 (u'domaindir', 0), (u'quota limit', 0), (u'aliasdomains', 0),
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   747
                 (u'accounts', 0), (u'aliases', 0), (u'relocated', 0))
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   748
    elif ctx.scmd == 'userinfo':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   749
        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
   750
        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
   751
        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
   752
           ctx.cget('account.disk_usage'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   753
            order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1),
398
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   754
                     (u'home', 0), (u'mail_location', 0),
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   755
                     (u'quota storage', 0), (u'quota messages', 0),
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   756
                     (u'disk usage', 0), (u'transport', 0), (u'smtp', 1),
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   757
                     (u'pop3', 1), (u'imap', 1), (sieve, 1))
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   758
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   759
            order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1),
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   760
                     (u'home', 0), (u'mail_location', 0),
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   761
                     (u'quota storage', 0), (u'quota messages', 0),
398
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   762
                     (u'transport', 0), (u'smtp', 1), (u'pop3', 1),
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   763
                     (u'imap', 1), (sieve, 1))
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   764
    elif ctx.scmd == 'getuser':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   765
        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
   766
    return order
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   767
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   768
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   769
def _format_quota_usage(limit, used, human=False):
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   770
    """Put quota's limit / usage / percentage in a formatted string."""
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   771
    if human:
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   772
        q_usage = {
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   773
            'used': human_size(used),
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   774
            'limit': human_size(limit),
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   775
        }
398
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   776
    else:
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   777
        q_usage = {
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   778
            'used': locale.format('%d', used, True),
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   779
            'limit': locale.format('%d', limit, True),
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   780
        }
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   781
    if limit:
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   782
        q_usage['percent'] = locale.format('%6.2f', 100. / limit * used, True)
398
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   783
    else:
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   784
        q_usage['percent'] = locale.format('%6.2f', 0, True)
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   785
    return _(u'[%(percent)s%%] %(used)s/%(limit)s') % q_usage
398
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   786
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   787
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   788
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
   789
    """Print info dicts."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   790
    # 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
   791
    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
   792
    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
   793
    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
   794
        if upper:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   795
            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
   796
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   797
            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
   798
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   799
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   800
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   801
def _print_list(alist, title):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   802
    """Print a list."""
429
9842650569c2 Messages: Replaced some 'Available' by 'Existing'.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 423
diff changeset
   803
    # TP: used in e.g. 'Existing alias addresses' or 'Existing accounts'
9842650569c2 Messages: Replaced some 'Available' by 'Existing'.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 423
diff changeset
   804
    msg = u'%s %s' % (_(u'Existing'), title)
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   805
    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
   806
    if alist:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   807
        if title != _(u'alias domains'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   808
            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
   809
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   810
            for domain in alist:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   811
                if not domain.startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   812
                    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
   813
                else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   814
                    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
   815
        print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   816
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   817
        w_std(_(u'\tNone'), '')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   818
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   819
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   820
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
   821
    """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
   822
    title = _(u'Alias information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   823
    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
   824
    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
   825
    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
   826
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   827
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   828
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   829
def _print_relocated_info(**kwargs):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   830
    """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
   831
    title = _(u'Relocated information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   832
    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
   833
    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
   834
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   835
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   836
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
   837
    """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
   838
    if domain.startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   839
        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
   840
    if main:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   841
        return u'\t[+] %s' % domain
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   842
    return u'\t[-]     %s' % domain
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   843
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   844
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   845
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
   846
    """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
   847
    if matching:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   848
        title = _(u'Matching domains')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   849
    else:
429
9842650569c2 Messages: Replaced some 'Available' by 'Existing'.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 423
diff changeset
   850
        title = _(u'Existing domains')
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   851
    w_std(title, '-' * len(title))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   852
    if domains:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   853
        for did in dids:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   854
            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
   855
                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
   856
            if len(domains[did]) > 1:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   857
                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
   858
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   859
        w_std(_('\tNone'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   860
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   861
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   862
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   863
def _print_aliasdomain_info(info):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   864
    """Print alias domain information."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   865
    title = _(u'Alias domain information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   866
    for key in ('alias', 'domain'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   867
        if info[key].startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   868
            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
   869
    w_std(title, '-' * len(title),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   870
          _('\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
   871
          info, '')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   872
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   873
del _