Exemplo n.º 1
0
 def copyDirOrFile(self, src, dst, configPath):
     if src != dst:
         if os.path.isfile(src):
             dstDir = os.path.dirname(dst)
             self.createDir(configPath, dstDir)
             copy2(src, dst)
             sMode, sUid, sGid = getModeFile(src)
             os.chown(dst, sUid, sGid)
             os.chmod(dst, sMode)
         elif os.path.isdir(src):
             self.createDir(configPath, dst)
             sMode, sUid, sGid = getModeFile(src)
             os.chown(dst, sUid, sGid)
             os.chmod(dst, sMode)
Exemplo n.º 2
0
    def createDir(self, configPath, dstDir):
        """Create need dirs"""
        if os.path.exists(dstDir):
            return True

        def splPath(path):
            listPath = []
            if path in ("", "/"):
                return []
            base, p = os.path.split(path)
            listPath.append(p)
            while not base in ("", "/"):
                base, p = os.path.split(base)
                listPath.append(p)
            listPath.reverse()
            return listPath

        notFoundPaths = []
        path = "/"
        for p in splPath(dstDir):
            path = os.path.join(path, p)
            if not os.path.exists(path):
                notFoundPaths.append(path)
        for mkPath in notFoundPaths:
            srcPath = pathJoin(configPath, mkPath)
            dMode, dUid, dGid = getModeFile(srcPath)
            os.mkdir(mkPath, dMode)
            os.chown(mkPath, dUid, dGid)
        return True
Exemplo n.º 3
0
 def save(self):
     path = os.path.dirname(self.fileName)
     if not os.path.exists(path):
         try:
             os.makedirs(path)
         except:
             self.printERROR(_("Failed to create directory %s")%path)
             return False
     if not os.path.exists(self.fileName):
         try:
             open(self.fileName, "w")
         except:
             self.printERROR(_("Failed to create file %s")%self.fileName)
             return False
     if self.getFileAccess(perm="WRITE"):
         modeFile = 0600
         if getModeFile(self.fileName, mode="mode") != modeFile:
             os.chmod(self.fileName, modeFile)
         buff = "\n".join(map(lambda x: ":".join(x), self.data)) + "\n"
         FD  = open(self.fileName, "w+")
         FD.write(buff)
         FD.close()
         return True
     else:
         return False
Exemplo n.º 4
0
 def copyConfigFiles(self, configPath, configProtect):
     """Копирование конфигурационных файлов"""
     configDstFiles = self.scanProtectDirs(configPath, configProtect)
     if configDstFiles:
         self.logger.warn(_("Replaced file:"))
     for dst in configDstFiles:
         src = pathJoin(configPath, dst)
         if src != dst:
             dstDir = os.path.dirname(dst)
             self.createDir(configPath, dstDir)
             copy2(src, dst)
             sMode, sUid, sGid = getModeFile(src)
             os.chown(dst, sUid, sGid)
             os.chmod(dst, sMode)
             self.logger.warn(" " * 5 + dst)
     return True