equal
deleted
inserted
replaced
8 Some common functions |
8 Some common functions |
9 """ |
9 """ |
10 |
10 |
11 import os |
11 import os |
12 import re |
12 import re |
|
13 import stat |
13 |
14 |
14 from VirtualMailManager import ENCODING |
15 from VirtualMailManager import ENCODING |
15 from VirtualMailManager.constants import \ |
16 from VirtualMailManager.constants import \ |
16 NOT_EXECUTABLE, NO_SUCH_BINARY, NO_SUCH_DIRECTORY |
17 NOT_EXECUTABLE, NO_SUCH_BINARY, NO_SUCH_DIRECTORY |
17 from VirtualMailManager.errors import VMMError |
18 from VirtualMailManager.errors import VMMError |
37 if isinstance(string, unicode): |
38 if isinstance(string, unicode): |
38 return string |
39 return string |
39 return unicode(string, ENCODING, 'replace') |
40 return unicode(string, ENCODING, 'replace') |
40 |
41 |
41 |
42 |
42 def is_dir(path): |
43 def lisdir(path): |
43 """Checks if `path` is a directory. |
44 """Checks if `path` is a directory. Doesn't follow symbolic links. |
44 |
45 Returns bool. |
45 Throws a `VMMError` if `path` is not a directory. |
|
46 """ |
46 """ |
47 path = expand_path(path) |
47 try: |
48 if not os.path.isdir(path): |
48 lstat = os.lstat(path) |
49 raise VMMError(_(u"'%s' is not a directory") % get_unicode(path), |
49 except OSError: |
50 NO_SUCH_DIRECTORY) |
50 return False |
51 return path |
51 return stat.S_ISDIR(lstat.st_mode) |
52 |
52 |
53 |
53 |
54 def exec_ok(binary): |
54 def exec_ok(binary): |
55 """Checks if the `binary` exists and if it is executable. |
55 """Checks if the `binary` exists and if it is executable. |
56 |
56 |