VirtualMailManager/cli/subcommands.py
author Pascal Volk <user@localhost.localdomain.org>
Sun, 02 Sep 2012 15:24:41 +0000
changeset 602 af88f01e5bfa
parent 601 463b10c258d9
child 606 ab97727357a4
permissions -rw-r--r--
VMM/cli/subcommands: Corrected two usage strings. domainnote's and usernote's note argument is optional.
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 -*-
568
14abdd04ddf5 Updated copyright notices to include the year 2012.
Pascal Volk <user@localhost.localdomain.org>
parents: 565
diff changeset
     2
# Copyright (c) 2007 - 2012, 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
532
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
    19
from VirtualMailManager.common import human_size, size_in_bytes, \
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
    20
     version_str, format_domain_default
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    21
from VirtualMailManager.constants import __copyright__, __date__, \
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    22
     __version__, ACCOUNT_EXISTS, ALIAS_EXISTS, ALIASDOMAIN_ISDOMAIN, \
555
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
    23
     DOMAIN_ALIAS_EXISTS, INVALID_ARGUMENT, EX_MISSING_ARGS, \
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
    24
     RELOCATED_EXISTS, TYPE_ACCOUNT, TYPE_ALIAS, TYPE_RELOCATED
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    25
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
    26
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
    27
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
    28
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    29
__all__ = (
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    30
    '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
    31
    '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
    32
    'aliasdomain_switch', 'catchall_add', 'catchall_info', 'catchall_delete',
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
    33
    '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
    34
    'domain_add', 'domain_delete',  'domain_info', 'domain_quota',
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
    35
    'domain_services', 'domain_transport', 'domain_note', 'get_user', 'help_',
555
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
    36
    'list_domains', 'list_pwschemes', 'list_users', 'list_aliases',
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
    37
    'list_relocated', 'list_addresses', 'relocated_add', 'relocated_delete',
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
    38
    'relocated_info', 'user_add', 'user_delete', 'user_info', 'user_name',
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
    39
    'user_password', 'user_quota', 'user_services', 'user_transport',
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
    40
    'user_note', 'version',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    41
)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    42
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    43
_ = lambda msg: msg
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    44
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
    45
cmd_map = {}
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    46
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    47
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    48
class Command(object):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    49
    """Container class for command information."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    50
    __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
    51
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    52
    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
    53
        """Create a new Command instance.
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    54
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    55
        Arguments:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    56
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    57
        `name` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    58
          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
    59
        `alias` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    60
          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
    61
        `func` : callable
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    62
          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
    63
        `args` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    64
          argument placeholders, e.g. ``aliasaddress``
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    65
        `descr` : str
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    66
          short description of the command
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    67
        """
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    68
        self.name = name
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    69
        self.alias = alias
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    70
        self.func = func
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    71
        self.args = args
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    72
        self.descr = descr
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    73
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    74
    @property
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    75
    def usage(self):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    76
        """the command's usage info."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    77
        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
    78
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    79
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    80
class RunContext(object):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    81
    """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
    82
    __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
    83
    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
    84
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    85
    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
    86
        """Create a new RunContext"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    87
        self.argc = len(argv)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    88
        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
    89
        self.cget = handler.cfg_dget
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    90
        self.hdlr = handler
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    91
        self.scmd = command
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    92
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    93
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    94
def alias_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    95
    """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
    96
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    97
        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
    98
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    99
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   100
        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
   101
    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
   102
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   103
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   104
def alias_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   105
    """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
   106
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   107
        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
   108
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   109
        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
   110
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   111
        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
   112
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   113
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   114
def alias_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   115
    """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
   116
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   117
        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
   118
    address = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   119
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   120
        _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
   121
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   122
        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
   123
            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
   124
                  'object': address})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   125
            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
   126
            user_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   127
        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
   128
            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
   129
                  'object': address})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   130
            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
   131
            relocated_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   132
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   133
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   134
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   135
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   136
def aliasdomain_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   137
    """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
   138
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   139
        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
   140
                                 u'domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   141
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   142
        usage(EX_MISSING_ARGS, _(u'Missing destination domain name.'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   143
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   144
    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
   145
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   146
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   147
def aliasdomain_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   148
    """delete the specified alias domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   149
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   150
        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
   151
    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
   152
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   153
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   154
def aliasdomain_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   155
    """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
   156
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   157
        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
   158
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   159
        _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
   160
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   161
        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
   162
            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
   163
                  '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
   164
            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
   165
            domain_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   166
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   167
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   168
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   169
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   170
def aliasdomain_switch(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   171
    """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
   172
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   173
        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
   174
                                 u'domain name.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   175
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   176
        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
   177
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   178
    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
   179
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   180
506
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   181
def catchall_add(ctx):
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   182
    """create a new catchall alias e-mail address"""
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   183
    if ctx.argc < 3:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   184
        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
   185
              ctx.scmd)
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   186
    elif ctx.argc < 4:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   187
        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
   188
    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
   189
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   190
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   191
def catchall_delete(ctx):
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   192
    """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
   193
    if ctx.argc < 3:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   194
        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
   195
    elif ctx.argc < 4:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   196
        ctx.hdlr.catchall_delete(ctx.args[2].lower())
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   197
    else:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   198
        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
   199
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   200
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   201
def catchall_info(ctx):
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   202
    """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
   203
    if ctx.argc < 3:
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   204
        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
   205
    address = ctx.args[2].lower()
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   206
    _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
   207
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   208
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   209
def config_get(ctx):
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   210
    """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
   211
    if ctx.argc < 3:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   212
        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
   213
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   214
    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
   215
    opt_formater = {
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   216
        '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
   217
        '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
   218
    }
cf661a40266d VMM/cli/subcommands: config_get: Print configured misc.quota_bytes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 376
diff changeset
   219
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   220
    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
   221
    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
   222
                       noop)(ctx.cget(option))))
345
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   223
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   224
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   225
def config_set(ctx):
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   226
    """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
   227
    if ctx.argc < 3:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   228
        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
   229
    if ctx.argc < 4:
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   230
        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
   231
              ctx.scmd)
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   232
    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
   233
f8d5c8bb8bce VMM/cli/subcommands: Added subcommands configget and configset.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   234
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   235
def configure(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   236
    """start interactive configuration modus"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   237
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   238
        ctx.hdlr.configure()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   239
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   240
        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
   241
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   242
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   243
def domain_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   244
    """create a new domain"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   245
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   246
        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
   247
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   248
        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
   249
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   250
        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
   251
    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
   252
        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
   253
        ctx.scmd = 'useradd'
7847f949d0a2 VMM/cli/subcommands: Small improvement in domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 455
diff changeset
   254
        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
   255
        ctx.argc = 3
7847f949d0a2 VMM/cli/subcommands: Small improvement in domain_add().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 455
diff changeset
   256
        user_add(ctx)
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   257
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   258
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   259
def domain_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   260
    """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
   261
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   262
        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
   263
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   264
        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
   265
    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
   266
        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
   267
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   268
        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
   269
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   270
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   271
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   272
def domain_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   273
    """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
   274
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   275
        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
   276
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   277
        details = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   278
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   279
        details = ctx.args[3].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   280
        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
   281
                           'relocated', 'catchall'):
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   282
            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
   283
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   284
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   285
        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
   286
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   287
        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
   288
            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
   289
                  '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
   290
            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
   291
            aliasdomain_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   292
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   293
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   294
    else:
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   295
        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
   296
        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
   297
            info['bytes'] = human_size(info['bytes'])
601
463b10c258d9 VMM: Decode localized numbers to the current encoding.
Pascal Volk <user@localhost.localdomain.org>
parents: 600
diff changeset
   298
            info['messages'] = locale.format('%d', info['messages'],
463b10c258d9 VMM: Decode localized numbers to the current encoding.
Pascal Volk <user@localhost.localdomain.org>
parents: 600
diff changeset
   299
                                             True).decode(ENCODING, 'replace')
474
4353981e3a7f VMM/cli/subcommands: Small improvement of domaininfo's output.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 471
diff changeset
   300
            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
   301
            _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
   302
        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
   303
            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
   304
            info[0]['messages'] = locale.format('%d', info[0]['messages'],
601
463b10c258d9 VMM: Decode localized numbers to the current encoding.
Pascal Volk <user@localhost.localdomain.org>
parents: 600
diff changeset
   305
                                                True).decode(ENCODING,
463b10c258d9 VMM: Decode localized numbers to the current encoding.
Pascal Volk <user@localhost.localdomain.org>
parents: 600
diff changeset
   306
                                                             'replace')
474
4353981e3a7f VMM/cli/subcommands: Small improvement of domaininfo's output.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 471
diff changeset
   307
            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
   308
            _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
   309
            if details == u'accounts':
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'accounts'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   311
            elif details == u'aliasdomains':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   312
                _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
   313
            elif details == u'aliases':
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'aliases'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   315
            elif details == u'relocated':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   316
                _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
   317
            elif details == u'catchall':
1fa354bbdb90 Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents: 506
diff changeset
   318
                _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
   319
            else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   320
                _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
   321
                _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
   322
                _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
   323
                _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
   324
                _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
   325
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   326
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   327
def domain_quota(ctx):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   328
    """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
   329
    if ctx.argc < 3:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   330
        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
   331
              ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   332
    if ctx.argc < 4:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   333
        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
   334
    messages = 0
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   335
    force = None
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   336
    try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   337
        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
   338
    except (ValueError, TypeError):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   339
        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
   340
              ctx.args[3], ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   341
    if ctx.argc < 5:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   342
        pass
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   343
    elif ctx.argc < 6:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   344
        try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   345
            messages = int(ctx.args[4])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   346
        except ValueError:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   347
            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
   348
                usage(INVALID_ARGUMENT,
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   349
                      _(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
   350
                        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
   351
            force = 'force'
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   352
    else:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   353
        try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   354
            messages = int(ctx.args[4])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   355
        except ValueError:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   356
            usage(INVALID_ARGUMENT,
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   357
                  _(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
   358
                  ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   359
        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
   360
            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
   361
                  ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   362
        force = 'force'
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   363
    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
   364
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   365
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   366
def domain_services(ctx):
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   367
    """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
   368
    if ctx.argc < 3:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   369
        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
   370
    services = []
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   371
    force = False
448
45c917e6a386 VMM/cli/subcommands: domainservices: Don't fail when neither a
Pascal Volk <neverseen@users.sourceforge.net>
parents: 447
diff changeset
   372
    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
   373
        pass
45c917e6a386 VMM/cli/subcommands: domainservices: Don't fail when neither a
Pascal Volk <neverseen@users.sourceforge.net>
parents: 447
diff changeset
   374
    elif ctx.argc is 4:
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   375
        arg = ctx.args[3].lower()
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   376
        if arg in SERVICES:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   377
            services.append(arg)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   378
        elif arg == 'force':
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   379
            force = True
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   380
        else:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   381
            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
   382
                  ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   383
    else:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   384
        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
   385
        arg = ctx.args[-1].lower()
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   386
        if arg == 'force':
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   387
            force = True
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   388
        else:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   389
            services.append(arg)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   390
        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
   391
        if unknown:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   392
            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
   393
                  ' '.join(unknown), ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   394
    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
   395
                             *services)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   396
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   397
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   398
def domain_transport(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   399
    """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
   400
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   401
        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
   402
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   403
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   404
        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
   405
    if ctx.argc < 5:
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])
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   407
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   408
        force = ctx.args[4].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   409
        if force != 'force':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   410
            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
   411
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   412
        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
   413
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   414
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   415
def domain_note(ctx):
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   416
    """update the note of the given domain"""
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   417
    if ctx.argc < 3:
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   418
        usage(EX_MISSING_ARGS, _(u'Missing domain name.'),
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   419
              ctx.scmd)
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   420
    elif ctx.argc < 4:
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   421
        note = None
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   422
    else:
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   423
        note = ' '.join(ctx.args[3:])
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   424
    ctx.hdlr.domain_note(ctx.args[2].lower(), note)
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   425
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   426
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   427
def get_user(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   428
    """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
   429
    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
   430
        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
   431
    _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
   432
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   433
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   434
def help_(ctx):
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   435
    """print help messages."""
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   436
    if ctx.argc > 2:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   437
        hlptpc = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   438
        if hlptpc in cmd_map:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   439
            topic = hlptpc
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   440
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   441
            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
   442
                if scmd.alias == hlptpc:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   443
                    topic = scmd.name
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   444
                    break
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   445
            else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   446
                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
   447
                      ctx.args[2], ctx.scmd)
597
c79fdce49908 VMM/cli/subcommands: Reverted accidentally committed help() code.
Pascal Volk <user@localhost.localdomain.org>
parents: 596
diff changeset
   448
        # FIXME
c79fdce49908 VMM/cli/subcommands: Reverted accidentally committed help() code.
Pascal Volk <user@localhost.localdomain.org>
parents: 596
diff changeset
   449
        w_err(1, "'help %s' not yet implemented." % topic, 'see also: vmm(1)')
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   450
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   451
    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
   452
    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
   453
    txt_wrpr.initial_indent = ' '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   454
    # 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
   455
    txt_wrpr.subsequent_indent = 20 * ' '
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   456
    order = cmd_map.keys()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   457
    order.sort()
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
    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
   460
    for key in order:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   461
        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
   462
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   463
    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
   464
    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
   465
    txt_wrpr.initial_indent = ''
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   466
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   467
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   468
def list_domains(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   469
    """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
   470
    matching = ctx.argc > 2
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   471
    if matching:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   472
        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
   473
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   474
        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
   475
    _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
   476
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   477
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   478
def list_pwschemes(ctx_unused):
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   479
    """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
   480
    # 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
   481
    # 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
   482
    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
   483
    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
   484
    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
   485
    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
   486
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   487
    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
   488
        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
   489
            #key = key.rpartition(':')[0]
90d69ae4f40d VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 474
diff changeset
   490
            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
   491
        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
   492
        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
   493
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   494
    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
   495
    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
   496
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   497
555
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   498
def list_addresses(ctx, limit=None):
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   499
    """List all addresses / search addresses by pattern. The output can be
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   500
    limited with TYPE_ACCOUNT, TYPE_ALIAS and TYPE_RELOCATED, which can be
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   501
    bitwise ORed as a combination. Not specifying a limit is the same as
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   502
    combining all three."""
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   503
    if limit is None:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   504
        limit = TYPE_ACCOUNT | TYPE_ALIAS | TYPE_RELOCATED
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   505
    matching = ctx.argc > 2
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   506
    if matching:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   507
        gids, addresses = ctx.hdlr.address_list(limit, ctx.args[2].lower())
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   508
    else:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   509
        gids, addresses = ctx.hdlr.address_list(limit)
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   510
    _print_address_list(limit, gids, addresses, matching)
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   511
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   512
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   513
def list_users(ctx):
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   514
    """list all user accounts / search user accounts by pattern"""
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   515
    return list_addresses(ctx, TYPE_ACCOUNT)
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   516
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   517
def list_aliases(ctx):
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   518
    """list all aliases / search aliases by pattern"""
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   519
    return list_addresses(ctx, TYPE_ALIAS)
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   520
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   521
def list_relocated(ctx):
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   522
    """list all relocated records / search relocated records by pattern"""
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   523
    return list_addresses(ctx, TYPE_RELOCATED)
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   524
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   525
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   526
def relocated_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   527
    """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
   528
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   529
        usage(EX_MISSING_ARGS,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   530
              _(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
   531
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   532
        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
   533
    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
   534
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   535
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   536
def relocated_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   537
    """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
   538
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   539
        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
   540
    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
   541
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   542
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   543
def relocated_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   544
    """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
   545
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   546
        usage(EX_MISSING_ARGS, _(u'Missing relocated address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   547
    relocated = ctx.args[2].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   548
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   549
        _print_relocated_info(addr=relocated,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   550
                              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
   551
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   552
        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
   553
            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
   554
                  'object': relocated})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   555
            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
   556
            user_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   557
        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
   558
            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
   559
                  'object': relocated})
376
2af61bc06215 VMM/cli/subcommands: Update also the RunContext's subcommand if
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   560
            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
   561
            alias_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   562
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   563
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   564
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   565
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   566
def user_add(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   567
    """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
   568
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   569
        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
   570
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   571
        password = None
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
        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
   574
    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
   575
    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
   576
        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
   577
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   578
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   579
def user_delete(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   580
    """delete the specified user"""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   581
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   582
        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
   583
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   584
        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
   585
    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
   586
        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
   587
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   588
        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
   589
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   590
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   591
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   592
def user_info(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   593
    """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
   594
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   595
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address.'), ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   596
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   597
        details = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   598
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   599
        details = ctx.args[3].lower()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   600
        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
   601
            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
   602
                  ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   603
    try:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   604
        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
   605
    except VMMError, err:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   606
        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
   607
            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
   608
                  '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
   609
            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
   610
            alias_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   611
        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
   612
            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
   613
                  '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
   614
            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
   615
            relocated_info(ctx)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   616
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   617
            raise
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   618
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   619
        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
   620
            info['quota storage'] = _format_quota_usage(info['ql_bytes'],
532
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   621
                    info['uq_bytes'], True, info['ql_domaindefault'])
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   622
            info['quota messages'] = _format_quota_usage(info['ql_messages'],
532
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   623
                    info['uq_messages'], domaindefault=info['ql_domaindefault'])
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   624
            _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
   625
        else:
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   626
            info[0]['quota storage'] = _format_quota_usage(info[0]['ql_bytes'],
532
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   627
                    info[0]['uq_bytes'], True, info[0]['ql_domaindefault'])
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   628
            info[0]['quota messages'] = \
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   629
                _format_quota_usage(info[0]['ql_messages'],
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   630
                                    info[0]['uq_messages'],
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   631
                                    domaindefault=info[0]['ql_domaindefault'])
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   632
            _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
   633
            _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
   634
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   635
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   636
def user_name(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   637
    """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
   638
    if ctx.argc < 3:
341
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 340
diff changeset
   639
        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
   640
              ctx.scmd)
536
c340ba4bd544 Allow username to take no argument to erase value
martin f. krafft <madduck@madduck.net>
parents: 533
diff changeset
   641
    elif ctx.argc < 4:
c340ba4bd544 Allow username to take no argument to erase value
martin f. krafft <madduck@madduck.net>
parents: 533
diff changeset
   642
        name = None
c340ba4bd544 Allow username to take no argument to erase value
martin f. krafft <madduck@madduck.net>
parents: 533
diff changeset
   643
    else:
c340ba4bd544 Allow username to take no argument to erase value
martin f. krafft <madduck@madduck.net>
parents: 533
diff changeset
   644
        name = ctx.args[3]
c340ba4bd544 Allow username to take no argument to erase value
martin f. krafft <madduck@madduck.net>
parents: 533
diff changeset
   645
    ctx.hdlr.user_name(ctx.args[2].lower(), name)
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   646
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   647
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   648
def user_password(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   649
    """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
   650
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   651
        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
   652
    elif ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   653
        password = None
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   654
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   655
        password = ctx.args[3]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   656
    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
   657
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   658
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   659
def user_note(ctx):
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   660
    """update the note of the given address"""
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   661
    if ctx.argc < 3:
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   662
        usage(EX_MISSING_ARGS, _(u'Missing e-mail address.'),
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   663
              ctx.scmd)
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   664
    elif ctx.argc < 4:
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   665
        note = None
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   666
    else:
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   667
        note = ' '.join(ctx.args[3:])
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   668
    ctx.hdlr.user_note(ctx.args[2].lower(), note)
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   669
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   670
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   671
def user_quota(ctx):
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   672
    """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
   673
    if ctx.argc < 3:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   674
        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
   675
              ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   676
    elif ctx.argc < 4:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   677
        usage(EX_MISSING_ARGS, _(u'Missing storage value.'), ctx.scmd)
565
a75923ce2842 VMM/cli/subcommands: Replaced the keyword `default' by `domain'.
Pascal Volk <user@localhost.localdomain.org>
parents: 561
diff changeset
   678
    if ctx.args[3] != 'domain':
559
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 555
diff changeset
   679
        try:
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 555
diff changeset
   680
            bytes_ = size_in_bytes(ctx.args[3])
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 555
diff changeset
   681
        except (ValueError, TypeError):
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 555
diff changeset
   682
            usage(INVALID_ARGUMENT, _(u"Invalid storage value: '%s'") %
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 555
diff changeset
   683
                  ctx.args[3], ctx.scmd)
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 555
diff changeset
   684
    else:
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 555
diff changeset
   685
        bytes_ = ctx.args[3]
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   686
    if ctx.argc < 5:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   687
        messages = 0
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   688
    else:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   689
        try:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   690
            messages = int(ctx.args[4])
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   691
        except ValueError:
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   692
            usage(INVALID_ARGUMENT,
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   693
                  _(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
   694
                  ctx.scmd)
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   695
    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
   696
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   697
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   698
def user_services(ctx):
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   699
    """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
   700
    if ctx.argc < 3:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   701
        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
   702
    services = []
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   703
    if ctx.argc >= 4:
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   704
        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
   705
        unknown = [service for service in services if service not in SERVICES]
565
a75923ce2842 VMM/cli/subcommands: Replaced the keyword `default' by `domain'.
Pascal Volk <user@localhost.localdomain.org>
parents: 561
diff changeset
   706
        if unknown and ctx.args[3] != 'domain':
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   707
            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
   708
                  ' '.join(unknown), ctx.scmd)
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   709
    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
   710
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   711
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   712
def user_transport(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   713
    """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
   714
    if ctx.argc < 3:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   715
        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
   716
              ctx.scmd)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   717
    if ctx.argc < 4:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   718
        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
   719
    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
   720
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   721
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   722
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
   723
    """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
   724
    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
   725
    """
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   726
    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
   727
        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
   728
              _(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
   729
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   730
    # 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
   731
    # (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
   732
    # usage: vmm subcommand arguments
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   733
    #   short long
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   734
    #   subcommand                arguments
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   735
    #
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   736
    #   da    domainadd           fqdn [transport]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   737
    #   dd    domaindelete        fqdn [force]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   738
    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
   739
  short long
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   740
  subcommand                arguments\n""") % prog
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   741
    order = cmd_map.keys()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   742
    order.sort()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   743
    w_err(0, u_head)
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   744
    for key in order:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   745
        scmd = cmd_map[key]
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   746
        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
   747
    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
   748
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   749
462
a64c1b5e08b4 VMM/cli/subcommands: Added new subcommand `listpwschemes' (lp).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 458
diff changeset
   750
def version(ctx_unused):
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   751
    """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
   752
    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
   753
    # 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
   754
    # the version information, e.g.:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   755
    # 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
   756
    # 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
   757
        _(u'version'), __version__, _(u'from'),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   758
        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
   759
            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
   760
        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
   761
        __copyright__, prog,
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   762
        _(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
   763
420
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   764
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   765
def update_cmd_map():
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   766
    """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
   767
    cmd = Command
d4a341248500 VMM/cli/subcommands: Added function update_cmd_map().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 418
diff changeset
   768
    cmd_map.update({
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   769
    # Account commands
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   770
    '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
   771
                   _(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
   772
    '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
   773
                   _(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
   774
    '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
   775
                      _(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
   776
    '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
   777
                    _(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
   778
    '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
   779
                    _(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
   780
    '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
   781
                        'address [password]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   782
                        _(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
   783
    'userquota': cmd('userquota', 'uq', user_quota,
565
a75923ce2842 VMM/cli/subcommands: Replaced the keyword `default' by `domain'.
Pascal Volk <user@localhost.localdomain.org>
parents: 561
diff changeset
   784
                     'address storage [messages] | address domain',
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   785
                     _(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
   786
    'userservices': cmd('userservices', 'us', user_services,
565
a75923ce2842 VMM/cli/subcommands: Replaced the keyword `default' by `domain'.
Pascal Volk <user@localhost.localdomain.org>
parents: 561
diff changeset
   787
                        'address [service ...] | address domain',
445
b8c94e06cd46 VMM/cli/subcommands: Added subcommand domainservices (ds).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 429
diff changeset
   788
                        _(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
   789
                          u'not specified services')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   790
    'usertransport': cmd('usertransport', 'ut', user_transport,
565
a75923ce2842 VMM/cli/subcommands: Replaced the keyword `default' by `domain'.
Pascal Volk <user@localhost.localdomain.org>
parents: 561
diff changeset
   791
                         'address transport | address domain',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   792
                         _(u'update the transport of the given address')),
602
af88f01e5bfa VMM/cli/subcommands: Corrected two usage strings.
Pascal Volk <user@localhost.localdomain.org>
parents: 601
diff changeset
   793
    'usernote': cmd('usernote', 'uo', user_note, 'address [note]',
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   794
                    _(u'update the note of the given address')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   795
    # Alias commands
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   796
    '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
   797
                    _(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
   798
                      u'destinations')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   799
    '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
   800
                       'address [destination]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   801
                       _(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
   802
                         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
   803
    '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
   804
                     _(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
   805
    # AliasDomain commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   806
    '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
   807
                          'fqdn destination',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   808
                          _(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
   809
    '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
   810
                             '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
   811
    '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
   812
                         _(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
   813
    '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
   814
                             '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
   815
                             'domain to an other domain')),
506
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   816
    # CatchallAlias commands
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   817
    'catchalladd': cmd('catchalladd', 'caa', catchall_add,
551
62f2daff853e VMM/cli/subcommands: Use the `fqdn' argument placeholder also for
Pascal Volk <user@localhost.localdomain.org>
parents: 542
diff changeset
   818
                       'fqdn destination ...',
506
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   819
                       _(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
   820
                         u'domain')),
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   821
    'catchalldelete': cmd('catchalldelete', 'cad', catchall_delete,
551
62f2daff853e VMM/cli/subcommands: Use the `fqdn' argument placeholder also for
Pascal Volk <user@localhost.localdomain.org>
parents: 542
diff changeset
   822
                       'fqdn [destination]',
506
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   823
                       _(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
   824
                         u'of a domain\'s destinations')),
551
62f2daff853e VMM/cli/subcommands: Use the `fqdn' argument placeholder also for
Pascal Volk <user@localhost.localdomain.org>
parents: 542
diff changeset
   825
    'catchallinfo': cmd('catchallinfo', 'cai', catchall_info, 'fqdn',
506
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   826
                     _(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
   827
    # Domain commands
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   828
    '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
   829
                     _(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
   830
    '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
   831
                      _(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
   832
    '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
   833
                      _(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
   834
    '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
   835
                       'fqdn storage [messages] [force]',
403
a4f5d4cd886d VMM/cli/subcommands: Implemented subcommands domainquota and userquota.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 401
diff changeset
   836
                       _(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
   837
    '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
   838
                          'fqdn [service ...] [force]',
446
18b75e6a39d5 VMM/cli/subcommands: Small indent fix.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 445
diff changeset
   839
                          _(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
   840
                            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
   841
    '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
   842
                           'fqdn transport [force]',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   843
                           _(u'update the transport of the specified domain')),
602
af88f01e5bfa VMM/cli/subcommands: Corrected two usage strings.
Pascal Volk <user@localhost.localdomain.org>
parents: 601
diff changeset
   844
    'domainnote': cmd('domainnote', 'do', domain_note, 'fqdn [note]',
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 536
diff changeset
   845
                      _(u'update the note of the given domain')),
555
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   846
    # List commands
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   847
    '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
   848
                      _(u'list all domains or search for domains by pattern')),
555
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   849
    'listaddresses': cmd('listaddresses', 'll', list_addresses, '[pattern]',
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   850
                      _(u'list all addresses or search for addresses by pattern')),
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   851
    'listusers': cmd('listusers', 'lu', list_users, '[pattern]',
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   852
                      _(u'list all user accounts or search for accounts by pattern')),
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   853
    'listaliases': cmd('listaliases', 'la', list_aliases, '[pattern]',
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   854
                      _(u'list all aliases or search for aliases by pattern')),
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   855
    'listrelocated': cmd('listrelocated', 'lr', list_relocated, '[pattern]',
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
   856
                      _(u'list all relocated entries or search for entries by pattern')),
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   857
    # Relocated commands
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   858
    '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
   859
                        'address newaddress',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   860
                        _(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
   861
    '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
   862
                           'address',
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   863
                           _(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
   864
    '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
   865
                         _(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
   866
    # cli commands
469
1ebb6b88f589 VMM/cli/subcommands: Subcommand argument placeholders are no longer translatable.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 462
diff changeset
   867
    '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
   868
                     _('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
   869
    '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
   870
                      _('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
   871
    '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
   872
                     _(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
   873
    '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
   874
                         _(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
   875
                           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
   876
    '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
   877
                _(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
   878
    'version': cmd('version', 'v', version, '',
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   879
                   _(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
   880
    })
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   881
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
def _get_order(ctx):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   884
    """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
   885
    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
   886
    order = ()
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   887
    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
   888
        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
   889
                 (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
   890
                 (u'transport', 0), (u'alias domains', 0), (u'accounts', 0),
515
09fa019bb330 Include catch-all count in domaininfo output
martin f. krafft <madduck@madduck.net>
parents: 510
diff changeset
   891
                 (u'aliases', 0), (u'relocated', 0), (u'catch-all dests', 0))
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   892
    elif ctx.scmd == 'userinfo':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   893
        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
   894
           ctx.cget('account.disk_usage'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   895
            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
   896
                     (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
   897
                     (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
   898
                     (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
   899
                     (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
   900
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   901
            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
   902
                     (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
   903
                     (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
   904
                     (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
   905
                     (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
   906
    elif ctx.scmd == 'getuser':
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   907
        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
   908
    return order
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
532
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   911
def _format_quota_usage(limit, used, human=False, domaindefault=False):
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   912
    """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
   913
    if human:
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   914
        q_usage = {
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   915
            'used': human_size(used),
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   916
            'limit': human_size(limit),
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   917
        }
398
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   918
    else:
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   919
        q_usage = {
601
463b10c258d9 VMM: Decode localized numbers to the current encoding.
Pascal Volk <user@localhost.localdomain.org>
parents: 600
diff changeset
   920
            'used': locale.format('%d', used, True).decode(ENCODING,
463b10c258d9 VMM: Decode localized numbers to the current encoding.
Pascal Volk <user@localhost.localdomain.org>
parents: 600
diff changeset
   921
                                                           'replace'),
463b10c258d9 VMM: Decode localized numbers to the current encoding.
Pascal Volk <user@localhost.localdomain.org>
parents: 600
diff changeset
   922
            'limit': locale.format('%d', limit, True).decode(ENCODING,
463b10c258d9 VMM: Decode localized numbers to the current encoding.
Pascal Volk <user@localhost.localdomain.org>
parents: 600
diff changeset
   923
                                                             'replace'),
401
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   924
        }
00a8c12a3da3 VMM/cli/subcommands: Divided 'quota usage' from userinfo subcommand
Pascal Volk <neverseen@users.sourceforge.net>
parents: 398
diff changeset
   925
    if limit:
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   926
        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
   927
    else:
414
ae1a8428298c VMM: Report quota usage/limit/percentage values formatted
Pascal Volk <neverseen@users.sourceforge.net>
parents: 413
diff changeset
   928
        q_usage['percent'] = locale.format('%6.2f', 0, True)
561
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 559
diff changeset
   929
    #  Py25: fmt = format_domain_default if domaindefault else lambda s: s
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 559
diff changeset
   930
    if domaindefault:
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 559
diff changeset
   931
        fmt = format_domain_default
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 559
diff changeset
   932
    else:
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 559
diff changeset
   933
        fmt = lambda s: s
532
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   934
    return fmt(_(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
   935
3e5ed678d535 VMM/cli/subcommands: Added quota limit/usage output to {domain,user}info
Pascal Volk <neverseen@users.sourceforge.net>
parents: 397
diff changeset
   936
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   937
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
   938
    """Print info dicts."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   939
    # 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
   940
    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
   941
    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
   942
    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
   943
        if upper:
447
c31d604e26d3 VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 446
diff changeset
   944
            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
   945
        else:
447
c31d604e26d3 VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 446
diff changeset
   946
            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
   947
    print
593
3dc1764c23d2 VMM/cli/subcommands: Added 'missing' newline below domain notes.
Pascal Volk <user@localhost.localdomain.org>
parents: 568
diff changeset
   948
    note = info.get('note')
3dc1764c23d2 VMM/cli/subcommands: Added 'missing' newline below domain notes.
Pascal Volk <user@localhost.localdomain.org>
parents: 568
diff changeset
   949
    if note:
3dc1764c23d2 VMM/cli/subcommands: Added 'missing' newline below domain notes.
Pascal Volk <user@localhost.localdomain.org>
parents: 568
diff changeset
   950
        _print_note(note + '\n')
3dc1764c23d2 VMM/cli/subcommands: Added 'missing' newline below domain notes.
Pascal Volk <user@localhost.localdomain.org>
parents: 568
diff changeset
   951
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   952
542
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   953
def _print_note(note):
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   954
    msg = _(u'Note')
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   955
    w_std(msg, u'-' * len(msg))
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   956
    old_ii = txt_wrpr.initial_indent
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   957
    old_si = txt_wrpr.subsequent_indent
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   958
    txt_wrpr.initial_indent = txt_wrpr.subsequent_indent = '\t'
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   959
    txt_wrpr.width -= 8
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   960
    for para in note.split('\n'):
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   961
        w_std(txt_wrpr.fill(para))
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   962
    txt_wrpr.width += 8
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   963
    txt_wrpr.subsequent_indent = old_si
c3b98364f03d Display formatted notes in info output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   964
    txt_wrpr.initial_indent = old_ii
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   965
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   966
def _print_list(alist, title):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   967
    """Print a list."""
429
9842650569c2 Messages: Replaced some 'Available' by 'Existing'.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 423
diff changeset
   968
    # 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
   969
    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
   970
    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
   971
    if alist:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   972
        if title != _(u'alias domains'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   973
            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
   974
        else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   975
            for domain in alist:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   976
                if not domain.startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   977
                    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
   978
                else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   979
                    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
   980
        print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   981
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   982
        w_std(_(u'\tNone'), '')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   983
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   984
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   985
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
   986
    """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
   987
    title = _(u'Alias information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   988
    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
   989
    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
   990
    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
   991
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   992
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   993
506
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   994
def _print_catchall_info(domain, destinations):
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   995
    """Print the catchall destinations of a domain"""
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   996
    title = _(u'Catch-all information')
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   997
    w_std(title, u'-' * len(title))
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
   998
    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
   999
          % domain)
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
  1000
    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
  1001
    print
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
  1002
fb0ffde628d6 Teach CLI about catchall* commands
martin f. krafft <madduck@madduck.net>
parents: 487
diff changeset
  1003
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1004
def _print_relocated_info(**kwargs):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1005
    """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
  1006
    title = _(u'Relocated information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1007
    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
  1008
    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
  1009
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1010
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1011
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
  1012
    """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
  1013
    if domain.startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1014
        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
  1015
    if main:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1016
        return u'\t[+] %s' % domain
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1017
    return u'\t[-]     %s' % domain
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1018
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1019
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1020
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
  1021
    """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
  1022
    if matching:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1023
        title = _(u'Matching domains')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1024
    else:
429
9842650569c2 Messages: Replaced some 'Available' by 'Existing'.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 423
diff changeset
  1025
        title = _(u'Existing domains')
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1026
    w_std(title, '-' * len(title))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1027
    if domains:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1028
        for did in dids:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1029
            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
  1030
                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
  1031
            if len(domains[did]) > 1:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1032
                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
  1033
    else:
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1034
        w_std(_('\tNone'))
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1035
    print
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1036
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1037
555
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1038
def _print_address_list(which, dids, addresses, matching):
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1039
    """Print a list of (matching) addresses."""
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1040
    _trans = { TYPE_ACCOUNT                  : _('user accounts')
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1041
             , TYPE_ALIAS                    : _('aliases')
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1042
             , TYPE_RELOCATED                : _('relocated entries')
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1043
             , TYPE_ACCOUNT | TYPE_ALIAS
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1044
                 : _('user accounts and aliases')
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1045
             , TYPE_ACCOUNT | TYPE_RELOCATED
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1046
                 : _('user accounts and relocated entries')
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1047
             , TYPE_ALIAS | TYPE_RELOCATED
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1048
                 : _('aliases and relocated entries')
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1049
             , TYPE_ACCOUNT | TYPE_ALIAS | TYPE_RELOCATED : _('addresses')
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1050
             }
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1051
    try:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1052
        if matching:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1053
            title = _(u'Matching %s') % _trans[which]
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1054
        else:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1055
            title = _(u'Existing %s') % _trans[which]
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1056
        w_std(title, '-' * len(title))
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1057
    except KeyError:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1058
        raise VMMError(_("Invalid address type for list: '%s'") % which,
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1059
                       INVALID_ARGUMENT)
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1060
    if addresses:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1061
        if which & (which - 1) == 0:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1062
            # only one type is requested, so no type indicator
600
0571f45501da VMM/cli/subcommands: Don't mark empty strings as translatable.
Pascal Volk <user@localhost.localdomain.org>
parents: 597
diff changeset
  1063
            _trans = { TYPE_ACCOUNT   : ''
0571f45501da VMM/cli/subcommands: Don't mark empty strings as translatable.
Pascal Volk <user@localhost.localdomain.org>
parents: 597
diff changeset
  1064
                     , TYPE_ALIAS     : ''
0571f45501da VMM/cli/subcommands: Don't mark empty strings as translatable.
Pascal Volk <user@localhost.localdomain.org>
parents: 597
diff changeset
  1065
                     , TYPE_RELOCATED : ''
555
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1066
                     }
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1067
        else:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1068
            _trans = { TYPE_ACCOUNT   : _('u')
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1069
                     , TYPE_ALIAS     : _('a')
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1070
                     , TYPE_RELOCATED : _('r')
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1071
                     }
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1072
        for did in dids:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1073
            for addr, atype, aliasdomain in addresses[did]:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1074
                if aliasdomain:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1075
                    leader = '[%s-]' % _trans[atype]
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1076
                else:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1077
                    leader = '[%s+]' % _trans[atype]
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1078
                w_std('\t%s %s' % (leader, addr))
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1079
    else:
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1080
        w_std(_('\tNone'))
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1081
    print
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1082
499c63f52462 Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents: 551
diff changeset
  1083
340
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1084
def _print_aliasdomain_info(info):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1085
    """Print alias domain information."""
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1086
    title = _(u'Alias domain information')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1087
    for key in ('alias', 'domain'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1088
        if info[key].startswith('xn--'):
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1089
            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
  1090
    w_std(title, '-' * len(title),
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1091
          _('\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
  1092
          info, '')
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1093
4515afec62e5 vmm: Renamed to VirtualMailManager/cli/main.py. Splitted subcommands
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
  1094
del _