Reorganized module import.
authorPascal Volk <neverseen@users.sourceforge.net>
Wed, 02 Sep 2009 06:08:53 +0000
changeset 138 617f27715b01
parent 137 fc09f657082d
child 139 7f6911bd11cd
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.
VirtualMailManager/Account.py
VirtualMailManager/Alias.py
VirtualMailManager/AliasDomain.py
VirtualMailManager/Config.py
VirtualMailManager/Domain.py
VirtualMailManager/EmailAddress.py
VirtualMailManager/Exceptions.py
VirtualMailManager/MailLocation.py
VirtualMailManager/Relocated.py
VirtualMailManager/Transport.py
VirtualMailManager/VirtualMailManager.py
VirtualMailManager/__init__.py
VirtualMailManager/ext/Postconf.py
vmm
--- a/VirtualMailManager/Account.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/Account.py	Wed Sep 02 06:08:53 2009 +0000
@@ -4,15 +4,13 @@
 
 """Virtual Mail Manager's Account class to manage e-mail accounts."""
 
-from constants.VERSION import *
-
+from __main__ import ERR
 from Exceptions import VMMAccountException as AccE
 from Domain import Domain
 from Transport import Transport
 from MailLocation import MailLocation
 from EmailAddress import EmailAddress
 import VirtualMailManager as VMM
-import constants.ERROR as ERR
 
 class Account(object):
     """Class to manage e-mail accounts."""
--- a/VirtualMailManager/Alias.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/Alias.py	Wed Sep 02 06:08:53 2009 +0000
@@ -4,12 +4,10 @@
 
 """Virtual Mail Manager's Alias class to manage e-mail aliases."""
 
-from constants.VERSION import *
-
+from __main__ import ERR
 from Exceptions import VMMAliasException as VMMAE
 from Domain import Domain
 from EmailAddress import EmailAddress
-import constants.ERROR as ERR
 import VirtualMailManager as VMM
 
 class Alias(object):
--- a/VirtualMailManager/AliasDomain.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/AliasDomain.py	Wed Sep 02 06:08:53 2009 +0000
@@ -4,10 +4,8 @@
 
 """Virtual Mail Manager's AliasDomain class to manage alias domains."""
 
-from constants.VERSION import *
-
+from __main__ import ERR
 from Exceptions import VMMAliasDomainException as VADE
-import constants.ERROR as ERR
 import VirtualMailManager as VMM
 
 class AliasDomain(object):
--- a/VirtualMailManager/Config.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/Config.py	Wed Sep 02 06:08:53 2009 +0000
@@ -7,15 +7,12 @@
 
 """
 
-from constants.VERSION import *
-
 from shutil import copy2
 from ConfigParser import ConfigParser, MissingSectionHeaderError, ParsingError
 from cStringIO import StringIO
 
-from __main__ import ENCODING, w_std
+from __main__ import ENCODING, ERR, w_std
 from Exceptions import VMMConfigException
-import constants.ERROR as ERR
 
 class Config(ConfigParser):
     """This class is for reading and modifying vmm's configuration file."""
--- a/VirtualMailManager/Domain.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/Domain.py	Wed Sep 02 06:08:53 2009 +0000
@@ -4,12 +4,10 @@
 
 """Virtual Mail Manager's Domain class to manage e-mail domains."""
 
-from constants.VERSION import *
-
 from random import choice
 
+from __main__ import ERR
 from Exceptions import VMMDomainException as VMMDE
-import constants.ERROR as ERR
 import VirtualMailManager as VMM
 from Transport import Transport
 
--- a/VirtualMailManager/EmailAddress.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/EmailAddress.py	Wed Sep 02 06:08:53 2009 +0000
@@ -4,13 +4,9 @@
 
 """Virtual Mail Manager's EmailAddress class to handle e-mail addresses."""
 
-from constants.VERSION import *
-
-import re
-
+from __main__ import re, ERR
 from Exceptions import VMMEmailAddressException as VMMEAE
 import VirtualMailManager as VMM
-import constants.ERROR as ERR
 
 RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]"""
 
--- a/VirtualMailManager/Exceptions.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/Exceptions.py	Wed Sep 02 06:08:53 2009 +0000
@@ -4,8 +4,6 @@
 
 """Exception classes for Virtual Mail Manager"""
 
-from constants.VERSION import *
-
 class VMMException(Exception):
     """Exception class for VirtualMailManager exceptions"""
     def __init__(self, msg, code):
--- a/VirtualMailManager/MailLocation.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/MailLocation.py	Wed Sep 02 06:08:53 2009 +0000
@@ -5,12 +5,8 @@
 """Virtual Mail Manager's MailLocation class to manage the mail_location
 for accounts."""
 
-from constants.VERSION import *
-
-import re
-
+from __main__ import re, ERR
 from Exceptions import VMMMailLocationException as MLE
-import constants.ERROR as ERR
 
 RE_MAILLOCATION = """^\w{1,20}$"""
 
--- a/VirtualMailManager/Relocated.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/Relocated.py	Wed Sep 02 06:08:53 2009 +0000
@@ -4,12 +4,10 @@
 
 """Virtual Mail Manager's Relocated class to manage relocated users."""
 
-from constants.VERSION import *
-
+from __main__ import ERR
 from Exceptions import VMMRelocatedException as VMMRE
 from Domain import Domain
 from EmailAddress import EmailAddress
-import constants.ERROR as ERR
 import VirtualMailManager as VMM
 
 class Relocated(object):
--- a/VirtualMailManager/Transport.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/Transport.py	Wed Sep 02 06:08:53 2009 +0000
@@ -5,10 +5,8 @@
 """Virtual Mail Manager's Transport class to manage the transport for
 domains and accounts."""
 
-from constants.VERSION import *
-
+from __main__ import ERR
 from Exceptions import VMMTransportException
-import constants.ERROR as ERR
 
 class Transport(object):
     """A wrapper class that provides access to the transport table"""
--- a/VirtualMailManager/VirtualMailManager.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/VirtualMailManager.py	Wed Sep 02 06:08:53 2009 +0000
@@ -4,10 +4,7 @@
 
 """The main class for vmm."""
 
-from constants.VERSION import *
 
-import os
-import re
 from encodings.idna import ToASCII, ToUnicode
 from getpass import getpass
 from shutil import rmtree
@@ -15,8 +12,7 @@
 
 from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net
 
-import constants.ERROR as ERR
-from __main__ import ENCODING, w_std
+from __main__ import os, re, ENCODING, ERR, w_std
 from ext.Postconf import Postconf
 from Account import Account
 from Alias import Alias
--- a/VirtualMailManager/__init__.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/__init__.py	Wed Sep 02 06:08:53 2009 +0000
@@ -1,6 +1,46 @@
 # -*- coding: UTF-8 -*-
 # Copyright (c) 2007 - 2009, VEB IT
 # See COPYING for distribution information.
-# package placeholder
+# package initialization code
 #
+
+import os
+import re
+import locale
+
+from constants.VERSION import *
+import constants.ERROR as ERR
+
+# Set all of the locales according to the current environment variables
+# and get the character encoding.
+locale.setlocale(locale.LC_ALL, '')
+ENCODING = locale.nl_langinfo(locale.CODESET)
+
+def w_std(*args):
+    """Writes each arg of args, encoded in the current ENCODING, to stdout and
+    appends a newline."""
+    for arg in args:
+        os.sys.stdout.write(arg.encode(ENCODING, 'replace'))
+        os.sys.stdout.write('\n')
+
+def w_err(code, *args):
+    """Writes each arg of args, encoded in the current ENCODING, to stderr and
+    appends a newline.
+    This function additional interrupts the program execution and uses 'code'
+    system exit status."""
+    for arg in args:
+        os.sys.stderr.write(arg.encode(ENCODING, 'replace'))
+        os.sys.stderr.write('\n')
+    os.sys.exit(code)
+
+__all__ = [
+        # imported modules
+        'os', 're', 'locale',
+        # version information from VERSION
+        '__author__', '__date__', '__version__',
+        # error codes
+        'ERR',
+        # defined stuff
+        'ENCODING', 'w_std', 'w_err'
+        ]
 # EOF
--- a/VirtualMailManager/ext/Postconf.py	Tue Sep 01 05:35:06 2009 +0000
+++ b/VirtualMailManager/ext/Postconf.py	Wed Sep 02 06:08:53 2009 +0000
@@ -4,12 +4,9 @@
 
 """A small - r/o - wrapper class for Postfix' postconf."""
 
-from VirtualMailManager.constants.VERSION import *
-
-import re
 from subprocess import Popen, PIPE
 
-import VirtualMailManager.constants.ERROR as ERR
+from __main__ import re, ERR
 from VirtualMailManager.Exceptions import VMMException
 
 RE_PC_PARAMS = """^\w+$"""
--- a/vmm	Tue Sep 01 05:35:06 2009 +0000
+++ b/vmm	Wed Sep 02 06:08:53 2009 +0000
@@ -5,34 +5,15 @@
 
 """This is the vmm main script."""
 
-from VirtualMailManager.constants.VERSION import *
-
-import locale
-# do it early - for importing in the other files
-locale.setlocale(locale.LC_ALL, '')
-ENCODING = locale.nl_langinfo(locale.CODESET)
-
-def w_std(*args):
-    for arg in args:
-        os.sys.stdout.write(arg.encode(ENCODING, 'replace'))
-        os.sys.stdout.write('\n')
-
-import os
 import gettext
 from time import strftime, strptime
 
+from VirtualMailManager import *
 from VirtualMailManager.VirtualMailManager import VirtualMailManager
 import VirtualMailManager.Exceptions as VMME
 import VirtualMailManager.constants.EXIT as EXIT
-import VirtualMailManager.constants.ERROR as ERR
 
 
-def w_err(code, *args):
-    for arg in args:
-        os.sys.stderr.write(arg.encode(ENCODING, 'replace'))
-        os.sys.stderr.write('\n')
-    os.sys.exit(code)
-
 def usage(excode=0, errMsg=None):
     u_head = _(u"""\
 Usage: %s SUBCOMMAND OBJECT ARGS*