Example #1
0
 def isAvailableAinstRoot(self):
     if not file_util.isDir(self._root):
         return True
     subDirs = file_util.listDir(self._root)
     if subDirs is not None and len(subDirs) == 0:
         return True
     return self.isValidAinstRoot()
Example #2
0
    def init(self):
        if self._inited:
            return True, None

        if not self._root:
            return False, None

        markFilePath = self._root + '/' + self._ainstRootMarkFile
        initTrace = []
        if not file_util.isDir(self._root):
            if not file_util.makeDir(self._root):
                self.clearInit(initTrace)
                return False, None
            initTrace.append(self._root)
            if not file_util.writeToFile(markFilePath, ''):
                self.clearInit(initTrace)
                return False, None
            initTrace.append(markFilePath)
        else:
            if not file_util.isFile(markFilePath):
                subDirs = file_util.listDir(self._root)
                if subDirs and len(subDirs) > 0:
                    self.clearInit(initTrace)
                    return False, None
                if not file_util.writeToFile(markFilePath, ''):
                    self.clearInit(initTrace)
                    return False, None
                initTrace.append(markFilePath)

        if not self._initRoot(initTrace):
            return False, None
        os.environ[self._installRootEnvKey] = self._root
        self._inited = True
        return True, initTrace
Example #3
0
 def getInstallPackages(self):
     installPkgs = []
     installDir = self._ainstRoot.getRootVarAinstDir('packages')
     subDirs = file_util.listDir(installDir)
     if subDirs:
         for subDir in subDirs:
             if file_util.isDir(installDir + subDir):
                 installPkgs.append(subDir)
     return installPkgs
Example #4
0
 def _getRepoFileList(self, reposdir):
     repoFileList = []
     for repodir in reposdir:
         if not file_util.exists(repodir):
             continue
         files = file_util.listDir(repodir)
         if files:
             for fileName in files:
                 if fileName.endswith('.repo'):
                     repoFileList.append(repodir + '/' + fileName)
     return repoFileList
Example #5
0
 def _getRepoFileList(self, reposdir):
     repoFileList = []
     for repodir in reposdir:
         if not file_util.exists(repodir):
             continue
         files = file_util.listDir(repodir)
         if files:
             for fileName in files:
                 if fileName.endswith('.repo'):
                     repoFileList.append(repodir + '/' + fileName)
     return repoFileList
Example #6
0
 def _getRootStateNumberList(self):
     numberList = []
     saveDir = self._ainstRoot.getRootVarAinstDir('save')
     subDirs = file_util.listDir(saveDir)
     pattern = re.compile(self._filePrefix + '(\d+)')
     if not subDirs:
         return numberList
     for subDir in subDirs:
         match = pattern.match(subDir)
         if match:
             numberList.append(int(match.group(1)))
     numberList.sort()
     return numberList
Example #7
0
 def getInstallPkgMetas(self):
     'return list [(pkgVer, rpmFilePath)]'
     installPkgMetas = []
     pkgDir = self._ainstRoot.getRootVarAinstDir('packages')
     subDirs = file_util.listDir(pkgDir)
     if subDirs is None:
         return None
     for subDir in subDirs:
         pkgPath = pkgDir + subDir
         if file_util.isDir(pkgPath):
             rpmPath = pkgPath + self._ainstRoot.getBackRpmPath()
             installPkgMetas.append((subDir, rpmPath))
     return installPkgMetas
Example #8
0
 def getActivePackages(self):
     'return list [(pkg, pkg-version, mtime)]'
     activePkgs = []
     activeDir = self._ainstRoot.getRootVarAinstDir('active')
     subDirs = file_util.listDir(activeDir)
     if not subDirs:
         return activePkgs
     for subDir in subDirs:
         subDirPath = activeDir + '/' + subDir
         linkPath = file_util.readLink(subDirPath)
         if linkPath and linkPath.startswith('../packages/'):
             packageName = os.path.basename(linkPath)
             mtime = os.lstat(subDirPath).st_mtime
             activePkgs.append((subDir, packageName, mtime))
     return activePkgs
Example #9
0
 def getPkgCrontabs(self):
     pkgCrontabs = {}
     crontabDir = self._ainstRoot.getRootVarDir('cron')
     activeDir = self._ainstRoot.getRootVarAinstDir('active')
     cronFiles = file_util.listDir(crontabDir)
     if not cronFiles:
         return pkgCrontabs
     for cronFile in cronFiles:
         activePath = activeDir + '/' + cronFile
         linkPath = file_util.readLink(activePath)
         if linkPath and linkPath.startswith('../packages/'):
             cronFilePath = crontabDir + '/' + cronFile
             content = file_util.readFromFile(cronFilePath)
             if content:
                 pkgCrontabs[cronFile] = content
     return pkgCrontabs
Example #10
0
 def _initLocalRepos(self, repoSack, localRepos):
     if not localRepos:
         return True
     if not repoSack:
         repoSack = MultiPackageSack()
     for local in localRepos:
         fileNames = file_util.listDir(local)
         if not fileNames:
             continue
         pkgSack = PackageSack()
         for name in fileNames:
             path = local + '/' + name
             pkg = LocalRpmPackage(path)
             if pkg.init():
                 pkgSack.addPackageObject(pkg)
         repoSack.addPackageSack(local, pkgSack)
     return True
Example #11
0
 def _initLocalRepos(self, repoSack, localRepos):
     if not localRepos:
         return True
     if not repoSack:
         repoSack = MultiPackageSack()
     for local in localRepos:
         fileNames = file_util.listDir(local)
         if not fileNames:
             continue
         pkgSack = PackageSack()
         for name in fileNames:
             path = local + "/" + name
             pkg = LocalRpmPackage(path)
             if pkg.init():
                 pkgSack.addPackageObject(pkg)
         repoSack.addPackageSack(local, pkgSack)
     return True
Example #12
0
 def getActivePkgMetas(self):
     'return list [(pkg, rpmFilePath, aicfFilePath)]'
     activePkgMetas = []
     activeDir = self._ainstRoot.getRootVarAinstDir('active')
     subDirs = file_util.listDir(activeDir)
     if subDirs is None:
         return None
     for subDir in subDirs:
         subDirPath = activeDir + '/' + subDir
         linkPath = file_util.readLink(subDirPath)
         if linkPath and linkPath.startswith('../packages/'):
             pkgPath = self._ainstRoot.getRootVarAinstDir('packages') +\
                 os.path.basename(linkPath) 
             rpmPath = pkgPath + self._ainstRoot.getBackRpmPath()
             aicfFile = pkgPath + '/ainst/' + subDir + '.aicf'
             activePkgMetas.append((subDir, rpmPath, aicfFile))
     return activePkgMetas
Example #13
0
 def getPkgSettings(self, pkgs=None):
     pkgSettings = {}
     if pkgs is None:
         pkgs = [x for x, y, z in self.getActivePackages()]
     if not pkgs:
         return pkgSettings
     settingsDir = self._ainstRoot.getRootVarAinstDir('settings')
     subDirs = file_util.listDir(settingsDir)
     if not subDirs:
         return pkgSettings
     streamer = SettingStreamer()
     for subDir in subDirs:
         if subDir in pkgs:
             subDirPath = settingsDir + '/' + subDir
             settingMap = streamer.parse(subDirPath)
             if settingMap:
                 pkgSettings[subDir] = settingMap
     return pkgSettings
 def _removeDir(self, dirName, rmdirList, recursive=True):
     if not dirName or not dirName.startswith(self._ainstRoot.getRoot()):
         Log.cout(Log.ERROR, 'Remove invalid path %s' % dirName)
         return False
     if dirName[-1] != '/':
         dirName += '/'
     if self._ainstRoot.isAinstDir(dirName):
         Log.cout(Log.DEBUG, 'Ainst root path %s need not remove' % dirName)
         return True
     subDirs = file_util.listDir(dirName)
     if subDirs is not None and len(subDirs) == 0:
         if not file_util.remove(dirName):
             Log.cout(Log.ERROR, 'Remove dir %s failed' % dirName)
             return False
         rmdirList.append(dirName)
         if recursive:
             dirPath = os.path.dirname(dirName[:-1])
             return self._removeDir(dirPath, rmdirList, recursive)
     return True