VirtualMailManager/cli/subcommands.py
author martin f. krafft <madduck@madduck.net>
Tue, 10 Apr 2012 22:56:30 +0200
branchv0.6.x
changeset 514 d863a44a6353
parent 510 1fa354bbdb90
child 515 09fa019bb330
permissions -rw-r--r--
Make PL/pgSQL function feed back identity for mailboxes/relocated when there are catchall destinations. Without catchall aliases, if no virtual_alias matches, the query can just return NULL and Postfix will later check mailboxes/relocated for the address to rewrite. However, since virtual aliases are handled long before mailboxes/relocated, a catchall alias would also catch mail to mailboxes and relocated addresses, which we do not want. The way to tell postfix to keep delivering is for the virtual alias map to return the search key itself (identity function). This patch changes the postfix_virtual_alias_maps Pl/pgSQL function to do exactly that, but only if there are catchall destinations defined for the domain in question — otherwise it returns NULL when no match is found.
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
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
    24
from VirtualMailManager.password import list_schemes
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
    25
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
    26
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    27
__all__ = (
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    28
    '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
    29
    'alias_info', 'aliasdomain_add', 'aliasdomain_delete', 'aliasdomain_info',
506
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
    30
    'aliasdomain_switch', 'catchall_add', 'catchall_info', 'catchall_delete',
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
    31
    '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
    32
    '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
    33
    'domain_services', 'domain_transport', 'get_user', 'help_', 'list_domains',
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
    34
    'list_pwschemes', 'relocated_add', 'relocated_delete', 'relocated_info',
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
    35
    'user_add', 'user_delete', 'user_info', 'user_name', 'user_password',
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
    36
    'user_quota', '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
    37
)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    38
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    39
_ = lambda msg: msg
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    40
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
    41
cmd_map = {}
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    42
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    43
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    44
class Command(object):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    45
    """Container class for command information."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    46
    __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
    47
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    48
    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
    49
        """Create a new Command instance.
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
        Arguments:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    52
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    53
        `name` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    54
          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
    55
        `alias` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    56
          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
    57
        `func` : callable
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    58
          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
    59
        `args` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    60
          argument placeholders, e.g. ``aliasaddress``
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    61
        `descr` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    62
          short description of the command
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    63
        """
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    64
        self.name = name
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    65
        self.alias = alias
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    66
        self.func = func
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    67
        self.args = args
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    68
        self.descr = descr
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    69
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    70
    @property
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    71
    def usage(self):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    72
        """the command's usage info."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    73
        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
    74
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    75
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    76
class RunContext(object):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    77
    """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
    78
    __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
    79
    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
    80
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    81
    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
    82
        """Create a new RunContext"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    83
        self.argc = len(argv)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    84
        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
    85
        self.cget = handler.cfg_dget
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    86
        self.hdlr = handler
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    87
        self.scmd = command
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    88
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    89
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    90
def alias_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    91
    """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
    92
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    93
        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
    94
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    95
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    96
        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
    97
    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
    98
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    99
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   100
def alias_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   101
    """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
   102
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   103
        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
   104
    elif ctx.argc < 4:
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())
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   106
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   107
        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
   108
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   109
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   110
def alias_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   111
    """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
   112
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   113
        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
   114
    address = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   115
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   116
        _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
   117
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   118
        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
   119
            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
   120
                  'object': address})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   121
            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
   122
            user_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   123
        elif err.code is RELOCATED_EXISTS:
455
b15960e9c53c VMM/cli/subcommands: Fixed a small failure in alias_info().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 448
diff changeset
   124
            w_err(0, ctx.plan_a_b % {'subcommand': u'relocatedinfo',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   125
                  'object': address})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   126
            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
   127
            relocated_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   128
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   129
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   130
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   131
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   132
def aliasdomain_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   133
    """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
   134
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   135
        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
   136
                                 u'domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   137
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   138
        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
   139
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   140
    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
   141
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   142
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   143
def aliasdomain_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   144
    """delete the specified alias domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   145
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   146
        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
   147
    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
   148
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   149
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   150
def aliasdomain_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   151
    """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
   152
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   153
        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
   154
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   155
        _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
   156
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   157
        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
   158
            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
   159
                  '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
   160
            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
   161
            domain_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   162
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   163
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   164
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   165
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   166
def aliasdomain_switch(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   167
    """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
   168
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   169
        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
   170
                                 u'domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   171
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   172
        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
   173
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   174
    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
   175
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   176
506
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   177
def catchall_add(ctx):
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   178
    """create a new catchall alias e-mail address"""
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   179
    if ctx.argc < 3:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   180
        usage(EX_MISSING_ARGS, _(u'Missing domain and destination.'),
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   181
              ctx.scmd)
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   182
    elif ctx.argc < 4:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   183
        usage(EX_MISSING_ARGS, _(u'Missing destination address.'), ctx.scmd)
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   184
    ctx.hdlr.catchall_add(ctx.args[2].lower(), *ctx.args[3:])
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   185
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   186
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   187
def catchall_delete(ctx):
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   188
    """delete the specified destination or all of the catchall destination"""
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   189
    if ctx.argc < 3:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   190
        usage(EX_MISSING_ARGS, _(u'Missing domain.'), ctx.scmd)
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   191
    elif ctx.argc < 4:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   192
        ctx.hdlr.catchall_delete(ctx.args[2].lower())
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   193
    else:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   194
        ctx.hdlr.catchall_delete(ctx.args[2].lower(), ctx.args[3])
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   195
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   196
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   197
def catchall_info(ctx):
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   198
    """show the catchall destination(s) of the specified domain"""
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   199
    if ctx.argc < 3:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   200
        usage(EX_MISSING_ARGS, _(u'Missing domain.'), ctx.scmd)
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   201
    address = ctx.args[2].lower()
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   202
    _print_catchall_info(address, ctx.hdlr.catchall_info(address))
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   203
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   204
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   205
def config_get(ctx):
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   206
    """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
   207
    if ctx.argc < 3:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   208
        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
   209
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   210
    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
   211
    opt_formater = {
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   212
        'misc.dovecot_version': version_str,
458
4ff0fa3ba0fa VMM/config: Moved some options to section `domain':
Pascal Volk <neverseen@users.sourceforge.net>
parents: 456
diff changeset
   213
        'domain.quota_bytes': human_size,
397
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   214
    }
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   215
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   216
    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
   217
    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
   218
                       noop)(ctx.cget(option))))
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   219
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   220
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   221
def config_set(ctx):
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   222
    """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
   223
    if ctx.argc < 3:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   224
        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
   225
    if ctx.argc < 4:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   226
        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
   227
              ctx.scmd)
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   228
    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
   229
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   230
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   231
def configure(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   232
    """start interactive configuration modus"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   233
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   234
        ctx.hdlr.configure()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   235
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   236
        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
   237
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   238
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   239
def domain_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   240
    """create a new domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   241
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   242
        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
   243
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   244
        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
   245
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   246
        ctx.hdlr.domain_add(ctx.args[2].lower(), ctx.args[3])
456
7847f949d0a2 VMM/cli/subcommands: Small improvement in domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 455
diff changeset
   247
    if ctx.cget('domain.auto_postmaster'):
7847f949d0a2 VMM/cli/subcommands: Small improvement in domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 455
diff changeset
   248
        w_std(_(u'Creating account for postmaster@%s') % ctx.args[2].lower())
7847f949d0a2 VMM/cli/subcommands: Small improvement in domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 455
diff changeset
   249
        ctx.scmd = 'useradd'
7847f949d0a2 VMM/cli/subcommands: Small improvement in domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 455
diff changeset
   250
        ctx.args = [prog, ctx.scmd, u'postmaster@' + ctx.args[2].lower()]
7847f949d0a2 VMM/cli/subcommands: Small improvement in domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 455
diff changeset
   251
        ctx.argc = 3
7847f949d0a2 VMM/cli/subcommands: Small improvement in domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 455
diff changeset
   252
        user_add(ctx)
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   253
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   254
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   255
def domain_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   256
    """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
   257
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   258
        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
   259
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   260
        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
   261
    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
   262
        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
   263
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   264
        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
   265
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   266
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   267
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   268
def domain_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   269
    """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
   270
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   271
        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
   272
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   273
        details = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   274
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   275
        details = ctx.args[3].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   276
        if details not in ('accounts', 'aliasdomains', 'aliases', 'full',
510
1fa354bbdb90 Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents: 506
diff changeset
   277
                           'relocated', 'catchall'):
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   278
            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
   279
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   280
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   281
        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
   282
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   283
        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
   284
            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
   285
                  '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
   286
            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
   287
            aliasdomain_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   288
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   289
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   290
    else:
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   291
        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
   292
        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
   293
            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
   294
            info['messages'] = locale.format('%d', info['messages'], True)
474
4353981e3a7f VMM/cli/subcommands: Small improvement of domaininfo's output.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 471
diff changeset
   295
            info['quota limit/user'] = q_limit % info
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   296
            _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
   297
        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
   298
            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
   299
            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
   300
                                                True)
474
4353981e3a7f VMM/cli/subcommands: Small improvement of domaininfo's output.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 471
diff changeset
   301
            info[0]['quota limit/user'] = q_limit % info[0]
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   302
            _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
   303
            if details == u'accounts':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   304
                _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
   305
            elif details == u'aliasdomains':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   306
                _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
   307
            elif details == u'aliases':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   308
                _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
   309
            elif details == u'relocated':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   310
                _print_list(info[1], _(u'relocated users'))
510
1fa354bbdb90 Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents: 506
diff changeset
   311
            elif details == u'catchall':
1fa354bbdb90 Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents: 506
diff changeset
   312
                _print_list(info[1], _(u'catch-all destinations'))
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   313
            else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   314
                _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
   315
                _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
   316
                _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
   317
                _print_list(info[4], _(u'relocated users'))
510
1fa354bbdb90 Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents: 506
diff changeset
   318
                _print_list(info[5], _(u'catch-all destinations'))
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   319
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   320
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   321
def domain_quota(ctx):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   322
    """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
   323
    if ctx.argc < 3:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   324
        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
   325
              ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   326
    if ctx.argc < 4:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   327
        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
   328
    messages = 0
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   329
    force = None
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   330
    try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   331
        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
   332
    except (ValueError, TypeError):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   333
        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
   334
              ctx.args[3], ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   335
    if ctx.argc < 5:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   336
        pass
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   337
    elif ctx.argc < 6:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   338
        try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   339
            messages = int(ctx.args[4])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   340
        except ValueError:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   341
            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
   342
                usage(INVALID_ARGUMENT,
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   343
                      _(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
   344
                        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
   345
            force = 'force'
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   346
    else:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   347
        try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   348
            messages = int(ctx.args[4])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   349
        except ValueError:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   350
            usage(INVALID_ARGUMENT,
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   351
                  _(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
   352
                  ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   353
        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
   354
            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
   355
                  ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   356
        force = 'force'
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   357
    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
   358
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   359
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   360
def domain_services(ctx):
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   361
    """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
   362
    if ctx.argc < 3:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   363
        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
   364
    services = []
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   365
    force = False
448
45c917e6a386 VMM/cli/subcommands: domainservices: Don't fail when neither a
Pascal Volk <neverseen@users.sourceforge.net>
parents: 447
diff changeset
   366
    if ctx.argc is 3:
45c917e6a386 VMM/cli/subcommands: domainservices: Don't fail when neither a
Pascal Volk <neverseen@users.sourceforge.net>
parents: 447
diff changeset
   367
        pass
45c917e6a386 VMM/cli/subcommands: domainservices: Don't fail when neither a
Pascal Volk <neverseen@users.sourceforge.net>
parents: 447
diff changeset
   368
    elif ctx.argc is 4:
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   369
        arg = ctx.args[3].lower()
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   370
        if arg in SERVICES:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   371
            services.append(arg)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   372
        elif arg == 'force':
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   373
            force = True
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   374
        else:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   375
            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
   376
                  ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   377
    else:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   378
        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
   379
        arg = ctx.args[-1].lower()
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   380
        if arg == 'force':
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   381
            force = True
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   382
        else:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   383
            services.append(arg)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   384
        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
   385
        if unknown:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   386
            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
   387
                  ' '.join(unknown), ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   388
    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
   389
                             *services)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   390
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   391
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   392
def domain_transport(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   393
    """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
   394
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   395
        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
   396
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   397
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   398
        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
   399
    if ctx.argc < 5:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   400
        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
   401
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   402
        force = ctx.args[4].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   403
        if force != 'force':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   404
            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
   405
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   406
        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
   407
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   408
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   409
def get_user(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   410
    """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
   411
    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
   412
        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
   413
    _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
   414
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   415
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   416
def help_(ctx):
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   417
    """print help messages."""
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   418
    if ctx.argc > 2:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   419
        hlptpc = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   420
        if hlptpc in cmd_map:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   421
            topic = hlptpc
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   422
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   423
            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
   424
                if scmd.alias == hlptpc:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   425
                    topic = scmd.name
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   426
                    break
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   427
            else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   428
                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
   429
                      ctx.args[2], ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   430
        # FIXME
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   431
        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
   432
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   433
    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
   434
    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
   435
    txt_wrpr.initial_indent = ' '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   436
    # 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
   437
    txt_wrpr.subsequent_indent = 20 * ' '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   438
    order = cmd_map.keys()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   439
    order.sort()
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
    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
   442
    for key in order:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   443
        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
   444
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   445
    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
   446
    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
   447
    txt_wrpr.initial_indent = ''
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   448
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   449
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   450
def list_domains(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   451
    """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
   452
    matching = ctx.argc > 2
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   453
    if matching:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   454
        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
   455
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   456
        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
   457
    _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
   458
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   459
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   460
def list_pwschemes(ctx_unused):
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   461
    """Prints all usable password schemes and password encoding suffixes."""
471
5d0114f7bb99 VMM/cli/subcommands: Use the common output formatting in list_pwschemes().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 469
diff changeset
   462
    # TODO: Remove trailing colons from keys.
5d0114f7bb99 VMM/cli/subcommands: Use the common output formatting in list_pwschemes().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 469
diff changeset
   463
    # For now it is to late, the translators has stared their work
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   464
    keys = (_(u'Usable password schemes:'), _(u'Usable encoding suffixes:'))
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   465
    old_ii, old_si = txt_wrpr.initial_indent, txt_wrpr.subsequent_indent
471
5d0114f7bb99 VMM/cli/subcommands: Use the common output formatting in list_pwschemes().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 469
diff changeset
   466
    txt_wrpr.initial_indent = txt_wrpr.subsequent_indent = '\t'
5d0114f7bb99 VMM/cli/subcommands: Use the common output formatting in list_pwschemes().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 469
diff changeset
   467
    txt_wrpr.width = txt_wrpr.width - 8
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   468
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   469
    for key, value in zip(keys, list_schemes()):
471
5d0114f7bb99 VMM/cli/subcommands: Use the common output formatting in list_pwschemes().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 469
diff changeset
   470
        if key.endswith(':'):  # who knows … (see TODO above)
481
90d69ae4f40d VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 474
diff changeset
   471
            #key = key.rpartition(':')[0]
90d69ae4f40d VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 474
diff changeset
   472
            key = key[:-1]  # This one is for Py24
471
5d0114f7bb99 VMM/cli/subcommands: Use the common output formatting in list_pwschemes().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 469
diff changeset
   473
        w_std(key, len(key) * '-')
5d0114f7bb99 VMM/cli/subcommands: Use the common output formatting in list_pwschemes().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 469
diff changeset
   474
        w_std('\n'.join(txt_wrpr.wrap(' '.join(value))), '')
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   475
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   476
    txt_wrpr.initial_indent, txt_wrpr.subsequent_indent = old_ii, old_si
471
5d0114f7bb99 VMM/cli/subcommands: Use the common output formatting in list_pwschemes().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 469
diff changeset
   477
    txt_wrpr.width = txt_wrpr.width + 8
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   478
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   479
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   480
def relocated_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   481
    """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
   482
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   483
        usage(EX_MISSING_ARGS,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   484
              _(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
   485
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   486
        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
   487
    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
   488
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
def relocated_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   491
    """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
   492
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   493
        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
   494
    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
   495
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   496
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   497
def relocated_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   498
    """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
   499
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   500
        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
   501
    relocated = ctx.args[2].lower()
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
        _print_relocated_info(addr=relocated,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   504
                              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
   505
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   506
        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
   507
            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
   508
                  'object': relocated})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   509
            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
   510
            user_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   511
        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
   512
            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
   513
                  'object': relocated})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   514
            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
   515
            alias_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   516
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   517
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   518
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   519
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   520
def user_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   521
    """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
   522
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   523
        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
   524
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   525
        password = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   526
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   527
        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
   528
    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
   529
    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
   530
        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
   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_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   534
    """delete the specified user"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   535
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   536
        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
   537
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   538
        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
   539
    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
   540
        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
   541
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   542
        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
   543
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   544
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   545
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   546
def user_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   547
    """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
   548
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   549
        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
   550
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   551
        details = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   552
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   553
        details = ctx.args[3].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   554
        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
   555
            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
   556
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   557
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   558
        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
   559
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   560
        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
   561
            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
   562
                  '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
   563
            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
   564
            alias_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   565
        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
   566
            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
   567
                  '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
   568
            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
   569
            relocated_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   570
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   571
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   572
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   573
        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
   574
            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
   575
                    info['uq_bytes'], True)
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   576
            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
   577
                    info['uq_messages'])
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   578
            _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
   579
        else:
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   580
            info[0]['quota storage'] = _format_quota_usage(info[0]['ql_bytes'],
487
fb0af82ab4af VMM/cli/subcommands: Fixed a TypeError in user_info().
Pascal Volk <user@localhost.localdomain.org>
parents: 481
diff changeset
   581
                    info[0]['uq_bytes'], True)
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   582
            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
   583
                    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
   584
            _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
   585
            _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
   586
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   587
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   588
def user_name(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   589
    """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
   590
    if ctx.argc < 3:
341
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 340
diff changeset
   591
        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
   592
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   593
    if ctx.argc < 4:
341
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 340
diff changeset
   594
        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
   595
    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
   596
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   597
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   598
def user_password(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   599
    """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
   600
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   601
        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
   602
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   603
        password = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   604
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   605
        password = ctx.args[3]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   606
    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
   607
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   608
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   609
def user_quota(ctx):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   610
    """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
   611
    if ctx.argc < 3:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   612
        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
   613
              ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   614
    elif ctx.argc < 4:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   615
        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
   616
    try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   617
        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
   618
    except (ValueError, TypeError):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   619
        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
   620
              ctx.args[3], ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   621
    if ctx.argc < 5:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   622
        messages = 0
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   623
    else:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   624
        try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   625
            messages = int(ctx.args[4])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   626
        except ValueError:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   627
            usage(INVALID_ARGUMENT,
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   628
                  _(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
   629
                  ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   630
    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
   631
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   632
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   633
def user_services(ctx):
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   634
    """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
   635
    if ctx.argc < 3:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   636
        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
   637
    services = []
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   638
    if ctx.argc >= 4:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   639
        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
   640
        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
   641
        if unknown:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   642
            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
   643
                  ' '.join(unknown), ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   644
    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
   645
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   646
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   647
def user_transport(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   648
    """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
   649
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   650
        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
   651
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   652
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   653
        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
   654
    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
   655
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   656
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   657
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
   658
    """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
   659
    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
   660
    """
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   661
    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
   662
        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
   663
              _(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
   664
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   665
    # 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
   666
    # (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
   667
    # usage: vmm subcommand arguments
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   668
    #   short long
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   669
    #   subcommand                arguments
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   670
    #
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   671
    #   da    domainadd           fqdn [transport]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   672
    #   dd    domaindelete        fqdn [force]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   673
    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
   674
  short long
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   675
  subcommand                arguments\n""") % prog
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   676
    order = cmd_map.keys()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   677
    order.sort()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   678
    w_err(0, u_head)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   679
    for key in order:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   680
        scmd = cmd_map[key]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   681
        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
   682
    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
   683
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   684
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   685
def version(ctx_unused):
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   686
    """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
   687
    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
   688
    # 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
   689
    # the version information, e.g.:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   690
    # 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
   691
    # 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
   692
        _(u'version'), __version__, _(u'from'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   693
        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
   694
            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
   695
        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
   696
        __copyright__, prog,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   697
        _(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
   698
420
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   699
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   700
def update_cmd_map():
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   701
    """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
   702
    cmd = Command
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   703
    cmd_map.update({
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   704
    # Account commands
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   705
    'getuser': cmd('getuser', 'gu', get_user, 'uid',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   706
                   _(u'get the address of the user with the given UID')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   707
    'useradd': cmd('useradd', 'ua', user_add, 'address [password]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   708
                   _(u'create a new e-mail user with the given address')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   709
    'userdelete': cmd('userdelete', 'ud', user_delete, 'address [force]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   710
                      _(u'delete the specified user')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   711
    'userinfo': cmd('userinfo', 'ui', user_info, 'address [details]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   712
                    _(u'display information about the given address')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   713
    'username': cmd('username', 'un', user_name, 'address name',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   714
                    _(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
   715
    'userpassword': cmd('userpassword', 'up', user_password,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   716
                        'address [password]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   717
                        _(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
   718
    'userquota': cmd('userquota', 'uq', user_quota,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   719
                     'address storage [messages]',
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   720
                     _(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
   721
    'userservices': cmd('userservices', 'us', user_services,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   722
                        'address [service ...]',
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   723
                        _(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
   724
                          u'not specified services')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   725
    'usertransport': cmd('usertransport', 'ut', user_transport,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   726
                         'address transport',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   727
                         _(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
   728
    # Alias commands
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   729
    'aliasadd': cmd('aliasadd', 'aa', alias_add, 'address destination ...',
406
58e23bd7c97f VMM/cli/subcommands: Made argument names translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 403
diff changeset
   730
                    _(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
   731
                      u'destinations')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   732
    'aliasdelete': cmd('aliasdelete', 'ad', alias_delete,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   733
                       'address [destination]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   734
                       _(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
   735
                         u'of its destinations')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   736
    'aliasinfo': cmd('aliasinfo', 'ai', alias_info, 'address',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   737
                     _(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
   738
    # AliasDomain commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   739
    'aliasdomainadd': cmd('aliasdomainadd', 'ada', aliasdomain_add,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   740
                          'fqdn destination',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   741
                          _(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
   742
    'aliasdomaindelete': cmd('aliasdomaindelete', 'add', aliasdomain_delete,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   743
                             'fqdn', _(u'delete the specified alias domain')),
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   744
    'aliasdomaininfo': cmd('aliasdomaininfo', 'adi', aliasdomain_info, 'fqdn',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   745
                         _(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
   746
    'aliasdomainswitch': cmd('aliasdomainswitch', 'ads', aliasdomain_switch,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   747
                             'fqdn destination', _(u'assign the given alias '
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   748
                             'domain to an other domain')),
506
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   749
    # CatchallAlias commands
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   750
    'catchalladd': cmd('catchalladd', 'caa', catchall_add,
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   751
                       'domain destination ...',
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   752
                       _(u'add one or more catch-all destinations for a '
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   753
                         u'domain')),
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   754
    'catchalldelete': cmd('catchalldelete', 'cad', catchall_delete,
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   755
                       'domain [destination]',
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   756
                       _(u'delete the specified catch-all destination or all '
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   757
                         u'of a domain\'s destinations')),
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   758
    'catchallinfo': cmd('catchallinfo', 'cai', catchall_info, 'domain',
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   759
                     _(u'show the catch-all destination(s) of the specified domain')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   760
    # Domain commands
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   761
    'domainadd': cmd('domainadd', 'da', domain_add, 'fqdn [transport]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   762
                     _(u'create a new domain')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   763
    'domaindelete': cmd('domaindelete', 'dd', domain_delete, 'fqdn [force]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   764
                      _(u'delete the given domain and all its alias domains')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   765
    'domaininfo': cmd('domaininfo', 'di', domain_info, 'fqdn [details]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   766
                      _(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
   767
    'domainquota': cmd('domainquota', 'dq', domain_quota,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   768
                       'fqdn storage [messages] [force]',
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   769
                       _(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
   770
    'domainservices': cmd('domainservices', 'ds', domain_services,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   771
                          'fqdn [service ...] [force]',
446
18b75e6a39d5 VMM/cli/subcommands: Small indent fix.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 445
diff changeset
   772
                          _(u'enables the specified services and disables all '
18b75e6a39d5 VMM/cli/subcommands: Small indent fix.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 445
diff changeset
   773
                            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
   774
    'domaintransport': cmd('domaintransport', 'dt', domain_transport,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   775
                           'fqdn transport [force]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   776
                           _(u'update the transport of the specified domain')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   777
    'listdomains': cmd('listdomains', 'ld', list_domains, '[pattern]',
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   778
                      _(u'list all domains or search for domains by pattern')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   779
    # Relocated commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   780
    'relocatedadd': cmd('relocatedadd', 'ra', relocated_add,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   781
                        'address newaddress',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   782
                        _(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
   783
    'relocateddelete': cmd('relocateddelete', 'rd', relocated_delete,
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   784
                           'address',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   785
                           _(u'delete the record of the relocated user')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   786
    '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
   787
                         _(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
   788
    # cli commands
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   789
    'configget': cmd('configget', 'cg', config_get, 'option',
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   790
                     _('show the actual value of the configuration option')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   791
    '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
   792
                      _('set a new value for the configuration option')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   793
    'configure': cmd('configure', 'cf', configure, '[section]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   794
                     _(u'start interactive configuration modus')),
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   795
    'listpwschemes': cmd('listpwschemes', 'lp', list_pwschemes, '',
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   796
                         _(u'lists all usable password schemes and password '
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   797
                           u'encoding suffixes')),
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   798
    'help': cmd('help', 'h', help_, '[subcommand]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   799
                _(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
   800
    'version': cmd('version', 'v', version, '',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   801
                   _(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
   802
    })
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   803
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   804
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   805
def _get_order(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   806
    """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
   807
    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
   808
    order = ()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   809
    if ctx.scmd == 'domaininfo':
447
c31d604e26d3 VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 446
diff changeset
   810
        order = ((u'domain name', 0), (u'gid', 1), (u'domain directory', 0),
474
4353981e3a7f VMM/cli/subcommands: Small improvement of domaininfo's output.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 471
diff changeset
   811
                 (u'quota limit/user', 0), (u'active services', 0),
447
c31d604e26d3 VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 446
diff changeset
   812
                 (u'transport', 0), (u'alias domains', 0), (u'accounts', 0),
c31d604e26d3 VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 446
diff changeset
   813
                 (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
   814
    elif ctx.scmd == 'userinfo':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   815
        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
   816
           ctx.cget('account.disk_usage'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   817
            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
   818
                     (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
   819
                     (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
   820
                     (u'disk usage', 0), (u'transport', 0), (u'smtp', 1),
447
c31d604e26d3 VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 446
diff changeset
   821
                     (u'pop3', 1), (u'imap', 1), (u'sieve', 1))
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   822
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   823
            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
   824
                     (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
   825
                     (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
   826
                     (u'transport', 0), (u'smtp', 1), (u'pop3', 1),
447
c31d604e26d3 VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 446
diff changeset
   827
                     (u'imap', 1), (u'sieve', 1))
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   828
    elif ctx.scmd == 'getuser':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   829
        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
   830
    return order
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   831
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   832
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   833
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
   834
    """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
   835
    if human:
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   836
        q_usage = {
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   837
            'used': human_size(used),
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   838
            'limit': human_size(limit),
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   839
        }
398
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   840
    else:
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   841
        q_usage = {
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   842
            '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
   843
            '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
   844
        }
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   845
    if limit:
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   846
        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
   847
    else:
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   848
        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
   849
    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
   850
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   851
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   852
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
   853
    """Print info dicts."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   854
    # 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
   855
    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
   856
    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
   857
    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
   858
        if upper:
447
c31d604e26d3 VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 446
diff changeset
   859
            w_std(u'\t%s: %s' % (key.upper().ljust(17, u'.'), info[key]))
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   860
        else:
447
c31d604e26d3 VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 446
diff changeset
   861
            w_std(u'\t%s: %s' % (key.title().ljust(17, u'.'), info[key]))
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   862
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   863
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   864
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   865
def _print_list(alist, title):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   866
    """Print a list."""
429
9842650569c2 Messages: Replaced some 'Available' by 'Existing'.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 423
diff changeset
   867
    # 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
   868
    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
   869
    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
   870
    if alist:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   871
        if title != _(u'alias domains'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   872
            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
   873
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   874
            for domain in alist:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   875
                if not domain.startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   876
                    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
   877
                else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   878
                    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
   879
        print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   880
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   881
        w_std(_(u'\tNone'), '')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   882
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   883
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   884
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
   885
    """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
   886
    title = _(u'Alias information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   887
    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
   888
    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
   889
    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
   890
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   891
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   892
506
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   893
def _print_catchall_info(domain, destinations):
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   894
    """Print the catchall destinations of a domain"""
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   895
    title = _(u'Catch-all information')
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   896
    w_std(title, u'-' * len(title))
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   897
    w_std(_(u'\tMail to unknown localparts in domain %s will be sent to:')
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   898
          % domain)
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   899
    w_std(*(u'\t     * %s' % dest for dest in destinations))
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   900
    print
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   901
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   902
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   903
def _print_relocated_info(**kwargs):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   904
    """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
   905
    title = _(u'Relocated information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   906
    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
   907
    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
   908
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   909
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   910
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
   911
    """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
   912
    if domain.startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   913
        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
   914
    if main:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   915
        return u'\t[+] %s' % domain
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   916
    return u'\t[-]     %s' % domain
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   917
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   918
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   919
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
   920
    """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
   921
    if matching:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   922
        title = _(u'Matching domains')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   923
    else:
429
9842650569c2 Messages: Replaced some 'Available' by 'Existing'.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 423
diff changeset
   924
        title = _(u'Existing domains')
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   925
    w_std(title, '-' * len(title))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   926
    if domains:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   927
        for did in dids:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   928
            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
   929
                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
   930
            if len(domains[did]) > 1:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   931
                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
   932
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   933
        w_std(_('\tNone'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   934
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   935
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   936
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   937
def _print_aliasdomain_info(info):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   938
    """Print alias domain information."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   939
    title = _(u'Alias domain information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   940
    for key in ('alias', 'domain'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   941
        if info[key].startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   942
            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
   943
    w_std(title, '-' * len(title),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   944
          _('\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
   945
          info, '')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   946
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   947
del _