VirtualMailManager/__init__.py
author Pascal Volk <neverseen@users.sourceforge.net>
Wed, 02 Sep 2009 06:08:53 +0000
changeset 138 617f27715b01
parent 102 485d3f7d6981
child 141 ecd6a379e523
permissions -rw-r--r--
Reorganized module import. Dropped the import of constants.VERSION, when it wasn't really needed. Centralized the import of os, re and locale in VirtualMailManager/__init__.py. Also moved w_std() and w_err() from vmm to the __init__.py.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     1
# -*- coding: UTF-8 -*-
102
485d3f7d6981 Removed svn keywords, more POSIX compliant shell scripts
Pascal Volk <neverseen@users.sourceforge.net>
parents: 77
diff changeset
     2
# Copyright (c) 2007 - 2009, VEB IT
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     3
# See COPYING for distribution information.
138
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
     4
# package initialization code
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     5
#
138
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
     6
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
     7
import os
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
     8
import re
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
     9
import locale
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    10
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    11
from constants.VERSION import *
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    12
import constants.ERROR as ERR
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    13
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    14
# Set all of the locales according to the current environment variables
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    15
# and get the character encoding.
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    16
locale.setlocale(locale.LC_ALL, '')
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    17
ENCODING = locale.nl_langinfo(locale.CODESET)
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    18
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    19
def w_std(*args):
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    20
    """Writes each arg of args, encoded in the current ENCODING, to stdout and
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    21
    appends a newline."""
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    22
    for arg in args:
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    23
        os.sys.stdout.write(arg.encode(ENCODING, 'replace'))
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    24
        os.sys.stdout.write('\n')
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    25
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    26
def w_err(code, *args):
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    27
    """Writes each arg of args, encoded in the current ENCODING, to stderr and
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    28
    appends a newline.
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    29
    This function additional interrupts the program execution and uses 'code'
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    30
    system exit status."""
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    31
    for arg in args:
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    32
        os.sys.stderr.write(arg.encode(ENCODING, 'replace'))
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    33
        os.sys.stderr.write('\n')
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    34
    os.sys.exit(code)
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    35
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    36
__all__ = [
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    37
        # imported modules
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    38
        'os', 're', 'locale',
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    39
        # version information from VERSION
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    40
        '__author__', '__date__', '__version__',
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    41
        # error codes
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    42
        'ERR',
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    43
        # defined stuff
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    44
        'ENCODING', 'w_std', 'w_err'
617f27715b01 Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    45
        ]
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    46
# EOF