# HG changeset patch # User Pascal Volk # Date 1280430859 0 # Node ID 8f8d9c4c83325387f481d942bb8557c5f801e351 # Parent 06c0457036a045f21399d05dde3c8900c264a17d VMM/common: Replaced function is_dir() by lisdir(). VMM/{config,mailbox}: Adjusted to the above change. diff -r 06c0457036a0 -r 8f8d9c4c8332 VirtualMailManager/common.py --- a/VirtualMailManager/common.py Thu Jul 29 04:01:43 2010 +0000 +++ b/VirtualMailManager/common.py Thu Jul 29 19:14:19 2010 +0000 @@ -10,6 +10,7 @@ import os import re +import stat from VirtualMailManager import ENCODING from VirtualMailManager.constants import \ @@ -39,16 +40,15 @@ return unicode(string, ENCODING, 'replace') -def is_dir(path): - """Checks if `path` is a directory. - - Throws a `VMMError` if `path` is not a directory. +def lisdir(path): + """Checks if `path` is a directory. Doesn't follow symbolic links. + Returns bool. """ - path = expand_path(path) - if not os.path.isdir(path): - raise VMMError(_(u"'%s' is not a directory") % get_unicode(path), - NO_SUCH_DIRECTORY) - return path + try: + lstat = os.lstat(path) + except OSError: + return False + return stat.S_ISDIR(lstat.st_mode) def exec_ok(binary): diff -r 06c0457036a0 -r 8f8d9c4c8332 VirtualMailManager/config.py --- a/VirtualMailManager/config.py Thu Jul 29 04:01:43 2010 +0000 +++ b/VirtualMailManager/config.py Thu Jul 29 19:14:19 2010 +0000 @@ -15,7 +15,8 @@ ParsingError, RawConfigParser from cStringIO import StringIO# TODO: move interactive stff to cli -from VirtualMailManager.common import exec_ok, get_unicode, is_dir, version_hex +from VirtualMailManager.common import \ + exec_ok, expand_path, get_unicode, lisdir, version_hex from VirtualMailManager.constants import CONF_ERROR from VirtualMailManager.errors import ConfigError, VMMError from VirtualMailManager.maillocation import known_format @@ -411,6 +412,17 @@ return not errors +def is_dir(path): + """Check if the expanded path is a directory. When the expanded path + is a directory the expanded path will be returned. Otherwise a + ConfigValueError will be raised. + """ + path = expand_path(path) + if lisdir(path): + return path + raise ConfigValueError(_(u"No such directory: %s") % get_unicode(path)) + + def check_mailbox_format(format): """ Check if the mailbox format *format* is supported. When the *format* diff -r 06c0457036a0 -r 8f8d9c4c8332 VirtualMailManager/mailbox.py --- a/VirtualMailManager/mailbox.py Thu Jul 29 04:01:43 2010 +0000 +++ b/VirtualMailManager/mailbox.py Thu Jul 29 19:14:19 2010 +0000 @@ -15,7 +15,7 @@ from subprocess import Popen, PIPE from VirtualMailManager.account import Account -from VirtualMailManager.common import is_dir +from VirtualMailManager.common import lisdir from VirtualMailManager.errors import VMMError from VirtualMailManager.constants import VMM_ERROR @@ -94,8 +94,7 @@ Creates a new mailbox instance. Use one of the `Maildir`, `SingleDbox` or `MultiDbox` classes. """ - assert isinstance(account, Account) - is_dir(account.home) + assert isinstance(account, Account) and lisdir(account.home) self._user = account self._boxes = [] self._root = self._user.mail_location.directory