cwconfig.py
branchstable
changeset 8484 4c1efb5bde0a
parent 8477 42e8755b3aba
child 8537 e30d0a7f0087
equal deleted inserted replaced
8482:0044a29ea118 8484:4c1efb5bde0a
   169 __docformat__ = "restructuredtext en"
   169 __docformat__ = "restructuredtext en"
   170 _ = unicode
   170 _ = unicode
   171 
   171 
   172 import sys
   172 import sys
   173 import os
   173 import os
       
   174 import stat
   174 import logging
   175 import logging
   175 import logging.config
   176 import logging.config
   176 from smtplib import SMTP
   177 from smtplib import SMTP
   177 from threading import Lock
   178 from threading import Lock
   178 from os.path import (exists, join, expanduser, abspath, normpath,
   179 from os.path import (exists, join, expanduser, abspath, normpath,
  1074         server process and is writeable.
  1075         server process and is writeable.
  1075 
  1076 
  1076         If not, try to fix this, letting exception propagate when not possible.
  1077         If not, try to fix this, letting exception propagate when not possible.
  1077         """
  1078         """
  1078         if not exists(path):
  1079         if not exists(path):
  1079             os.makedirs(path)
  1080             self.info('creating %s directory', path)
       
  1081             try:
       
  1082                 os.makedirs(path)
       
  1083             except OSError, ex:
       
  1084                 self.warning('error while creating %s directory: %s', path, ex)
       
  1085                 return
  1080         if self['uid']:
  1086         if self['uid']:
  1081             try:
  1087             try:
  1082                 uid = int(self['uid'])
  1088                 uid = int(self['uid'])
  1083             except ValueError:
  1089             except ValueError:
  1084                 from pwd import getpwnam
  1090                 from pwd import getpwnam
  1088                 uid = os.getuid()
  1094                 uid = os.getuid()
  1089             except AttributeError: # we are on windows
  1095             except AttributeError: # we are on windows
  1090                 return
  1096                 return
  1091         fstat = os.stat(path)
  1097         fstat = os.stat(path)
  1092         if fstat.st_uid != uid:
  1098         if fstat.st_uid != uid:
  1093             os.chown(path, uid, os.getgid())
  1099             self.info('giving ownership of %s directory to %s', path, self['uid'])
  1094         import stat
  1100             try:
       
  1101                 os.chown(path, uid, os.getgid())
       
  1102             except OSError, ex:
       
  1103                 self.warning('error while giving ownership of %s directory to %s: %s',
       
  1104                              path, self['uid'], ex)
  1095         if not (fstat.st_mode & stat.S_IWUSR):
  1105         if not (fstat.st_mode & stat.S_IWUSR):
  1096             os.chmod(path, fstat.st_mode | stat.S_IWUSR)
  1106             self.info('forcing write permission on directory %s', path)
       
  1107             try:
       
  1108                 os.chmod(path, fstat.st_mode | stat.S_IWUSR)
       
  1109             except OSError, ex:
       
  1110                 self.warning('error while forcing write permission on directory %s: %s',
       
  1111                              path, ex)
       
  1112                 return
  1097 
  1113 
  1098     @cached
  1114     @cached
  1099     def instance_md5_version(self):
  1115     def instance_md5_version(self):
  1100         from hashlib import md5 # pylint: disable=E0611
  1116         from hashlib import md5 # pylint: disable=E0611
  1101         infos = []
  1117         infos = []