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