vmm
changeset 156 a849843115e9
parent 155 eb866ebb9f2e
child 157 eb3ccf9484b3
equal deleted inserted replaced
155:eb866ebb9f2e 156:a849843115e9
    13 import VirtualMailManager.Exceptions as VMME
    13 import VirtualMailManager.Exceptions as VMME
    14 import VirtualMailManager.constants.EXIT as EXIT
    14 import VirtualMailManager.constants.EXIT as EXIT
    15 
    15 
    16 
    16 
    17 def usage(excode=0, errMsg=None):
    17 def usage(excode=0, errMsg=None):
       
    18     # TP: Please adjust translated words like the original text.
       
    19     # (It's a table header.) Extract from usage text:
       
    20     # Usage: vmm SUBCOMMAND OBJECT ARGS*
       
    21     #  short long
       
    22     #  subcommand               object             args (* = optional)
       
    23     #
       
    24     #  da    domainadd          domain.tld         transport*
       
    25     #  di    domaininfo         domain.tld         details*
    18     u_head = _(u"""\
    26     u_head = _(u"""\
    19 Usage: %s SUBCOMMAND OBJECT ARGS*
    27 Usage: %s SUBCOMMAND OBJECT ARGS*
    20   short long
    28   short long
    21   subcommand               object             args (* = optional)\n""")\
    29   subcommand               object             args (* = optional)\n""")\
    22           % __prog__
    30           % __prog__
    52 """
    60 """
    53     if excode > 0:
    61     if excode > 0:
    54         if errMsg is None:
    62         if errMsg is None:
    55             w_err(excode, u_head, u_body)
    63             w_err(excode, u_head, u_body)
    56         else:
    64         else:
    57             w_err(excode, u_head, u_body, '%s: %s\n' % (_(u'Error'), errMsg))
    65             w_err(excode, u_head, u_body, _(u'Error: %s\n') % errMsg)
    58     else:
    66     else:
    59         w_std(u_head, u_body)
    67         w_std(u_head, u_body)
    60         os.sys.exit(excode)
    68         os.sys.exit(excode)
    61 
    69 
    62 def get_vmm():
    70 def get_vmm():
    63     try:
    71     try:
    64         vmm = VirtualMailManager()
    72         vmm = VirtualMailManager()
    65         return vmm
    73         return vmm
    66     except (VMME.VMMException, VMME.VMMNotRootException, VMME.VMMPermException,
    74     except (VMME.VMMException, VMME.VMMNotRootException, VMME.VMMPermException,
    67             VMME.VMMConfigException), e:
    75             VMME.VMMConfigException), e:
    68         w_err(e.code(), "%s: %s\n" % (_(u'Error'), e.msg()))
    76         w_err(e.code(), _(u'Error: %s\n') % e.msg())
    69 
    77 
    70 def _getOrder():
    78 def _getOrder():
    71     order = ()
    79     order = ()
    72     if vmm.cfgGetInt('misc', 'dovecotvers') > 11:
    80     if vmm.cfgGetInt('misc', 'dovecotvers') > 11:
    73         sieve_name = u'sieve'
    81         sieve_name = u'sieve'
    90     elif argv[1] in (u'gu', u'getuser'):
    98     elif argv[1] in (u'gu', u'getuser'):
    91         order = ((u'uid', 1), (u'gid', 1), (u'address', 0))
    99         order = ((u'uid', 1), (u'gid', 1), (u'address', 0))
    92     return order
   100     return order
    93 
   101 
    94 def _printInfo(info, title):
   102 def _printInfo(info, title):
       
   103     # TP: e.g. 'Domain information' or 'Account information'
    95     msg = u'%s %s' % (title, _(u'information'))
   104     msg = u'%s %s' % (title, _(u'information'))
    96     w_std (u'%s\n%s' % (msg, u'-'*len(msg)))
   105     w_std (u'%s\n%s' % (msg, u'-'*len(msg)))
    97     for k,u in _getOrder():
   106     for k,u in _getOrder():
    98         if u:
   107         if u:
    99             w_std(u'\t%s: %s' % (k.upper().ljust(15, u'.'), info[k]))
   108             w_std(u'\t%s: %s' % (k.upper().ljust(15, u'.'), info[k]))
   100         else:
   109         else:
   101             w_std(u'\t%s: %s' % (k.title().ljust(15, u'.'), info[k]))
   110             w_std(u'\t%s: %s' % (k.title().ljust(15, u'.'), info[k]))
   102     print
   111     print
   103 
   112 
   104 def _printList(alist, title):
   113 def _printList(alist, title):
       
   114     # TP: e.g. 'Available alias addresses' or 'Available accounts'
   105     msg = u'%s %s' % (_(u'Available'), title)
   115     msg = u'%s %s' % (_(u'Available'), title)
   106     w_std(u'%s\n%s' % (msg, u'-'*len(msg)))
   116     w_std(u'%s\n%s' % (msg, u'-'*len(msg)))
   107     if len(alist) > 0:
   117     if len(alist) > 0:
   108         if title != _(u'alias domains'):
   118         if title != _(u'alias domains'):
   109             for val in alist:
   119             for val in alist:
   441         for warning in vmm.getWarnings():
   451         for warning in vmm.getWarnings():
   442             w_std( " * %s" % warning)
   452             w_std( " * %s" % warning)
   443 
   453 
   444 def show_version():
   454 def show_version():
   445     w_std('%s, %s %s (%s %s)\nPython %s %s %s\n\n%s %s' % (__prog__,
   455     w_std('%s, %s %s (%s %s)\nPython %s %s %s\n\n%s %s' % (__prog__,
       
   456     # TP: The words 'from', 'version' and 'on' are used in the version
       
   457     # information:
       
   458     # vmm, version 0.5.2 (from 09/09/09)
       
   459     # Python 2.5.4 on FreeBSD
   446         _(u'version'), __version__, _(u'from'),
   460         _(u'version'), __version__, _(u'from'),
   447         strftime(locale.nl_langinfo(locale.D_FMT),
   461         strftime(locale.nl_langinfo(locale.D_FMT),
   448             strptime(__date__, '%Y-%m-%d')).decode(ENCODING, 'replace'),
   462             strptime(__date__, '%Y-%m-%d')).decode(ENCODING, 'replace'),
   449         os.sys.version.split()[0], _(u'on'), os.uname()[0], __prog__,
   463         os.sys.version.split()[0], _(u'on'), os.uname()[0], __prog__,
   450         'is free software and comes with ABSOLUTELY NO WARRANTY.'))
   464         _(u'is free software and comes with ABSOLUTELY NO WARRANTY.')))
   451 
   465 
   452 #def main():
   466 #def main():
   453 if __name__ == '__main__':
   467 if __name__ == '__main__':
   454     __prog__ = os.path.basename(os.sys.argv[0])
   468     __prog__ = os.path.basename(os.sys.argv[0])
   455     gettext.install(__prog__, '/usr/local/share/locale', unicode=1)
   469     gettext.install(__prog__, '/usr/local/share/locale', unicode=1)
   516         elif argv[1] in (u'h', u'help'):
   530         elif argv[1] in (u'h', u'help'):
   517             usage()
   531             usage()
   518         elif argv[1] in (u'v', u'version'):
   532         elif argv[1] in (u'v', u'version'):
   519             show_version()
   533             show_version()
   520         else:
   534         else:
   521             usage(EXIT.UNKNOWN_COMMAND,
   535             usage(EXIT.UNKNOWN_COMMAND, _(u'Unknown subcommand: ā€œ%sā€')% argv[1])
   522                     u"%s: ā€œ%sā€" % (_(u'Unknown subcommand'), argv[1]))
       
   523         show_warnings()
   536         show_warnings()
   524     except (EOFError, KeyboardInterrupt):
   537     except (EOFError, KeyboardInterrupt):
   525         w_err(EXIT.USER_INTERRUPT, '\n%s!\n' % _(u'Ouch'))
   538         # TP: We have to cry, because the user has killed/interrupted vmm with
       
   539         # Ctrl+C or Ctrl+D.
       
   540         w_err(EXIT.USER_INTERRUPT, _(u'\nOuch!\n'))
   526     except (VMME.VMMConfigException, VMME.VMMException), e:
   541     except (VMME.VMMConfigException, VMME.VMMException), e:
   527         if e.code() != ERR.DATABASE_ERROR:
   542         if e.code() != ERR.DATABASE_ERROR:
   528             w_err(e.code(), "%s: %s" % (_(u'Error'), e.msg()))
   543             w_err(e.code(), _(u'Error: %s') % e.msg())
   529         else:
   544         else:
   530             w_err(e.code(), "%s" % unicode(e.msg(), ENCODING, 'replace'))
   545             w_err(e.code(), unicode(e.msg(), ENCODING, 'replace'))