VirtualMailManager/Handler.py
branchv0.6.x
changeset 310 644e2cc4a441
parent 309 d21423478803
child 316 31d8931dc535
equal deleted inserted replaced
309:d21423478803 310:644e2cc4a441
   220         isdir = os.path.isdir(directory)
   220         isdir = os.path.isdir(directory)
   221         if not isdir:
   221         if not isdir:
   222             self.__warnings.append(_('No such directory: %s') % directory)
   222             self.__warnings.append(_('No such directory: %s') % directory)
   223         return isdir
   223         return isdir
   224 
   224 
   225     def __makedir(self, directory, mode=None, uid=None, gid=None):
   225     def __make_domain_dir(self, domain):
   226         if mode is None:
   226         cwd = os.getcwd()
   227             mode = self._Cfg.dget('account.directory_mode')
   227         hashdir, domdir = domain.directory.split(os.path.sep)[-2:]
   228         if uid is None:
   228         os.chdir(self._Cfg.dget('misc.base_directory'))
   229             uid = 0
   229         if not os.path.isdir(hashdir):
   230         if gid is None:
   230             os.mkdir(hashdir, 0711)
   231             gid = 0
   231             os.chown(hashdir, 0, 0)
   232         os.makedirs(directory, mode)
   232         os.mkdir(os.path.join(hashdir, domdir),
   233         os.chown(directory, uid, gid)
   233                  self._Cfg.dget('domain.directory_mode'))
   234 
   234         os.chown(domain.directory, 0, domain.gid)
   235     def __domDirMake(self, domdir, gid):
   235         os.chdir(cwd)
   236         #TODO: clenaup!
       
   237         os.umask(0006)
       
   238         oldpwd = os.getcwd()
       
   239         basedir = self._Cfg.dget('misc.base_directory')
       
   240         domdirdirs = domdir.replace(basedir + '/', '').split('/')
       
   241 
       
   242         os.chdir(basedir)
       
   243         if not os.path.isdir(domdirdirs[0]):
       
   244             self.__makedir(domdirdirs[0], 489, 0, 0)
       
   245         os.chdir(domdirdirs[0])
       
   246         os.umask(0007)
       
   247         self.__makedir(domdirdirs[1], self._Cfg.dget('domain.directory_mode'),
       
   248                        0, gid)
       
   249         os.chdir(oldpwd)
       
   250 
   236 
   251     def __make_home(self, account):
   237     def __make_home(self, account):
   252         """Create a home directory for the new Account *account*."""
   238         """Create a home directory for the new Account *account*."""
   253         os.umask(0007)
   239         os.umask(0007)
   254         os.chdir(account.domain_directory)
   240         os.chdir(account.domain_directory)
   329                               transport=self._Cfg.dget('misc.transport')))
   315                               transport=self._Cfg.dget('misc.transport')))
   330         else:
   316         else:
   331             dom.set_transport(Transport(self._dbh, transport=transport))
   317             dom.set_transport(Transport(self._dbh, transport=transport))
   332         dom.set_directory(self._Cfg.dget('misc.base_directory'))
   318         dom.set_directory(self._Cfg.dget('misc.base_directory'))
   333         dom.save()
   319         dom.save()
   334         self.__domDirMake(dom.directory, dom.gid)
   320         self.__make_domain_dir(dom)
   335 
   321 
   336     def domainTransport(self, domainname, transport, force=None):
   322     def domainTransport(self, domainname, transport, force=None):
   337         if force is not None and force != 'force':
   323         if force is not None and force != 'force':
   338             raise DomainError(_(u"Invalid argument: ā€œ%sā€") % force,
   324             raise DomainError(_(u"Invalid argument: ā€œ%sā€") % force,
   339                 ERR.INVALID_OPTION)
   325                 ERR.INVALID_OPTION)