VirtualMailManager/VirtualMailManager.py
changeset 40 ab0748a5da9a
parent 38 c44ea4526546
child 44 c9ab6900ede9
--- a/VirtualMailManager/VirtualMailManager.py	Tue Jun 17 00:37:23 2008 +0000
+++ b/VirtualMailManager/VirtualMailManager.py	Wed Aug 06 22:11:17 2008 +0000
@@ -247,8 +247,17 @@
         Keyword arguments:
         directory -- the directory to summarize recursively disk usage for
         """
-        return Popen([self.__Cfg.get('bin', 'du'), "-hs", directory],
+        if self.__isdir(directory):
+            return Popen([self.__Cfg.get('bin', 'du'), "-hs", directory],
                 stdout=PIPE).communicate()[0].split('\t')[0]
+        else:
+            return 0
+
+    def __isdir(self, directory):
+        isdir = os.path.isdir(directory)
+        if not isdir:
+            self.__warnings.append(_('No such directory: %s') % directory)
+        return isdir
 
     def __makedir(self, directory, mode=None, uid=None, gid=None):
         if mode is None:
@@ -316,9 +325,14 @@
                            _('FATAL: owner/group mismatch in maildir detected'),
                            ERR.MAILDIR_PERM_MISMATCH))
                     rmtree(maildir, ignore_errors=True)
+                else:
+                    self.__warnings.append(_('No such directory: %s/%s') %
+                            (domdir,uid))
 
     def __domdirdelete(self, domdir, gid):
         if gid > 0:
+            if not self.__isdir(domdir):
+                return
             basedir = '%s' % self.__Cfg.get('domdir', 'base')
             domdirdirs = domdir.replace(basedir+'/', '').split('/')
             if basedir.count('..') or domdir.count('..'):
@@ -402,6 +416,15 @@
         """Returns a list with all available warnings."""
         return self.__warnings
 
+    def cfgGetBoolean(self, section, option):
+        return self.__Cfg.getboolean(section, option)
+
+    def cfgGetInt(self, section, option):
+        return self.__Cfg.getint(section, option)
+
+    def cfgGetString(self, section, option):
+        return self.__Cfg.get(section, option)
+
     def setupIsDone(self):
         """Checks if vmm is configured, returns bool"""
         try: