VMM/Handler: __init__ accepts now a config_type ('default'||'cli'). v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Sat, 06 Feb 2010 04:09:17 +0000
branchv0.6.x
changeset 188 cf1b5f22dbd2
parent 187 38b9a9859749
child 189 e63853509ad0
VMM/Handler: __init__ accepts now a config_type ('default'||'cli'). - fixed syntax errors, introduced with the last commit. VMM/Config: added Config.configure() -> NotImplementedError. VMM/__init__: install gettext global, everything depends on it.
VirtualMailManager/Config.py
VirtualMailManager/Handler.py
VirtualMailManager/__init__.py
vmm
--- a/VirtualMailManager/Config.py	Sat Feb 06 02:11:55 2010 +0000
+++ b/VirtualMailManager/Config.py	Sat Feb 06 04:09:17 2010 +0000
@@ -261,7 +261,7 @@
 
 
 class Config(LazyConfig):
-    """This class is for reading and modifying vmm's configuration file."""
+    """This class is for reading vmm's configuration file."""
 
     def __init__(self, filename):
         """Creates a new Config instance
@@ -321,6 +321,9 @@
             },
         }
 
+    def configure(self, sections):
+        raise NotImplementedError
+
     def load(self):
         """Loads the configuration, read only.
 
--- a/VirtualMailManager/Handler.py	Sat Feb 06 02:11:55 2010 +0000
+++ b/VirtualMailManager/Handler.py	Sat Feb 06 04:09:17 2010 +0000
@@ -21,11 +21,10 @@
 from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net
 
 import VirtualMailManager.constants.ERROR as ERR
-from VirtualMailManager import ENCODING, ace2idna, exec_ok, read_pass
+from VirtualMailManager import ENCODING, ace2idna, exec_ok
 from VirtualMailManager.Account import Account
 from VirtualMailManager.Alias import Alias
 from VirtualMailManager.AliasDomain import AliasDomain
-from VirtualMailManager.Config import Config as Cfg
 from VirtualMailManager.Domain import Domain
 from VirtualMailManager.EmailAddress import EmailAddress
 from VirtualMailManager.Exceptions import *
@@ -40,11 +39,13 @@
 class Handler(object):
     """Wrapper class to simplify the access on all the stuff from
     VirtualMailManager"""
-    # TODO: accept a LazyConfig object as argument
     __slots__ = ('__Cfg', '__cfgFileName', '__dbh', '__scheme', '__warnings',
                  '_postconf')
-    def __init__(self):
+    def __init__(self, config_type='default'):
         """Creates a new Handler instance.
+
+        Accepted ``config_type``s are 'default' and 'cli'.
+
         Throws a VMMNotRootException if your uid is greater 0.
         """
         self.__cfgFileName = ''
@@ -52,6 +53,14 @@
         self.__Cfg = None
         self.__dbh = None
 
+        if config_type == 'default':
+            from VirtualMailManager.Config import Config as Cfg
+        elif config_type == 'cli':
+            from VirtualMailManager.cli.CliConfig import CliConfig as Cfg
+            from VirtualMailManager.cli import read_pass
+        else:
+            raise ValueError('invalid config_type: %r' % config_type)
+
         if os.geteuid():
             raise VMMNotRootException(_(u"You are not root.\n\tGood bye!\n"),
                 ERR.CONF_NOPERM)
@@ -154,15 +163,15 @@
 
     def aliasExists(dbh, address):
         sql = "SELECT DISTINCT gid FROM alias WHERE gid = (SELECT gid FROM\
- domain_name WHERE domainname = '%s') AND address = '%s'" %
-            (address._domainname, address._localpart)
+ domain_name WHERE domainname = '%s') AND address = '%s'" % (
+                                        address._domainname, address._localpart)
         return Handler._exists(dbh, sql)
     aliasExists = staticmethod(aliasExists)
 
     def relocatedExists(dbh, address):
         sql = "SELECT gid FROM relocated WHERE gid = (SELECT gid FROM\
- domain_name WHERE domainname = '%s') AND address = '%s'" %
-            (address._domainname, address._localpart)
+ domain_name WHERE domainname = '%s') AND address = '%s'" % (
+                                        address._domainname, address._localpart)
         return Handler._exists(dbh, sql)
     relocatedExists = staticmethod(relocatedExists)
 
--- a/VirtualMailManager/__init__.py	Sat Feb 06 02:11:55 2010 +0000
+++ b/VirtualMailManager/__init__.py	Sat Feb 06 04:09:17 2010 +0000
@@ -4,6 +4,7 @@
 # package initialization code
 #
 
+import gettext
 import os
 import re
 import locale
@@ -40,6 +41,8 @@
 RE_DOMAIN = """^(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}$"""
 
 
+gettext.install('vmm', '/usr/local/share/locale', unicode=1)
+
 def get_unicode(string):
     """Converts `string` to `unicode`, if necessary."""
     if isinstance(string, unicode):
--- a/vmm	Sat Feb 06 02:11:55 2010 +0000
+++ b/vmm	Sat Feb 06 04:09:17 2010 +0000
@@ -5,7 +5,6 @@
 
 """This is the vmm main script."""
 
-import gettext
 from time import strftime, strptime
 
 from VirtualMailManager import *
@@ -490,7 +489,6 @@
 
 if __name__ == '__main__':
     __prog__ = os.path.basename(os.sys.argv[0])
-    gettext.install(__prog__, '/usr/local/share/locale', unicode=1)
     argv = [unicode(arg, ENCODING) for arg in os.sys.argv]
     argc = len(os.sys.argv)
     plan_a_b =_(u'Plan A failed ... trying Plan B: %(subcommand)s %(object)s')