1 # -*- coding: UTF-8 -*- |
1 # -*- coding: UTF-8 -*- |
2 # Copyright (c) 2007 - 2010, Pascal Volk |
2 # Copyright (c) 2007 - 2012, Pascal Volk |
3 # See COPYING for distribution information. |
3 # See COPYING for distribution information. |
4 # package initialization code |
4 """ |
5 # |
5 VirtualMailManager |
|
6 ~~~~~~~~~~~~~~~~~~ |
6 |
7 |
7 import os |
8 VirtualMailManager package initialization code |
8 import re |
9 """ |
|
10 |
|
11 import gettext |
9 import locale |
12 import locale |
|
13 import sys |
10 |
14 |
11 from constants.VERSION import * |
15 from VirtualMailManager.constants import __author__, __date__, __version__ |
12 import constants.ERROR as ERR |
16 |
|
17 __all__ = [ |
|
18 # version information from VERSION |
|
19 '__author__', '__date__', '__version__', |
|
20 # defined stuff |
|
21 'ENCODING', |
|
22 ] |
|
23 |
13 |
24 |
14 # Try to set all of the locales according to the current |
25 # Try to set all of the locales according to the current |
15 # environment variables and get the character encoding. |
26 # environment variables and get the character encoding. |
16 try: |
27 try: |
17 locale.setlocale(locale.LC_ALL, '') |
28 locale.setlocale(locale.LC_ALL, '') |
18 except locale.Error: |
29 except locale.Error: |
|
30 sys.stderr.write('warning: unsupported locale setting - ' |
|
31 'that may cause encoding problems.\n\n') |
19 locale.setlocale(locale.LC_ALL, 'C') |
32 locale.setlocale(locale.LC_ALL, 'C') |
20 ENCODING = locale.nl_langinfo(locale.CODESET) |
33 ENCODING = locale.nl_langinfo(locale.CODESET) |
21 |
34 |
22 def w_std(*args): |
35 gettext.install('vmm', '/usr/local/share/locale', unicode=1) |
23 """Writes each arg of args, encoded in the current ENCODING, to stdout and |
|
24 appends a newline.""" |
|
25 _write = os.sys.stdout.write |
|
26 for arg in args: |
|
27 _write(arg.encode(ENCODING, 'replace')) |
|
28 _write('\n') |
|
29 |
|
30 def w_err(code, *args): |
|
31 """Writes each arg of args, encoded in the current ENCODING, to stderr and |
|
32 appends a newline. |
|
33 This function additional interrupts the program execution and uses 'code' |
|
34 system exit status.""" |
|
35 _write = os.sys.stderr.write |
|
36 for arg in args: |
|
37 _write(arg.encode(ENCODING, 'replace')) |
|
38 _write('\n') |
|
39 os.sys.exit(code) |
|
40 |
|
41 __all__ = [ |
|
42 # imported modules |
|
43 'os', 're', 'locale', |
|
44 # version information from VERSION |
|
45 '__author__', '__date__', '__version__', |
|
46 # error codes |
|
47 'ERR', |
|
48 # defined stuff |
|
49 'ENCODING', 'w_std', 'w_err' |
|
50 ] |
|
51 # EOF |
|