def checkPermFiles(self):
     """Check permission files"""
     checkThisFiles = [migrateGroups.fileGroups, migrateUsers.filePasswd,
                       migrateShadow.fileShadow]
     checkNewFiles = map(lambda x: pathJoin(self.prefixNewSystem,x),
                         checkThisFiles)
     parentDir = lambda x: "".join(os.path.split(x)[:-1])
     notRead = lambda x: not os.access(x, os.R_OK)
     notWrite = lambda x: not os.access(x, os.W_OK)
     filesNotRead = filter(notRead,checkThisFiles)
     if filesNotRead:
         self.printERROR(_("Failed to read files") + ": " +\
                         ", ".join(filesNotRead))
         return False
     filesNotWrite = filter(notWrite,checkNewFiles)
     if filesNotWrite:
         self.printERROR(_("Failed to write to files") + ": " +\
                         ", ".join(filesNotWrite))
         return False
     # Check permissions backup files
     checkNewBackupFiles = map(lambda x:pathJoin(self.prefixNewSystem,x+"-"),
                               checkThisFiles)
     notWriteBackup = lambda x: not os.access(x, os.W_OK) and \
                                (os.path.exists(x) or \
                                 not os.access(os.path.dirname(x), os.W_OK))
     filesNotWrite = filter(notWriteBackup, checkNewBackupFiles)
     if filesNotWrite:
         self.printERROR(_("Failed to write to files") + ": " +\
                         ", ".join(filesNotWrite))
         return False
     return True
 def getTableByChild(self,device):
     """Get table by child partitions"""
     syspath = getUdevDeviceInfo(name=device).get('DEVPATH','')
     if not syspath.startswith('/sys'):
         syspath = pathJoin('/sys',syspath)
     shortnameDevice = path.basename(device)
     childs = filter(lambda x:x.startswith(shortnameDevice),
              listDirectory(syspath))
     if childs:
         child = pathJoin(syspath,childs[0])
         return getUdevDeviceInfo(path=child).get('ID_PART_ENTRY_SCHEME','')
     return ""
 def saveNewFiles(self):
     """Save /etc/passwd /etc/group /etc/shadow to new system"""
     listFilesThisSystem = [migrateGroups.fileGroups,migrateUsers.filePasswd,
                            migrateShadow.fileShadow]
     listFiles = map(lambda x:(pathJoin(self.prefixNewSystem,x), 
                               pathJoin(self.prefixNewSystem,x+"-")),
                     listFilesThisSystem)
     listData = [self.dataGroups, self.dataUsers, self.dataShadow]
     allData = zip(listFiles,listData)
     for fileNames, data in allData:
         buff = "\n".join(map(lambda x: ":".join(x), data)) + "\n"
         for fileName in fileNames:
             FD  = open(fileName, "w+")
             FD.write(buff)
             FD.close()
Пример #4
0
 def scanProtectDirs(self, configPath):
     configFiles = []
     scanObj = scanDirectory()
     scanObj.processingFile = lambda path,prefix:configFiles.append(path) or\
                                                 True
     protectPaths = ["/etc"] + filter(lambda x: x.strip(),
                                   os.environ["CONFIG_PROTECT"].split(" "))
     configPath = os.path.realpath(configPath)
     for pPath in protectPaths:
         realPath = pathJoin(configPath, pPath)
         if os.path.exists(realPath):
             scanObj.scanningDirectory(realPath)
     configFiles = map(lambda x: x.partition(configPath)[2], configFiles)
     configFiles = map(lambda x: pathJoin('/',x), configFiles)
     return configFiles
 def getNewDataSystemGroups(self):
     """Get data system groups in new system"""
     fileName = pathJoin(self.prefixNewSystem, self.fileGroups)
     return filter(lambda x:\
         self._reNumb.match(x[2]) and\
         (int(x[2])>self.maxGid or int(x[2])<self.minGid),
         self.getData(fileName=fileName))
 def getNewDataSystemUsers(self):
     """Get data system users in new system"""
     fileName = pathJoin(self.prefixNewSystem, self.filePasswd)
     return filter(lambda x:\
         self._reNumb.match(x[2]) and\
         (int(x[2]>self.maxId) or int(x[2])<self.minId),
                   self.getData(fileName=fileName))
Пример #7
0
    def createDir(self, configPath, dstDir):
        """Создание директории в случае необходимости"""
        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
 def __init__(self, sysThisMigrateUsers, sysNewMigrateUsers, newMigrateUsers,
              thisMigrateUsers, prefixNewSystem):
     self.prefixNewSystem = prefixNewSystem
     self.sysThisMigrateUsers = sysThisMigrateUsers
     self.sysNewMigrateUsers = sysNewMigrateUsers
     self.newMigrateUsers = newMigrateUsers
     self.thisMigrateUsers = thisMigrateUsers
     self.newFileName = pathJoin(self.prefixNewSystem, self.fileShadow)
Пример #9
0
 def get_os_builder_linux_filesnum(self):
     """Files number in image system"""
     if self.Get('cl_builder_tree') == 'off':
         sourceDirectory = self.Get('cl_builder_path')
         portagePath = pathJoin(sourceDirectory,"usr/portage")
         overlayPath = pathJoin(sourceDirectory,"var/lib/layman/calculate")
         excludeCount = \
               reduce(lambda x,y:x + y,
               map(countFiles,
               map(lambda x: path.join(sourceDirectory,"var/lib/layman/calculate",x),
               filter(lambda x: not x in ("distfiles", "eclass", ".git","profiles"),
               listDirectory(overlayPath))) + \
               map(lambda x: path.join(sourceDirectory,"usr/portage",x),
               filter(lambda x: not x in ("distfiles", "eclass", ".git","profiles"),
               listDirectory(portagePath)))),0)
     else:
         excludeCount = 0
     systemRoot = self.Get('cl_builder_path')
     return str(countFiles(systemRoot)-excludeCount)
Пример #10
0
 def get_cl_builder_cdname(self):
     """Cd size specified by name (DVD/CD)"""
     squashfile = pathJoin(self.Get('cl_builder_iso_path'),
                            self.Get('cl_builder_current_squash'))
     kernelfile = pathJoin(self.Get('cl_builder_iso_path'),
                           self.Get('cl_builder_squash_path'),
                           'boot',
                           self.Get('cl_builder_kernel'))
     initrdfile = pathJoin(self.Get('cl_builder_iso_path'),
                           self.Get('cl_builder_squash_path'),
                           'boot',
                           self.Get('cl_builder_initrd_install'))
     if os.access(squashfile,R_OK) and os.access(kernelfile,R_OK) and \
         os.access(initrdfile,R_OK):
         isosize = path.getsize(squashfile)+path.getsize(kernelfile)+ \
                     path.getsize(initrdfile)+2*1024*1024
         if isosize > 700*1024*1024:
             return "DVD"
         else:
             return "CD"
     return ""
Пример #11
0
 def __getPathCalculateIni(self, location):
     """Получить путь к ini файлу по алиасу пути"""
     retData = self.Get("cl_env_data")
     ini_dict = {}
     ini_dict.update(retData)
     if location in ini_dict.keys():
         name_calculate_ini = ini_dict[location]
     else:
         cl_overriding.printERROR(
             _("Unable to find alias '%s' of the path to the file " "storing template variables templates")
             % location
         )
         cl_overriding.exit(1)
     return pathJoin(self.Get("cl_chroot_path"), name_calculate_ini)
 def checkAtom(self,atom):
     """Chech if atom is installed"""
     dbPkg = '/var/db/pkg'
     if "/" in atom:
         category,slash,package = atom.partition("/")
         categoryPath = pathJoin(dbPkg,category)
         return \
               map(lambda x:"%s/%s"%(category,x.groups()[0]),
               filter(lambda x:x and x.groups()[0] == package,
               map(self.reVerSplit.search, 
               filter(lambda x:x.startswith(package),
               listDirectory(categoryPath)))))
     else:
         return reduce(lambda x,y:x+self.checkAtom("%s/%s"%(y,atom)),
                listDirectory(dbPkg),[])
Пример #13
0
 def copyConfigFiles(self, configPath):
     """Копирование конфигурационных файлов"""
     configDstFiles = self.scanProtectDirs(configPath)
     if configDstFiles:
         self.logger.warn(_("Replaced files:"))
     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
Пример #14
0
 def getNewData(self):
     """Get data migrate groups in new system"""
     fileName = pathJoin(self.prefixNewSystem, self.fileGroups)
     return filter(lambda x:\
         self._reNumb.match(x[2]) and self.minGid<=int(x[2])<=self.maxGid,
                   self.getData(fileName=fileName))
Пример #15
0
 def createHome(userdata):
     if not userdata[5].startswith('/dev/'):
         homedir = pathJoin(self.prefixNewSystem,userdata[5])
         if not path.exists(homedir):
             os.mkdir(homedir)
             os.chown(homedir,int(userdata[2]),int(userdata[3]))
Пример #16
0
 def getNewData(self):
     """Get data migrate users in new system"""
     fileName = pathJoin(self.prefixNewSystem, self.filePasswd)
     return filter(lambda x:\
         self._reNumb.match(x[2]) and self.minId<=int(x[2])<=self.maxId,
                   self.getData(fileName=fileName))