VirtualMailManager/VirtualMailManager.py
changeset 40 ab0748a5da9a
parent 38 c44ea4526546
child 44 c9ab6900ede9
equal deleted inserted replaced
39:8dcf739fc97e 40:ab0748a5da9a
   245         """Estimate file space usage for the given directory.
   245         """Estimate file space usage for the given directory.
   246         
   246         
   247         Keyword arguments:
   247         Keyword arguments:
   248         directory -- the directory to summarize recursively disk usage for
   248         directory -- the directory to summarize recursively disk usage for
   249         """
   249         """
   250         return Popen([self.__Cfg.get('bin', 'du'), "-hs", directory],
   250         if self.__isdir(directory):
       
   251             return Popen([self.__Cfg.get('bin', 'du'), "-hs", directory],
   251                 stdout=PIPE).communicate()[0].split('\t')[0]
   252                 stdout=PIPE).communicate()[0].split('\t')[0]
       
   253         else:
       
   254             return 0
       
   255 
       
   256     def __isdir(self, directory):
       
   257         isdir = os.path.isdir(directory)
       
   258         if not isdir:
       
   259             self.__warnings.append(_('No such directory: %s') % directory)
       
   260         return isdir
   252 
   261 
   253     def __makedir(self, directory, mode=None, uid=None, gid=None):
   262     def __makedir(self, directory, mode=None, uid=None, gid=None):
   254         if mode is None:
   263         if mode is None:
   255             mode = self.__Cfg.getint('maildir', 'mode')
   264             mode = self.__Cfg.getint('maildir', 'mode')
   256         if uid is None:
   265         if uid is None:
   314                     if (mdstat.st_uid, mdstat.st_gid) != (uid, gid):
   323                     if (mdstat.st_uid, mdstat.st_gid) != (uid, gid):
   315                         raise VMMException((
   324                         raise VMMException((
   316                            _('FATAL: owner/group mismatch in maildir detected'),
   325                            _('FATAL: owner/group mismatch in maildir detected'),
   317                            ERR.MAILDIR_PERM_MISMATCH))
   326                            ERR.MAILDIR_PERM_MISMATCH))
   318                     rmtree(maildir, ignore_errors=True)
   327                     rmtree(maildir, ignore_errors=True)
       
   328                 else:
       
   329                     self.__warnings.append(_('No such directory: %s/%s') %
       
   330                             (domdir,uid))
   319 
   331 
   320     def __domdirdelete(self, domdir, gid):
   332     def __domdirdelete(self, domdir, gid):
   321         if gid > 0:
   333         if gid > 0:
       
   334             if not self.__isdir(domdir):
       
   335                 return
   322             basedir = '%s' % self.__Cfg.get('domdir', 'base')
   336             basedir = '%s' % self.__Cfg.get('domdir', 'base')
   323             domdirdirs = domdir.replace(basedir+'/', '').split('/')
   337             domdirdirs = domdir.replace(basedir+'/', '').split('/')
   324             if basedir.count('..') or domdir.count('..'):
   338             if basedir.count('..') or domdir.count('..'):
   325                 raise VMMException(
   339                 raise VMMException(
   326                         (_('FATAL: ".." in domain directory path detected.'),
   340                         (_('FATAL: ".." in domain directory path detected.'),
   399         return bool(len(self.__warnings))
   413         return bool(len(self.__warnings))
   400 
   414 
   401     def getWarnings(self):
   415     def getWarnings(self):
   402         """Returns a list with all available warnings."""
   416         """Returns a list with all available warnings."""
   403         return self.__warnings
   417         return self.__warnings
       
   418 
       
   419     def cfgGetBoolean(self, section, option):
       
   420         return self.__Cfg.getboolean(section, option)
       
   421 
       
   422     def cfgGetInt(self, section, option):
       
   423         return self.__Cfg.getint(section, option)
       
   424 
       
   425     def cfgGetString(self, section, option):
       
   426         return self.__Cfg.get(section, option)
   404 
   427 
   405     def setupIsDone(self):
   428     def setupIsDone(self):
   406         """Checks if vmm is configured, returns bool"""
   429         """Checks if vmm is configured, returns bool"""
   407         try:
   430         try:
   408             return self.__Cfg.getboolean('config', 'done')
   431             return self.__Cfg.getboolean('config', 'done')