author | Pascal Volk <neverseen@users.sourceforge.net> |
Tue, 08 Sep 2009 02:41:08 +0000 | |
changeset 147 | e3fd0b67ae50 |
parent 141 | ecd6a379e523 |
child 152 | 3dbee02711cd |
permissions | -rw-r--r-- |
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.""" |
141
ecd6a379e523
Small optimization in w_std()/w_err() 'avoid the dot'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
22 |
_write = os.sys.stdout.write |
138
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
23 |
for arg in args: |
141
ecd6a379e523
Small optimization in w_std()/w_err() 'avoid the dot'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
24 |
_write(arg.encode(ENCODING, 'replace')) |
ecd6a379e523
Small optimization in w_std()/w_err() 'avoid the dot'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
25 |
_write('\n') |
138
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
26 |
|
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
27 |
def w_err(code, *args): |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
28 |
"""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
|
29 |
appends a newline. |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
30 |
This function additional interrupts the program execution and uses 'code' |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
31 |
system exit status.""" |
141
ecd6a379e523
Small optimization in w_std()/w_err() 'avoid the dot'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
32 |
_write = os.sys.stderr.write |
138
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
33 |
for arg in args: |
141
ecd6a379e523
Small optimization in w_std()/w_err() 'avoid the dot'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
34 |
_write(arg.encode(ENCODING, 'replace')) |
ecd6a379e523
Small optimization in w_std()/w_err() 'avoid the dot'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
35 |
_write('\n') |
138
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
36 |
os.sys.exit(code) |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
37 |
|
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
38 |
__all__ = [ |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
39 |
# imported modules |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
40 |
'os', 're', 'locale', |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
41 |
# version information from VERSION |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
42 |
'__author__', '__date__', '__version__', |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
43 |
# error codes |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
44 |
'ERR', |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
45 |
# defined stuff |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
46 |
'ENCODING', 'w_std', 'w_err' |
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
47 |
] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
48 |
# EOF |