def exec_axel(conduit, remote, local, size, conn=None, text=None): """ Run axel binary to download""" if not size or size == -1: # we need size here. if not, we do nothing conduit.info(3, "axel got unknown size") return False # new thread to run axel conf = conduit.getConf() axel_debug = False if conf.debuglevel >= 3: axel_debug = True axel = Axel(debug=axel_debug, remote=remote, local=local, conn=conn) axel.start() # make axel outout look like yum output tm = TextMeter() size = int(size) filename = os.path.basename(local) if not text: text = filename # compose text console output tm.start(filename=filename, size=size, text=str(text)) #axel.start() lastSize = curSize = 0 slow_count = 0 while True: live = axel.isAlive() if curSize >= size or not live: if live: conduit.info(3, "axel is unexpectedly still alive") break try: curSize = os.path.getsize(local) except OSError, e: # maybe axel still don't generate local file # just continue to the following time call curSize = 0 pass # update the text bar every one second tm.update(curSize) time.sleep(0.5) # too slow, Less than 1000 bytes/sec transferred # the last 30 second if (curSize - lastSize) < 1000: slow_count += 1 if slow_count == 60: conduit.info(3, "Operation too slow. Less than 1000 \ bytes/sec transferred the last 30 seconds") axel.stop() break lastSize = curSize
def setup_repos(self, repos_to_enable=None, repos_to_disable=None): if repos_to_disable: self.repos.disableRepo(repos_to_disable) if repos_to_enable: self.repos.enableRepo(repos_to_enable) self.repos.setProgressBar(None) self.doRepoSetup() enabled_repos = self.repos.listEnabled() match_count = 0 for repo in enabled_repos: if fnmatch.fnmatch(repo.id, repos_to_enable): match_count = match_count + 1 if len(enabled_repos) == 0 or match_count == 0: raise NoReposError( _('No repositories matching %s were able to be' ' enabled, please ensure that your system is' ' subscribed to the appropriate software' ' repositories.' % (repos_to_enable))) # Re-enable the file download text meter self.repos.setProgressBar(TextMeter(fo=sys.stdout))
def exec_axel(conduit, remote, local, size, conn=None, text=None): """ Run axel binary to download""" if not size or size == -1: # we need size here. if not, we do nothing conduit.info(3, "axel got unknown size") return False # new thread to run axel conf = conduit.getConf() axel_debug = False if conf.debuglevel >= 3: axel_debug = True axel = Axel(debug=axel_debug, remote=remote, local=local, conn=conn) axel.start() # make axel outout look like yum output tm = TextMeter() size = int(size) filename = os.path.basename(local) if not text: text = filename # compose text console output tm.start(filename=filename, size=size, text=str(text)) #axel.start() lastSize = curSize = 0 slow_count = 0 while True: live = axel.isAlive() if curSize >= size or not live: if live: conduit.info(3, "axel is unexpectedly still alive") break try: curSize = os.path.getsize(local) except OSError, e: # maybe axel still don't generate local file # just continue to the following time call curSize = 0 pass # update the text bar every one second tm.update(curSize) time.sleep(0.5) # too slow, Less than 1000 bytes/sec transferred # the last 30 second if (curSize - lastSize) < 1000: slow_count += 1 if slow_count == 60: conduit.info( 3, "Operation too slow. Less than 1000 \ bytes/sec transferred the last 30 seconds") axel.stop() break lastSize = curSize
def main(): parser = setup_opts() (opts, args) = parser.parse_args() comps = yum.comps.Comps() # Borrowing large sections from repoquery/pkg-tree etc. initnoise = (not opts.quiet) * 2 yb = yum.YumBase() if opts.conffile is not None: yb.preconf.fn = opts.conffile yb.preconf.debuglevel = initnoise yb.preconf.init_plugins = opts.plugins yb.conf # Show what is going on, if --quiet is not set. if not opts.quiet and sys.stdout.isatty(): yb.repos.setProgressBar(TextMeter(fo=sys.stdout)) yb.repos.callback = output.CacheProgressCallback() yumout = output.YumOutput() freport = (yumout.failureReport, (), {}) yb.repos.setFailureCallback(freport) if os.geteuid() != 0 or opts.tempcache: cachedir = yum.misc.getCacheDir() if cachedir is None: yb.logger.error("Error: Could not make cachedir, exiting") sys.exit(50) yb.repos.setCacheDir(cachedir) yb.conf.cache = 0 # yum set cache=1, if uid != 0 if opts.cache: yb.conf.cache = True if not opts.quiet: yb.logger.info('Running from cache, results might be incomplete.') if opts.disablerepos: for repo_match in opts.disablerepos: for repo in yb.repos.findRepos(repo_match): repo.disable() if opts.enablerepos: for repo_match in opts.enablerepos: for repo in yb.repos.findRepos(repo_match): repo.enable() try: yb.doRepoSetup() except yum.Errors.RepoError, e: yb.logger.error("Could not setup repo: %s" % (e)) sys.exit(50)
def find_package(self, query=None): ''' Find package in the available repos. WARNING: by default this function only searches the debug repos. You need to change the args to search other repos. Keyword arguments: query -- A package name. Wildcards allowed. Returns: An array yum package objects. ''' retVal = None try: self.repos.setProgressBar(None) retVal = self.pkgSack.returnPackages(patterns=[query]) # Re-enable the file download text meter self.repos.setProgressBar(TextMeter(fo=sys.stdout)) except Exception, e: logger.log(logging.ERROR, e) logger.exception(e)
def __init__(self): ''' Returns an initialized yum.YumBase object. Important: You must close() the object after performing a transaction. ''' yum.YumBase.__init__(self) # You must do this so that Yum doesn't spam the console. self.doConfigSetup(debuglevel=0, errorlevel=0) # Initialize Yum. if hasattr(yum.YumBase, 'setCacheDir'): # Newer version appear to use this self.setCacheDir() self._override_sigchecks = True else: # Older use this. self._getConfig() setattr(self, '_checkSignatures', lambda x, y: True) # Set the progress bar self.repos.setProgressBar(TextMeter(fo=sys.stdout))
my.conf.uid = 1 # force locking of user cache elif opts.cachedir: my.repos.setCacheDir(opts.cachedir) # Lock if they've not given an explicit cachedir if not opts.cachedir: try: my.doLock() except yum.Errors.LockError, e: print >> sys.stderr, _("Error: %s") % e sys.exit(50) # Use progress bar display when downloading repo metadata # and package files ... needs to be setup before .repos (ie. RHN/etc.). if not opts.quiet: my.repos.setProgressBar(TextMeter(fo=sys.stdout), TextMultiFileMeter(fo=sys.stdout)) try: my.doRepoSetup() except yum.Errors.RepoError, e: print >> sys.stderr, _("Error setting up repositories: %s") % e sys.exit(1) if len(opts.repoid) > 0: myrepos = [] # find the ones we want for glob in opts.repoid: add_repos = my.repos.findRepos(glob) if not add_repos: print >> sys.stderr, _(
def run(self): ret = subprocess.call(['axel', '-q', DATA, '-o', FILENAME]) return ret def get_size(filename): return os.path.getsize(os.path.join(PWD, filename)) # MAIN a = Axel() a.start() time.sleep(2) # start tm = TextMeter() tm.start(filename=FILENAME, text=FILENAME) cur = get_size(FILENAME) while True: if cur >= SIZE: print "Done" break cur = get_size(FILENAME) print "size: %d" % cur tm.update(cur) time.sleep(1) tm.end(SIZE)
repo.cache = 0 download.localpath = local # Hack: to set the localpath we want. try: checkfunc = (self.verifyPkg, (download, 1), {}) path = repo.getPackage(download, checkfunc=checkfunc) except IOError, e: self.logger.error("Cannot write to file %s. Error was: %s" % (local, e)) exit_code = 2 continue except RepoError, e: self.logger.error("Could not download/verify pkg %s: %s" % (download, e)) exit_code = 2 continue if not os.path.exists(local) or not os.path.samefile(path, local): progress = TextMeter() progress.start(basename=os.path.basename(local), size=os.stat(path).st_size) shutil.copy2(path, local) progress.end(progress.size) return exit_code def _groupPackages(self,pkglist): pkgGroups = {} for po in pkglist: na = '%s.%s' % (po.name,po.arch) if not na in pkgGroups: pkgGroups[na] = [po] else: pkgGroups[na].append(po) return pkgGroups
my.conf.uid = 1 # force locking of user cache elif opts.cachedir: my.repos.setCacheDir(opts.cachedir) # Lock if they've not given an explicit cachedir if not opts.cachedir: try: my.doLock() except yum.Errors.LockError, e: print >> sys.stderr, _("Error: %s") % e sys.exit(50) # Use progress bar display when downloading repo metadata # and package files ... needs to be setup before .repos (ie. RHN/etc.). if not opts.quiet: my.repos.setProgressBar(TextMeter(fo=sys.stdout), TextMultiFileMeter(fo=sys.stdout)) my.doRepoSetup() if len(opts.repoid) > 0: myrepos = [] myrepoids = deque() # find the ones we want for glob in opts.repoid: add_repos = my.repos.findRepos(glob) if not add_repos: print >> sys.stderr, _("Warning: cannot find repository %s") % glob continue myrepos.extend(add_repos) myrepoids.append(glob)
def run(self): ret = subprocess.call(['axel', '-q', DATA, '-o', FILENAME ]) return ret def get_size(filename): return os.path.getsize(os.path.join(PWD,filename)) # MAIN a = Axel() a.start() time.sleep(2) # start tm = TextMeter() tm.start(filename=FILENAME, text=FILENAME) cur = get_size(FILENAME) while True: if cur >= SIZE: print "Done" break cur = get_size(FILENAME) print "size: %d" %cur tm.update(cur) time.sleep(1) tm.end(SIZE)