VirtualMailManager/cli/__init__.py
branchv0.6.x
changeset 215 33f727efa7c4
parent 205 bc9726c9ad85
child 217 eecd05e31517
equal deleted inserted replaced
214:84e6e898e6c5 215:33f727efa7c4
     6     VirtualMailManager.cli
     6     VirtualMailManager.cli
     7 
     7 
     8     VirtualMailManager's command line interface.
     8     VirtualMailManager's command line interface.
     9 """
     9 """
    10 
    10 
       
    11 import os
    11 from cStringIO import StringIO
    12 from cStringIO import StringIO
    12 from getpass import getpass
    13 from getpass import getpass
    13 from textwrap import TextWrapper
    14 from textwrap import TextWrapper
    14 
    15 
    15 import VirtualMailManager
    16 from VirtualMailManager import ENCODING
    16 
    17 
    17 
    18 
    18 __all__ = ('get_winsize', 'read_pass', 'string_io', 'w_err', 'w_std')
    19 __all__ = ('get_winsize', 'read_pass', 'string_io', 'w_err', 'w_std')
    19 
    20 
    20 os = VirtualMailManager.os
       
    21 _std_write = os.sys.stdout.write
    21 _std_write = os.sys.stdout.write
    22 _err_write = os.sys.stderr.write
    22 _err_write = os.sys.stderr.write
    23 
    23 
    24 
    24 
    25 def w_std(*args):
    25 def w_std(*args):
    26     """Writes each arg of `args`, encoded in the current ENCODING, to stdout
    26     """Writes each arg of `args`, encoded in the current ENCODING, to stdout
    27     and appends a newline."""
    27     and appends a newline."""
    28     for arg in args:
    28     for arg in args:
    29         _std_write(arg.encode(VirtualMailManager.ENCODING, 'replace'))
    29         _std_write(arg.encode(ENCODING, 'replace'))
    30         _std_write('\n')
    30         _std_write('\n')
    31 
    31 
    32 
    32 
    33 def w_err(code, *args):
    33 def w_err(code, *args):
    34     """Writes each arg of `args`, encoded in the current ENCODING, to stderr
    34     """Writes each arg of `args`, encoded in the current ENCODING, to stderr
    35     and appends a newline.
    35     and appends a newline.
    36 
    36 
    37     This function additional interrupts the program execution and uses
    37     This function additional interrupts the program execution and uses
    38     `code` system exit status."""
    38     `code` system exit status."""
    39     for arg in args:
    39     for arg in args:
    40         _err_write(arg.encode(VirtualMailManager.ENCODING, 'replace'))
    40         _err_write(arg.encode(ENCODING, 'replace'))
    41         _err_write('\n')
    41         _err_write('\n')
    42     os.sys.exit(code)
    42     os.sys.exit(code)
    43 
    43 
    44 
    44 
    45 def get_winsize():
    45 def get_winsize():