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