コード例 #1
0
ファイル: repositories.py プロジェクト: baiyuanlab/kimchi
 def _get_repos(self, errcode):
     try:
         kimchiLock.acquire()
         repos = get_yum_repositories()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed(errcode, {'err': str(e)})
コード例 #2
0
ファイル: repositories.py プロジェクト: zofuthan/kimchi
    def updateRepo(self, repo_id, params):
        """
        Update a given repository in repositories.Repositories() format
        """
        kimchiLock.acquire()
        repos = self._get_repos('KCHREPOS0011E')
        kimchiLock.release()
        if repo_id not in repos.repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        config = params.get('config', {})
        entry = repos.getRepo(repo_id)

        baseurl = params.get('baseurl', None)
        mirrorlist = config.get('mirrorlist', None)

        if baseurl is not None:
            validate_repo_url(baseurl)
            entry.baseurl = baseurl

        if mirrorlist == '':
            mirrorlist = None

        if mirrorlist is not None:
            validate_repo_url(mirrorlist)
            entry.mirrorlist = mirrorlist

        entry.id = params.get('repo_id', repo_id)
        entry.name = config.get('repo_name', entry.name)
        entry.gpgcheck = config.get('gpgcheck', entry.gpgcheck)
        entry.gpgkey = config.get('gpgkey', entry.gpgkey)
        kimchiLock.acquire()
        self._conf.writeRawRepoFile(entry)
        kimchiLock.release()
        return repo_id
コード例 #3
0
ファイル: repositories.py プロジェクト: baiyuanlab/kimchi
    def toggleRepo(self, repo_id, enable):
        repos = self._get_repos('KCHREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.get(repo_id)
        if enable and entry.enabled:
            raise InvalidOperation("KCHREPOS0015E", {'repo_id': repo_id})

        if not enable and not entry.enabled:
            raise InvalidOperation("KCHREPOS0016E", {'repo_id': repo_id})

        kimchiLock.acquire()
        try:
            if enable:
                entry.enable()
            else:
                entry.disable()

            write_repo_to_file(entry)
        except:
            if enable:
                raise OperationFailed("KCHREPOS0020E", {'repo_id': repo_id})

            raise OperationFailed("KCHREPOS0021E", {'repo_id': repo_id})
        finally:
            kimchiLock.release()

        return repo_id
コード例 #4
0
ファイル: repositories.py プロジェクト: SkyWei/kimchi
    def getRepo(self, repo_id):
        """
        Return a dictionary in the repositories.Repositories() of the given
        repository ID format with the information of a YumRepository object.
        """
        kimchiLock.acquire()
        repos = self._get_repos('KCHREPOS0025E')
        kimchiLock.release()

        if repo_id not in repos.repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.getRepo(repo_id)

        info = {}
        info['enabled'] = entry.enabled

        baseurl = ''
        if entry.baseurl:
            baseurl = entry.baseurl[0]

        info['baseurl'] = baseurl
        info['config'] = {}
        info['config']['repo_name'] = entry.name
        info['config']['gpgcheck'] = entry.gpgcheck
        info['config']['gpgkey'] = entry.gpgkey
        info['config']['mirrorlist'] = entry.mirrorlist or ''
        info['config']['metalink'] = entry.metalink or ''
        return info
コード例 #5
0
ファイル: repositories.py プロジェクト: wr4eng/kimchi
    def addRepo(self, params):
        """
        Add a new APT repository based on <params>
        """
        # To create a APT repository the dist is a required parameter
        # (in addition to baseurl, verified on controller through API.json)
        config = params.get('config', None)
        if config is None:
            raise MissingParameter("KCHREPOS0019E")

        if 'dist' not in config.keys():
            raise MissingParameter("KCHREPOS0019E")

        uri = params['baseurl']
        dist = config['dist']
        comps = config.get('comps', [])

        kimchiLock.acquire()
        repos = self._sourceslist()
        repos.refresh()
        source_entry = repos.add('deb', uri, dist, comps, file=self.filename)
        repos.save()
        kimchiLock.release()

        return self._get_repo_id(source_entry)
コード例 #6
0
ファイル: repositories.py プロジェクト: SkyWei/kimchi
    def addRepo(self, params):
        """
        Add a new APT repository based on <params>
        """
        # To create a APT repository the dist is a required parameter
        # (in addition to baseurl, verified on controller through API.json)
        config = params.get('config', None)
        if config is None:
            raise MissingParameter("KCHREPOS0019E")

        if 'dist' not in config.keys():
            raise MissingParameter("KCHREPOS0019E")

        uri = params['baseurl']
        dist = config['dist']
        comps = config.get('comps', [])

        validate_repo_url(uri)

        kimchiLock.acquire()
        try:
            repos = self._get_repos()
            source_entry = repos.add('deb', uri, dist, comps,
                                     file=self.filename)
            with self.pkg_lock():
                repos.save()
        except Exception as e:
            kimchiLock.release()
            raise OperationFailed("KCHREPOS0026E", {'err': e.message})
        kimchiLock.release()
        return self._get_repo_id(source_entry)
コード例 #7
0
 def _get_repos(self, errcode):
     try:
         kimchiLock.acquire()
         repos = get_yum_repositories()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed(errcode, {'err': str(e)})
コード例 #8
0
ファイル: repositories.py プロジェクト: wr4eng/kimchi
    def toggleRepo(self, repo_id, enable):
        """
        Enable a given repository
        """
        r = self._get_source_entry(repo_id)
        if r is None:
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        if enable and not r.disabled:
            raise InvalidOperation("KCHREPOS0015E", {'repo_id': repo_id})

        if not enable and r.disabled:
            raise InvalidOperation("KCHREPOS0016E", {'repo_id': repo_id})

        if enable:
            line = 'deb'
        else:
            line = '#deb'

        kimchiLock.acquire()
        try:
            repos = self._sourceslist()
            repos.refresh()
            repos.remove(r)
            repos.add(line, r.uri, r.dist, r.comps, file=self.filename)
            repos.save()
        except:
            if enable:
                raise OperationFailed("KCHREPOS0020E", {'repo_id': repo_id})

            raise OperationFailed("KCHREPOS0021E", {'repo_id': repo_id})
        finally:
            kimchiLock.release()

        return repo_id
コード例 #9
0
ファイル: repositories.py プロジェクト: EmperorBeezie/kimchi
    def updateRepo(self, repo_id, params):
        """
        Update a given repository in repositories.Repositories() format
        """
        kimchiLock.acquire()
        repos = self._get_repos('KCHREPOS0011E')
        kimchiLock.release()
        if repo_id not in repos.repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        config = params.get('config', {})
        entry = repos.getRepo(repo_id)

        baseurl = params.get('baseurl', None)
        mirrorlist = config.get('mirrorlist', None)

        if baseurl is not None:
            entry.baseurl = baseurl

        if mirrorlist == '':
            mirrorlist = None

        if mirrorlist is not None:
            entry.mirrorlist = mirrorlist

        entry.id = params.get('repo_id', repo_id)
        entry.name = config.get('repo_name', entry.name)
        entry.gpgcheck = config.get('gpgcheck', entry.gpgcheck)
        entry.gpgkey = config.get('gpgkey', entry.gpgkey)
        kimchiLock.acquire()
        self._conf.writeRawRepoFile(entry)
        kimchiLock.release()
        return repo_id
コード例 #10
0
ファイル: repositories.py プロジェクト: xuweiwei2011/kimchi
    def getRepo(self, repo_id):
        """
        Return a dictionary in the repositories.Repositories() of the given
        repository ID format with the information of a YumRepository object.
        """
        kimchiLock.acquire()
        repos = self._get_repos('KCHREPOS0025E')
        kimchiLock.release()

        if repo_id not in repos.repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.getRepo(repo_id)

        info = {}
        info['enabled'] = entry.enabled

        baseurl = ''
        if entry.baseurl:
            baseurl = entry.baseurl[0]

        info['baseurl'] = baseurl
        info['config'] = {}
        info['config']['repo_name'] = entry.name
        info['config']['gpgcheck'] = entry.gpgcheck
        info['config']['gpgkey'] = entry.gpgkey
        info['config']['mirrorlist'] = entry.mirrorlist or ''
        info['config']['metalink'] = entry.metalink or ''
        return info
コード例 #11
0
ファイル: repositories.py プロジェクト: wr4eng/kimchi
 def getRepositoriesList(self):
     """
     Return a list of repositories IDs
     """
     kimchiLock.acquire()
     repos = self._yb().repos.repos.keys()
     kimchiLock.release()
     return repos
コード例 #12
0
ファイル: repositories.py プロジェクト: SkyWei/kimchi
 def getRepositoriesList(self):
     """
     Return a list of repositories IDs
     """
     kimchiLock.acquire()
     repos = self._get_repos('KCHREPOS0024E')
     kimchiLock.release()
     return repos.repos.keys()
コード例 #13
0
ファイル: repositories.py プロジェクト: xuweiwei2011/kimchi
 def getRepositoriesList(self):
     """
     Return a list of repositories IDs
     """
     kimchiLock.acquire()
     repos = self._get_repos('KCHREPOS0024E')
     kimchiLock.release()
     return repos.repos.keys()
コード例 #14
0
ファイル: repositories.py プロジェクト: SkyWei/kimchi
 def _get_repos(self):
     try:
         with self.pkg_lock():
             repos = self._sourceslist()
             repos.refresh()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed('KCHREPOS0025E', {'err': e.message})
コード例 #15
0
ファイル: repositories.py プロジェクト: xuweiwei2011/kimchi
 def _get_repos(self, errcode):
     try:
         yb = self._yb()
         yb.doLock()
         repos = yb.repos
         yb.doUnlock()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed(errcode, {'err': str(e)})
コード例 #16
0
ファイル: repositories.py プロジェクト: SkyWei/kimchi
 def _get_repos(self, errcode):
     try:
         yb = self._yb()
         yb.doLock()
         repos = yb.repos
         yb.doUnlock()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed(errcode, {'err': str(e)})
コード例 #17
0
ファイル: repositories.py プロジェクト: SkyWei/kimchi
    def addRepo(self, params):
        """
        Add a given repository to YumBase
        """
        # At least one base url, or one mirror, must be given.
        baseurl = params.get('baseurl', '')

        config = params.get('config', {})
        mirrorlist = config.get('mirrorlist', '')
        metalink = config.get('metalink', '')
        if not baseurl and not mirrorlist and not metalink:
            raise MissingParameter("KCHREPOS0013E")

        if baseurl:
            validate_repo_url(baseurl)

        if mirrorlist:
            validate_repo_url(mirrorlist)

        if metalink:
            validate_repo_url(metalink)

        if mirrorlist and metalink:
            raise InvalidOperation('KCHREPOS0030E')

        repo_id = params.get('repo_id', None)
        if repo_id is None:
            repo_id = "kimchi_repo_%s" % str(int(time.time() * 1000))

        kimchiLock.acquire()
        repos = self._get_repos('KCHREPOS0026E')
        kimchiLock.release()
        if repo_id in repos.repos.keys():
            raise InvalidOperation("KCHREPOS0022E", {'repo_id': repo_id})

        repo_name = config.get('repo_name', repo_id)
        repo = {'baseurl': baseurl, 'mirrorlist': mirrorlist,
                'name': repo_name, 'gpgcheck': 1,
                'gpgkey': [], 'enabled': 1, 'metalink': metalink}

        # write a repo file in the system with repo{} information.
        parser = ConfigParser()
        parser.add_section(repo_id)

        for key, value in repo.iteritems():
            if value:
                parser.set(repo_id, key, value)

        repofile = os.path.join(self._confdir, repo_id + '.repo')
        try:
            with open(repofile, 'w') as fd:
                parser.write(fd)
        except:
            raise OperationFailed("KCHREPOS0018E",
                                  {'repo_file': repofile})

        return repo_id
コード例 #18
0
ファイル: repositories.py プロジェクト: zofuthan/kimchi
    def addRepo(self, params):
        """
        Add a given repository to YumBase
        """
        # At least one base url, or one mirror, must be given.
        baseurl = params.get('baseurl', '')

        config = params.get('config', {})
        mirrorlist = config.get('mirrorlist', '')
        if not baseurl and not mirrorlist:
            raise MissingParameter("KCHREPOS0013E")

        if baseurl:
            validate_repo_url(baseurl)

        if mirrorlist:
            validate_repo_url(mirrorlist)

        repo_id = params.get('repo_id', None)
        if repo_id is None:
            repo_id = "kimchi_repo_%s" % str(int(time.time() * 1000))

        kimchiLock.acquire()
        repos = self._get_repos('KCHREPOS0026E')
        kimchiLock.release()
        if repo_id in repos.repos.keys():
            raise InvalidOperation("KCHREPOS0022E", {'repo_id': repo_id})

        repo_name = config.get('repo_name', repo_id)
        repo = {
            'baseurl': baseurl,
            'mirrorlist': mirrorlist,
            'name': repo_name,
            'gpgcheck': 1,
            'gpgkey': [],
            'enabled': 1
        }

        # write a repo file in the system with repo{} information.
        parser = ConfigParser()
        parser.add_section(repo_id)

        for key, value in repo.iteritems():
            if value:
                parser.set(repo_id, key, value)

        repofile = os.path.join(self._confdir, repo_id + '.repo')
        try:
            with open(repofile, 'w') as fd:
                parser.write(fd)
        except:
            raise OperationFailed("KCHREPOS0018E", {'repo_file': repofile})

        return repo_id
コード例 #19
0
ファイル: swupdate.py プロジェクト: Gossing/kimchi
 def getPackagesList(self):
     """
     Return a list of package's dictionaries. Each dictionary contains the
     information about a package, in the format
     package = {'package_name': <string>, 'version': <string>,
                'arch': <string>, 'repository': <string>}
     """
     kimchiLock.acquire()
     self._refreshUpdateList()
     kimchiLock.release()
     return self._pkgs
コード例 #20
0
 def getPackagesList(self):
     """
     Return a list of package's dictionaries. Each dictionary contains the
     information about a package, in the format
     package = {'package_name': <string>, 'version': <string>,
                'arch': <string>, 'repository': <string>}
     """
     kimchiLock.acquire()
     self._refreshUpdateList()
     kimchiLock.release()
     return self._pkgs
コード例 #21
0
ファイル: swupdate.py プロジェクト: Gossing/kimchi
 def _refreshUpdateList(self):
     """
     Update the list of packages to be updated in the system.
     """
     try:
         yb = getattr(__import__('yum'), 'YumBase')()
         yb.doLock()
         self._pkgs = yb.doPackageLists('updates')
         yb.doUnlock()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed('KCHPKGUPD0003E', {'err': str(e)})
コード例 #22
0
ファイル: swupdate.py プロジェクト: shaohef/kimchi
 def _refreshUpdateList(self):
     """
     Update the list of packages to be updated in the system.
     """
     try:
         yb = getattr(__import__('yum'), 'YumBase')()
         yb.doLock()
         self._pkgs = yb.doPackageLists('updates')
         yb.doUnlock()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed('KCHPKGUPD0003E', {'err': str(e)})
コード例 #23
0
ファイル: repositories.py プロジェクト: xuweiwei2011/kimchi
    def updateRepo(self, repo_id, params):
        """
        Update a given repository in repositories.Repositories() format
        """
        kimchiLock.acquire()
        repos = self._get_repos('KCHREPOS0011E')
        kimchiLock.release()
        if repo_id not in repos.repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.getRepo(repo_id)

        baseurl = params.get('baseurl', None)
        config = params.get('config', {})
        mirrorlist = config.get('mirrorlist', None)
        metalink = config.get('metalink', None)

        if baseurl is not None and len(baseurl.strip()) == 0:
            baseurl = None

        if mirrorlist is not None and len(mirrorlist.strip()) == 0:
            mirrorlist = None

        if metalink is not None and len(metalink.strip()) == 0:
            metalink = None

        if baseurl is None and mirrorlist is None and metalink is None:
            raise MissingParameter("KCHREPOS0013E")

        if baseurl is not None:
            validate_repo_url(baseurl)
            entry.baseurl = baseurl

        if mirrorlist is not None:
            validate_repo_url(mirrorlist)
            entry.mirrorlist = mirrorlist

        if metalink is not None:
            validate_repo_url(metalink)
            entry.metalink = metalink

        if mirrorlist and metalink:
            raise InvalidOperation('KCHREPOS0030E')

        entry.id = params.get('repo_id', repo_id)
        entry.name = config.get('repo_name', entry.name)
        entry.gpgcheck = config.get('gpgcheck', entry.gpgcheck)
        entry.gpgkey = config.get('gpgkey', entry.gpgkey)
        kimchiLock.acquire()
        self._conf.writeRawRepoFile(entry)
        kimchiLock.release()
        return repo_id
コード例 #24
0
ファイル: repositories.py プロジェクト: SkyWei/kimchi
    def updateRepo(self, repo_id, params):
        """
        Update a given repository in repositories.Repositories() format
        """
        kimchiLock.acquire()
        repos = self._get_repos('KCHREPOS0011E')
        kimchiLock.release()
        if repo_id not in repos.repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.getRepo(repo_id)

        baseurl = params.get('baseurl', None)
        config = params.get('config', {})
        mirrorlist = config.get('mirrorlist', None)
        metalink = config.get('metalink', None)

        if baseurl is not None and len(baseurl.strip()) == 0:
            baseurl = None

        if mirrorlist is not None and len(mirrorlist.strip()) == 0:
            mirrorlist = None

        if metalink is not None and len(metalink.strip()) == 0:
            metalink = None

        if baseurl is None and mirrorlist is None and metalink is None:
            raise MissingParameter("KCHREPOS0013E")

        if baseurl is not None:
            validate_repo_url(baseurl)
            entry.baseurl = baseurl

        if mirrorlist is not None:
            validate_repo_url(mirrorlist)
            entry.mirrorlist = mirrorlist

        if metalink is not None:
            validate_repo_url(metalink)
            entry.metalink = metalink

        if mirrorlist and metalink:
            raise InvalidOperation('KCHREPOS0030E')

        entry.id = params.get('repo_id', repo_id)
        entry.name = config.get('repo_name', entry.name)
        entry.gpgcheck = config.get('gpgcheck', entry.gpgcheck)
        entry.gpgkey = config.get('gpgkey', entry.gpgkey)
        kimchiLock.acquire()
        self._conf.writeRawRepoFile(entry)
        kimchiLock.release()
        return repo_id
コード例 #25
0
ファイル: swupdate.py プロジェクト: Gossing/kimchi
 def _refreshUpdateList(self):
     """
     Update the list of packages to be updated in the system.
     """
     apt_cache = getattr(__import__('apt'), 'Cache')()
     try:
         with self.pkg_lock():
             apt_cache.update()
             apt_cache.upgrade()
             self._pkgs = apt_cache.get_changes()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed('KCHPKGUPD0003E', {'err': e.message})
コード例 #26
0
 def _refreshUpdateList(self):
     """
     Update the list of packages to be updated in the system.
     """
     apt_cache = getattr(__import__('apt'), 'Cache')()
     try:
         with self.pkg_lock():
             apt_cache.update()
             apt_cache.upgrade()
             self._pkgs = apt_cache.get_changes()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed('KCHPKGUPD0003E', {'err': e.message})
コード例 #27
0
ファイル: repositories.py プロジェクト: SkyWei/kimchi
    def _get_source_entry(self, repo_id):
        kimchiLock.acquire()
        repos = self._get_repos()
        kimchiLock.release()

        for r in repos:
            # Ignore deb-src repositories
            if r.type != 'deb':
                continue

            if self._get_repo_id(r) != repo_id:
                continue

            return r

        return None
コード例 #28
0
ファイル: swupdate.py プロジェクト: Gossing/kimchi
 def getPackagesList(self):
     """
     Return a list of package's dictionaries. Each dictionary contains the
     information about a package, in the format:
     package = {'package_name': <string>, 'version': <string>,
                'arch': <string>, 'repository': <string>}
     """
     kimchiLock.acquire()
     self._refreshUpdateList()
     kimchiLock.release()
     pkg_list = []
     for pkg in self._pkgs:
         package = {'package_name': pkg.name,
                    'version': "%s-%s" % (pkg.version, pkg.release),
                    'arch': pkg.arch, 'repository': pkg.ui_from_repo}
         pkg_list.append(package)
     return pkg_list
コード例 #29
0
 def getPackagesList(self):
     """
     Return a list of package's dictionaries. Each dictionary contains the
     information about a package, in the format:
     package = {'package_name': <string>, 'version': <string>,
                'arch': <string>, 'repository': <string>}
     """
     kimchiLock.acquire()
     self._refreshUpdateList()
     kimchiLock.release()
     pkg_list = []
     for pkg in self._pkgs:
         package = {'package_name': pkg.name,
                    'version': "%s-%s" % (pkg.version, pkg.release),
                    'arch': pkg.arch, 'repository': pkg.ui_from_repo}
         pkg_list.append(package)
     return pkg_list
コード例 #30
0
ファイル: repositories.py プロジェクト: wr4eng/kimchi
    def removeRepo(self, repo_id):
        """
        Remove a given repository
        """
        r = self._get_source_entry(repo_id)
        if r is None:
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        kimchiLock.acquire()
        try:
            repos = self._sourceslist()
            repos.refresh()
            repos.remove(r)
            repos.save()
        except:
            raise OperationFailed("KCHREPOS0017E", {'repo_id': repo_id})
        finally:
            kimchiLock.release()
コード例 #31
0
ファイル: swupdate.py プロジェクト: wr4eng/kimchi
 def getPackagesList(self):
     """
     Return a list of package's dictionaries. Each dictionary contains the
     information about a package, in the format
     package = {'package_name': <string>, 'version': <string>,
                'arch': <string>, 'repository': <string>}
     """
     kimchiLock.acquire()
     self._refreshUpdateList()
     kimchiLock.release()
     pkg_list = []
     for pkg in self._pkgs:
         package = {'package_name': pkg.shortname,
                    'version': pkg.candidate.version,
                    'arch': pkg.architecture(),
                    'repository': pkg.candidate.origins[0].label}
         pkg_list.append(package)
     return pkg_list
コード例 #32
0
    def getPackagesList(self):
        """
        Return a list of package's dictionaries. Each dictionary contains the
        information about a package, in the format
        package = {'package_name': <string>, 'version': <string>,
                   'arch': <string>, 'repository': <string>}
        """
        kimchiLock.acquire()
        self._refreshUpdateList()
        kimchiLock.release()
        pkg_list = []
        for pkg in self._pkgs:
            package = {'package_name': pkg.shortname,
                       'version': pkg.candidate.version,
                       'arch': pkg._pkg.architecture,
                       'repository': pkg.candidate.origins[0].label}
            pkg_list.append(package)

        return pkg_list
コード例 #33
0
ファイル: repositories.py プロジェクト: SkyWei/kimchi
    def getRepositoriesList(self):
        """
        Return a list of repositories IDs

        APT repositories there aren't the concept about repository ID, so for
        internal control, the repository ID will be built as described in
        _get_repo_id()
        """
        kimchiLock.acquire()
        repos = self._get_repos()
        kimchiLock.release()

        res = []
        for r in repos:
            # Ignore deb-src repositories
            if r.type != 'deb':
                continue

            res.append(self._get_repo_id(r))

        return res
コード例 #34
0
ファイル: repositories.py プロジェクト: xuweiwei2011/kimchi
    def removeRepo(self, repo_id):
        """
        Remove a given repository
        """
        kimchiLock.acquire()
        repos = self._get_repos('KCHREPOS0027E')
        kimchiLock.release()
        if repo_id not in repos.repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.getRepo(repo_id)
        parser = ConfigParser()
        with open(entry.repofile) as fd:
            parser.readfp(fd)

        if len(parser.sections()) == 1:
            os.remove(entry.repofile)
            return

        parser.remove_section(repo_id)
        with open(entry.repofile, "w") as fd:
            parser.write(fd)
コード例 #35
0
ファイル: repositories.py プロジェクト: SkyWei/kimchi
    def removeRepo(self, repo_id):
        """
        Remove a given repository
        """
        kimchiLock.acquire()
        repos = self._get_repos('KCHREPOS0027E')
        kimchiLock.release()
        if repo_id not in repos.repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.getRepo(repo_id)
        parser = ConfigParser()
        with open(entry.repofile) as fd:
            parser.readfp(fd)

        if len(parser.sections()) == 1:
            os.remove(entry.repofile)
            return

        parser.remove_section(repo_id)
        with open(entry.repofile, "w") as fd:
            parser.write(fd)
コード例 #36
0
    TYPE = 'yum'
    DEFAULT_CONF_DIR = "/etc/yum.repos.d"
    CONFIG_ENTRY = ('repo_name', 'mirrorlist', 'metalink')

    def __init__(self):
        self._confdir = self.DEFAULT_CONF_DIR

    def _get_repos(self, errcode):
        try:
            kimchiLock.acquire()
            repos = get_yum_repositories()
        except Exception, e:
            kimchiLock.release()
            raise OperationFailed(errcode, {'err': str(e)})
        finally:
            kimchiLock.release()

        return repos

    def getRepositoriesList(self):
        """
        Return a list of repositories IDs
        """
        repos = self._get_repos('KCHREPOS0024E')
        return repos.keys()

    def getRepo(self, repo_id):
        """
        Return a dictionary in the repositories.Repositories() of the given
        repository ID format with the information of a YumRepository object.
        """
コード例 #37
0
ファイル: repositories.py プロジェクト: baiyuanlab/kimchi
    TYPE = 'yum'
    DEFAULT_CONF_DIR = "/etc/yum.repos.d"
    CONFIG_ENTRY = ('repo_name', 'mirrorlist', 'metalink')

    def __init__(self):
        self._confdir = self.DEFAULT_CONF_DIR

    def _get_repos(self, errcode):
        try:
            kimchiLock.acquire()
            repos = get_yum_repositories()
        except Exception, e:
            kimchiLock.release()
            raise OperationFailed(errcode, {'err': str(e)})
        finally:
            kimchiLock.release()

        return repos

    def getRepositoriesList(self):
        """
        Return a list of repositories IDs
        """
        repos = self._get_repos('KCHREPOS0024E')
        return repos.keys()

    def getRepo(self, repo_id):
        """
        Return a dictionary in the repositories.Repositories() of the given
        repository ID format with the information of a YumRepository object.
        """