equal
deleted
inserted
replaced
39 from ConfigParser import \ |
39 from ConfigParser import \ |
40 Error, MissingSectionHeaderError, NoOptionError, NoSectionError, \ |
40 Error, MissingSectionHeaderError, NoOptionError, NoSectionError, \ |
41 ParsingError, RawConfigParser |
41 ParsingError, RawConfigParser |
42 from cStringIO import StringIO# TODO: move interactive stff to cli |
42 from cStringIO import StringIO# TODO: move interactive stff to cli |
43 |
43 |
44 from VirtualMailManager import ENCODING, exec_ok, get_unicode, is_dir |
44 from VirtualMailManager import exec_ok, get_unicode, is_dir |
45 from VirtualMailManager.constants.ERROR import CONF_ERROR |
45 from VirtualMailManager.constants.ERROR import CONF_ERROR |
46 from VirtualMailManager.Exceptions import VMMConfigException |
46 from VirtualMailManager.Exceptions import VMMConfigException |
47 |
47 |
48 |
48 |
49 class BadOptionError(Error): |
49 class BadOptionError(Error): |
224 self._get_section_option(option) |
224 self._get_section_option(option) |
225 return True |
225 return True |
226 except(BadOptionError, NoSectionError, NoOptionError): |
226 except(BadOptionError, NoSectionError, NoOptionError): |
227 return False |
227 return False |
228 |
228 |
|
229 def sections(self): |
|
230 """Returns an iterator object for all configuration sections.""" |
|
231 return self._cfg.iterkeys() |
|
232 |
229 |
233 |
230 class LazyConfigOption(object): |
234 class LazyConfigOption(object): |
231 """A simple container class for configuration settings. |
235 """A simple container class for configuration settings. |
232 |
236 |
233 ``LazyConfigOption`` instances are required by `LazyConfig` instances, |
237 ``LazyConfigOption`` instances are required by `LazyConfig` instances, |
382 errmsg.write(_(u'* Section: %s\n') % section) |
386 errmsg.write(_(u'* Section: %s\n') % section) |
383 for option in options: |
387 for option in options: |
384 errmsg.write((u' %s\n') % option) |
388 errmsg.write((u' %s\n') % option) |
385 raise VMMConfigException(errmsg.getvalue(), CONF_ERROR) |
389 raise VMMConfigException(errmsg.getvalue(), CONF_ERROR) |
386 |
390 |
387 def sections(self): |
|
388 """Returns an iterator object for all configuration sections.""" |
|
389 return self._cfg.iterkeys() |
|
390 |
|
391 def known_scheme(self, scheme): |
391 def known_scheme(self, scheme): |
392 """Converts ``scheme`` to upper case and checks if is known by |
392 """Converts ``scheme`` to upper case and checks if is known by |
393 Dovecot (listed in VirtualMailManager.SCHEMES). |
393 Dovecot (listed in VirtualMailManager.SCHEMES). |
394 |
394 |
395 Throws a `ConfigValueError` if the scheme is not listed in |
395 Throws a `ConfigValueError` if the scheme is not listed in |
403 to Unicode. |
403 to Unicode. |
404 """ |
404 """ |
405 return get_unicode(self.get(section, option)) |
405 return get_unicode(self.get(section, option)) |
406 |
406 |
407 def __chkCfg(self): |
407 def __chkCfg(self): |
408 """Checks all section's options for settings w/o default values. |
408 """Checks all section's options for settings w/o a default value. |
409 |
409 |
410 Returns ``True`` if everything is fine, else ``False``.""" |
410 Returns ``True`` if everything is fine, else ``False``.""" |
411 errors = False |
411 errors = False |
412 for section in self._cfg.iterkeys(): |
412 for section in self._cfg.iterkeys(): |
413 missing = [] |
413 missing = [] |