VMM/Config: Added method Config.install() -> global cfg_dget().
VirtualMailManager.Configuration removed -> some adjustments.
--- a/VirtualMailManager/Config.py Wed Apr 28 05:37:14 2010 +0000
+++ b/VirtualMailManager/Config.py Wed Apr 28 09:00:02 2010 +0000
@@ -389,8 +389,17 @@
check_version_format(self.get('misc', 'dovecot_version'))
def hexversion(self, section, option):
+ """Converts the version number (e.g.: 1.2.3) from the *option*'s
+ value to an int."""
return version_hex(self.get(section, option))
+ def install(self):
+ """Installs the dget() method as ``cfg_dget`` in the built-in
+ namespace."""
+ import __builtin__
+ assert 'cfg_dget' not in __builtin__.__dict__
+ __builtin__.__dict__['cfg_dget'] = self.dget
+
def known_scheme(self, scheme):
"""Converts `scheme` to upper case and checks if is known by
Dovecot (listed in VirtualMailManager.SCHEMES).
--- a/VirtualMailManager/Handler.py Wed Apr 28 05:37:14 2010 +0000
+++ b/VirtualMailManager/Handler.py Wed Apr 28 09:00:02 2010 +0000
@@ -21,7 +21,7 @@
from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net
import VirtualMailManager.constants.ERROR as ERR
-from VirtualMailManager import ENCODING, set_configuration
+from VirtualMailManager import ENCODING
from VirtualMailManager.Account import Account
from VirtualMailManager.Alias import Alias
from VirtualMailManager.AliasDomain import AliasDomain
@@ -77,7 +77,7 @@
# will be moved to the new password module and Alias
#self._scheme = self._Cfg.dget('misc.password_scheme')
#self._postconf = Postconf(self._Cfg.dget('bin.postconf'))
- set_configuration(self._Cfg)
+ self._Cfg.install()
def __findCfgFile(self):
for path in ['/root', '/usr/local/etc', '/etc']:
--- a/VirtualMailManager/__init__.py Wed Apr 28 05:37:14 2010 +0000
+++ b/VirtualMailManager/__init__.py Wed Apr 28 09:00:02 2010 +0000
@@ -18,7 +18,7 @@
# version information from VERSION
'__author__', '__date__', '__version__',
# defined stuff
- 'ENCODING', 'Configuration', 'set_configuration',
+ 'ENCODING',
]
@@ -30,15 +30,4 @@
locale.setlocale(locale.LC_ALL, 'C')
ENCODING = locale.nl_langinfo(locale.CODESET)
-Configuration = None
-
gettext.install('vmm', '/usr/local/share/locale', unicode=1)
-
-
-def set_configuration(cfg_obj):
- """Assigns the *cfg_obj* to the global `Configuration`.
- *cfg_obj* has to be a `VirtualMailManager.Config.Config` instance."""
- from VirtualMailManager.Config import Config
- assert isinstance(cfg_obj, Config)
- global Configuration
- Configuration = cfg_obj
--- a/VirtualMailManager/password.py Wed Apr 28 05:37:14 2010 +0000
+++ b/VirtualMailManager/password.py Wed Apr 28 09:00:02 2010 +0000
@@ -21,7 +21,7 @@
except ImportError:
from VirtualMailManager.pycompat import hashlib
-from VirtualMailManager import ENCODING, Configuration
+from VirtualMailManager import ENCODING
from VirtualMailManager.EmailAddress import EmailAddress
from VirtualMailManager.common import get_unicode, version_str
from VirtualMailManager.constants.ERROR import VMM_ERROR
@@ -34,6 +34,7 @@
DEFAULT_HEX = (None, 'HEX')
_ = lambda msg: msg
+cfg_dget = lambda option: None
_get_salt = lambda s_len: ''.join(choice(SALTCHARS) for x in xrange(s_len))
@@ -43,9 +44,9 @@
"""
if encoding:
scheme = '.'.join((scheme, encoding))
- cmd_args = [Configuration.dget('bin.dovecotpw'), '-s', scheme, '-p',
+ cmd_args = [cfg_dget('bin.dovecotpw'), '-s', scheme, '-p',
get_unicode(password)]
- if Configuration.dget('misc.dovecot_version') >= 0x20000a01:
+ if cfg_dget('misc.dovecot_version') >= 0x20000a01:
cmd_args.insert(1, 'pw')
process = Popen(cmd_args, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
@@ -143,7 +144,7 @@
# versions. See also:
# http://dovecot.org/list/dovecot-news/2009-March/000103.html
# http://hg.dovecot.org/dovecot-1.1/rev/2b0043ba89ae
- if Configuration.dget('misc.dovecot_version') >= 0x1010cf00:
+ if cfg_dget('misc.dovecot_version') >= 0x1010cf00:
md5.update('%s:%s:' % (user.localpart, user.domainname))
else:
md5.update('%s::' % user)
@@ -290,7 +291,6 @@
be used for the hash generation. When 'DIGEST-MD5' is used as scheme,
also an EmailAddress instance must be given as *user* argument.
"""
- assert Configuration is not None
if not isinstance(password, basestring):
raise TypeError('Password is not a string: %r' % password)
if isinstance(password, unicode):
@@ -299,18 +299,18 @@
if not password:
raise ValueError("Couldn't accept empty password.")
if scheme is None:
- scheme = Configuration.dget('misc.password_scheme')
+ scheme = cfg_dget('misc.password_scheme')
scheme_encoding = scheme.split('.')
scheme = scheme_encoding[0].upper()
if not scheme in _scheme_info:
raise VMMError(_(u"Unsupported password scheme: '%s'") % scheme,
VMM_ERROR)
- if Configuration.dget('misc.dovecot_version') < _scheme_info[scheme][1]:
+ if cfg_dget('misc.dovecot_version') < _scheme_info[scheme][1]:
raise VMMError(_(u"The scheme '%s' requires Dovecot >= v%s") %
(scheme, version_str(_scheme_info[scheme][1])),
VMM_ERROR)
if len(scheme_encoding) > 1:
- if Configuration.dget('misc.dovecot_version') < 0x10100a01:
+ if cfg_dget('misc.dovecot_version') < 0x10100a01:
raise VMMError(_(u'Encoding suffixes for password schemes require \
Dovecot >= v1.1.alpha1'),
VMM_ERROR)
@@ -331,12 +331,11 @@
The length of the password can be configured in the ``vmm.cfg``
(account.password_length).
"""
- assert Configuration is not None
pw_chars = list(PASSWDCHARS)
shuffle(pw_chars)
- pw_len = Configuration.dget('account.password_length')
+ pw_len = cfg_dget('account.password_length')
if pw_len < 8:
pw_len = 8
return ''.join(choice(pw_chars) for x in xrange(pw_len))
-del _
+del _, cfg_dget