예제 #1
0
파일: yumrepo.py 프로젝트: comstud/yumsync
    def _download_remote_packages(self):
        @contextmanager
        def suppress():
            """ Suppress stdout within a context.

            This is necessary in this use case because, unfortunately, the YUM
            library will do direct printing to stdout in many error conditions.
            Since we are maintaining a real-time, in-place updating presentation
            of progress, we must suppress this, as we receive exceptions for our
            reporting purposes anyways.
            """
            stdout = sys.stdout
            sys.stdout = open(os.devnull, 'w')
            yield
            sys.stdout = stdout

        try:
            yb = YumBase()
            if self.srcpkgs:
                if not 'src' in yb.arch.archlist:
                    yb.arch.archlist.append('src')
            repo = self._set_path(self.package_dir)
            if self.__yum_callback_obj:
                repo.setCallback(self.__yum_callback_obj)
            yb.repos.add(repo)
            yb.repos.enableRepo(repo.id)
            with suppress():
                if self.newestonly:
                    packages = yb.pkgSack.returnNewestByNameArch()
                else:
                    packages = yb.pkgSack.returnPackages()
            # Inform about number of packages total in the repo.
            self._callback('repo_init', len(packages))
            # Check if the packages are already downloaded. This is probably a bit
            # expensive, but the alternative is simply not knowing, which is
            # horrible for progress indication.
            for po in packages:
                local = po.localPkg()
                self._packages.append(os.path.basename(local))
                if os.path.exists(local):
                    if yb.verifyPkg(local, po, False):
                        self._callback('pkg_exists', os.path.basename(local))
            with suppress():
                yb.downloadPkgs(packages)

            self._callback('repo_complete')
        except (KeyboardInterrupt, SystemExit):
            pass
        except Exception as e:
            self._callback('repo_error', str(e))
            raise PackageDownloadError(str(e))
예제 #2
0
파일: yumrepo.py 프로젝트: comstud/yumsync
 def get_group_data(self):
     if self.local_dir:
         self._comps = None
     else:
         try:
             yb = YumBase()
             yb.repos.add(self.__repo_obj)
             self._comps = yb._getGroups().xml()
         except yum.Errors.GroupsError:
             pass
     if self._comps:
         self._callback('repo_group_data', 'available')
     else:
         self._callback('repo_group_data', 'unavailable')
예제 #3
0
파일: yumrepo.py 프로젝트: jrwesolo/yumsync
 def get_group_data(self):
     if self.local_dir:
         self._comps = None
     else:
         try:
             yb = YumBase()
             yb.repos.add(self.__repo_obj)
             self._comps = yb._getGroups().xml()
         except yum.Errors.GroupsError:
             pass
     if self._comps:
         self._callback('repo_group_data', 'available')
     else:
         self._callback('repo_group_data', 'unavailable')
예제 #4
0
파일: yumrepo.py 프로젝트: jrwesolo/yumsync
 def _get_repo_obj(repoid, localdir=None, baseurl=None, mirrorlist=None):
     yb = YumBase()
     if baseurl is not None:
         if type(baseurl) is list:
             repo = yb.add_enable_repo(repoid, baseurls=baseurl)
         else:
             repo = yb.add_enable_repo(repoid, baseurls=[baseurl])
     elif mirrorlist is not None:
         repo = yb.add_enable_repo(repoid, mirrorlist=mirrorlist)
     elif localdir:
         repo = yb.add_enable_repo(repoid)
     else:
         raise ValueError('One or more baseurls or mirrorlist required')
     return repo
예제 #5
0
파일: yumrepo.py 프로젝트: jrwesolo/yumsync
    def _download_remote_packages(self):
        @contextmanager
        def suppress():
            """ Suppress stdout within a context.

            This is necessary in this use case because, unfortunately, the YUM
            library will do direct printing to stdout in many error conditions.
            Since we are maintaining a real-time, in-place updating presentation
            of progress, we must suppress this, as we receive exceptions for our
            reporting purposes anyways.
            """
            stdout = sys.stdout
            sys.stdout = open(os.devnull, 'w')
            yield
            sys.stdout = stdout

        try:
            yb = YumBase()
            repo = self._set_path(self.package_dir)
            if self.__yum_callback_obj:
                repo.setCallback(self.__yum_callback_obj)
            yb.repos.add(repo)
            yb.repos.enableRepo(repo.id)
            with suppress():
                # showdups allows us to get multiple versions of the same package.
                ygh = yb.doPackageLists(showdups=True)
            # reinstall_available = Available packages which are installed.
            packages = ygh.available + ygh.reinstall_available
            # Inform about number of packages total in the repo.
            self._callback('repo_init', len(packages))
            # Check if the packages are already downloaded. This is probably a bit
            # expensive, but the alternative is simply not knowing, which is
            # horrible for progress indication.
            for po in packages:
                local = po.localPkg()
                if os.path.exists(local):
                    if yb.verifyPkg(local, po, False):
                        self._callback('pkg_exists', self._get_package_filename(po))
            with suppress():
                yb.downloadPkgs(packages)

            self._packages = [self._get_package_filename(pkg) for pkg in packages]
            self._callback('repo_complete')
        except (KeyboardInterrupt, SystemExit):
            pass
        except Exception as e:
            self._callback('repo_error', str(e))
            raise PackageDownloadError(str(e))
예제 #6
0
파일: yumrepo.py 프로젝트: comstud/yumsync
 def _get_repo_obj(repoid, localdir=None, baseurl=None, mirrorlist=None):
     yb = YumBase()
     if baseurl is not None:
         if isinstance(baseurl, list):
             repo = yb.add_enable_repo(repoid, baseurls=baseurl)
         else:
             repo = yb.add_enable_repo(repoid, baseurls=[baseurl])
     elif mirrorlist is not None:
         repo = yb.add_enable_repo(repoid, mirrorlist=mirrorlist)
     elif localdir:
         repo = yb.add_enable_repo(repoid)
     else:
         raise ValueError('One or more baseurls or mirrorlist required')
     return repo