VMM: added 'Configuration' variable and set_configuration().
Handler.__init__() now exports its config via set_configuration().
# -*- coding: UTF-8 -*-# Copyright (c) 2007 - 2010, Pascal Volk# See COPYING for distribution information.""" VirtualMailManager VirtualMailManager package initialization code"""importgettextimportosimportlocalefromVirtualMailManager.constants.ERRORimport \NOT_EXECUTABLE,NO_SUCH_BINARY,NO_SUCH_DIRECTORYfromVirtualMailManager.constants.versionimport__author__,__date__, \__version__fromVirtualMailManager.errorsimportVMMError__all__=[# version information from VERSION'__author__','__date__','__version__',# defined stuff'ENCODING','Configuration','exec_ok','expand_path','get_unicode','is_dir','set_configuration',]# Try to set all of the locales according to the current# environment variables and get the character encoding.try:locale.setlocale(locale.LC_ALL,'')exceptlocale.Error:locale.setlocale(locale.LC_ALL,'C')ENCODING=locale.nl_langinfo(locale.CODESET)Configuration=Nonegettext.install('vmm','/usr/local/share/locale',unicode=1)_=lambdamsg:msgdefset_configuration(cfg_obj):"""Assigns the *cfg_obj* to the global `Configuration`. *cfg_obj* has to be a `VirtualMailManager.Config.Config` instance."""fromVirtualMailManager.ConfigimportConfigassertisinstance(cfg_obj,Config)globalConfigurationConfiguration=cfg_objdefget_unicode(string):"""Converts `string` to `unicode`, if necessary."""ifisinstance(string,unicode):returnstringreturnunicode(string,ENCODING,'replace')defexpand_path(path):"""Expands paths, starting with ``.`` or ``~``, to an absolute path."""ifpath.startswith('.'):returnos.path.abspath(path)ifpath.startswith('~'):returnos.path.expanduser(path)returnpathdefis_dir(path):"""Checks if `path` is a directory. Throws a `VMMError` if `path` is not a directory. """path=expand_path(path)ifnotos.path.isdir(path):raiseVMMError(_(u"'%s' is not a directory")%get_unicode(path),NO_SUCH_DIRECTORY)returnpathdefexec_ok(binary):"""Checks if the `binary` exists and if it is executable. Throws a `VMMError` if the `binary` isn't a file or is not executable. """binary=expand_path(binary)ifnotos.path.isfile(binary):raiseVMMError(_(u"'%s' is not a file")%get_unicode(binary),NO_SUCH_BINARY)ifnotos.access(binary,os.X_OK):raiseVMMError(_(u"File is not executable: '%s'")%get_unicode(binary),NOT_EXECUTABLE)returnbinarydel_