Exemplo n.º 1
0
    def buildMultiRootContext(self,
                              installRoots,
                              ainstConf,
                              useRepo=False,
                              repos=[]):
        repoSack = None
        if useRepo:
            repoSack = self._initRepos(ainstConf, repos)
            if repoSack is None:
                return None

        rootSack = None
        localSack = MultiPackageSack()
        for installRoot in installRoots:
            if installRoot == '/':
                rootSack = RPMDBPackageSack('/')
            else:
                sack = AinstPackageSackBuilder(
                    installRoot).buildActivePkgSack()
                if sack is None:
                    Log.cout(
                        Log.DEBUG,
                        'Build active pkg sack of %s failed' % installRoot)
                    continue
                localSack.addPackageSack(installRoot, sack)
        return AinstMultiRootContext(rootSack, localSack, repoSack)
Exemplo n.º 2
0
 def _initPackageSack(self):
     repoList = self.getEnabledRepo()
     self.packageSack = MultiPackageSack()
     for repo in repoList:
         packageSack = repo.getPackageSack()
         if packageSack:
             self.packageSack.addPackageSack(repo.id, packageSack)
Exemplo n.º 3
0
 def _initPackageSack(self):
     repoList = self.getEnabledRepo()
     self.packageSack = MultiPackageSack()
     for repo in repoList:
         packageSack = repo.getPackageSack()
         if packageSack:
             self.packageSack.addPackageSack(repo.id, packageSack)
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
0
    def buildMultiRootContext(self, installRoots, ainstConf, useRepo=False, repos=[]):
        repoSack = None
        if useRepo:
            repoSack = self._initRepos(ainstConf, repos)
            if repoSack is None:
                return None

        rootSack = None
        localSack = MultiPackageSack()
        for installRoot in installRoots:
            if installRoot == "/":
                rootSack = RPMDBPackageSack("/")
            else:
                sack = AinstPackageSackBuilder(installRoot).buildActivePkgSack()
                if sack is None:
                    Log.cout(Log.DEBUG, "Build active pkg sack of %s failed" % installRoot)
                    continue
                localSack.addPackageSack(installRoot, sack)
        return AinstMultiRootContext(rootSack, localSack, repoSack)
Exemplo n.º 7
0
    def buildAinstContext(
        self,
        installRoot,
        ainstConf,
        useRepo=True,
        repos=[],
        localRepos=[],
        localRoots=None,
        localActivePkgs=None,
        localDeactivePkgs=None,
    ):
        repoSack = None
        if useRepo:
            repoSack = self._initRepos(ainstConf, repos)
            self._initLocalRepos(repoSack, localRepos)
            self._initInstallRootRepos(repoSack, installRoot)
            if repoSack is None:
                return None

        rootSack = RPMDBPackageSack("/")
        localSacks = MultiPackageSack()
        if installRoot == "/":
            if localRoots:
                for localRoot in localRoots:
                    builder = AinstPackageSackBuilder(localRoot)
                    sack = builder.buildActivePkgSack()
                    if sack is None:
                        Log.cout(Log.DEBUG, "Build active pkg sack of %s failed" % localRoot)
                        continue
                    localSacks.addPackageSack(localRoot, sack)
        else:
            builder = AinstPackageSackBuilder(installRoot)
            sack = builder.buildActivePkgSack()
            if sack is None:
                Log.cout(Log.DEBUG, "Build active pkg sack of %s failed" % installRoot)
            else:
                localSacks.addPackageSack(installRoot, sack)
            self._addFakeLocalInstallPkgs(localActivePkgs, installRoot, localSacks)
            if not self._removeWillDeactivePkgs(localSacks, localDeactivePkgs):
                return None
        return AinstContextImpl(installRoot, repoSack, rootSack, localSacks)
Exemplo n.º 8
0
    def buildAinstContext(self,
                          installRoot,
                          ainstConf,
                          useRepo=True,
                          repos=[],
                          localRepos=[],
                          localRoots=None,
                          localActivePkgs=None,
                          localDeactivePkgs=None):
        repoSack = None
        if useRepo:
            repoSack = self._initRepos(ainstConf, repos)
            self._initLocalRepos(repoSack, localRepos)
            self._initInstallRootRepos(repoSack, installRoot)
            if repoSack is None:
                return None

        rootSack = RPMDBPackageSack('/')
        localSacks = MultiPackageSack()
        if installRoot == '/':
            if localRoots:
                for localRoot in localRoots:
                    builder = AinstPackageSackBuilder(localRoot)
                    sack = builder.buildActivePkgSack()
                    if sack is None:
                        Log.cout(
                            Log.DEBUG,
                            'Build active pkg sack of %s failed' % localRoot)
                        continue
                    localSacks.addPackageSack(localRoot, sack)
        else:
            builder = AinstPackageSackBuilder(installRoot)
            sack = builder.buildActivePkgSack()
            if sack is None:
                Log.cout(Log.DEBUG,
                         'Build active pkg sack of %s failed' % installRoot)
            else:
                localSacks.addPackageSack(installRoot, sack)
            self._addFakeLocalInstallPkgs(localActivePkgs, installRoot,
                                          localSacks)
            if not self._removeWillDeactivePkgs(localSacks, localDeactivePkgs):
                return None
        return AinstContextImpl(installRoot, repoSack, rootSack, localSacks)
Exemplo n.º 9
0
class RepoStorage:
    def __init__(self):
        self.repoDict = {}
        self.packageSack = None

    def addRepo(self, repo):
        if self.repoDict.has_key(repo.id):
            return False
        self.repoDict[repo.id] = repo

    def deleteRepo(self, repoid):
        if self.repoDict.has_key(repoid):
            del self.repoDict[repoid]

    def getRepo(self, repoid):
        if self.repoDict.has_key(repoid):
            return self.repoDict[repoid]
        return None

    def enableRepo(self, repoid):
        pattern = re.compile(fnmatch.translate(repoid))
        for key in self.repoDict:
            if pattern.match(key):
                self.repoDict[key].enable()

    def disableRepo(self, repoid):
        pattern = re.compile(fnmatch.translate(repoid))
        for key in self.repoDict:
            if pattern.match(key):
                self.repoDict[key].disable()

    def getEnabledRepo(self):
        repoList = []
        for repo in self.repoDict.values():
            if repo.isEnabled():
                repoList.append(repo)
        repoList.sort()
        return repoList

    def processDisableEnable(self, repos):
        if not repos:
            return True
        for repoItem in repos:
            for key, value in repoItem.items():
                if key == 'disable':
                    self.disableRepo(value)
                elif key == 'enable':
                    self.enableRepo(value)
        return True

    def makeCache(self):
        repoList = self.getEnabledRepo()
        for repo in repoList:
            if not repo.makeCache():
                Log.coutValue(Log.INFO, repo.id, 'failed')
            else:
                Log.coutValue(Log.INFO, repo.id, 'success')
        return True

    def clearCache(self):
        repoList = self.getEnabledRepo()
        for repo in repoList:
            if not repo.clearCache():
                Log.coutValue(Log.INFO, repo.id, 'failed')
                self._consoleLogger.error(log)
            else:
                Log.coutValue(Log.INFO, repo.id, 'success')
        return True

    def getPackageSack(self):
        if not self.packageSack:
            self._initPackageSack()
        return self.packageSack

    def _initPackageSack(self):
        repoList = self.getEnabledRepo()
        self.packageSack = MultiPackageSack()
        for repo in repoList:
            packageSack = repo.getPackageSack()
            if packageSack:
                self.packageSack.addPackageSack(repo.id, packageSack)

    def populateSack(self, metaType):
        packageSack = self.getPackageSack()
        packageSack.populate(metaType)
Exemplo n.º 10
0
class RepoStorage:
    def __init__(self):
        self.repoDict = {}
        self.packageSack = None
        
    def addRepo(self, repo):
        if self.repoDict.has_key(repo.id):
            return False
        self.repoDict[repo.id] = repo

    def deleteRepo(self, repoid):
        if self.repoDict.has_key(repoid):
            del self.repoDict[repoid]

    def getRepo(self, repoid):
        if self.repoDict.has_key(repoid):
            return self.repoDict[repoid]
        return None

    def enableRepo(self, repoid):
        pattern = re.compile(fnmatch.translate(repoid))
        for key in self.repoDict:
            if pattern.match(key):
                self.repoDict[key].enable()

    def disableRepo(self, repoid):
        pattern = re.compile(fnmatch.translate(repoid))
        for key in self.repoDict:
            if pattern.match(key):
                self.repoDict[key].disable()

    def getEnabledRepo(self):
        repoList = []
        for repo in self.repoDict.values():
            if repo.isEnabled():
                repoList.append(repo)
        repoList.sort()
        return repoList

    def processDisableEnable(self, repos):
        if not repos:
            return True
        for repoItem in repos:
            for key, value in repoItem.items():
                if key == 'disable':
                    self.disableRepo(value)
                elif key == 'enable':
                    self.enableRepo(value)
        return True

    def makeCache(self):
        repoList = self.getEnabledRepo()
        for repo in repoList:
            if not repo.makeCache():
                Log.coutValue(Log.INFO, repo.id, 'failed')
            else:
                Log.coutValue(Log.INFO, repo.id, 'success')
        return True

    def clearCache(self):
        repoList = self.getEnabledRepo()
        for repo in repoList:
            if not repo.clearCache():
                Log.coutValue(Log.INFO, repo.id, 'failed')
                self._consoleLogger.error(log)
            else:
                Log.coutValue(Log.INFO, repo.id, 'success')
        return True

    def getPackageSack(self):
        if not self.packageSack:
            self._initPackageSack()
        return self.packageSack

    def _initPackageSack(self):
        repoList = self.getEnabledRepo()
        self.packageSack = MultiPackageSack()
        for repo in repoList:
            packageSack = repo.getPackageSack()
            if packageSack:
                self.packageSack.addPackageSack(repo.id, packageSack)

    def populateSack(self, metaType):
        packageSack = self.getPackageSack()
        packageSack.populate(metaType)