def prepare(self): self.mute_stdout() #self.conf.cache = os.geteuid() != 0 # Setup yum (Ts, RPM db, Repo & Sack) # doConfigSetup() takes some time, let user know what we are doing try: # Saw this exception here: # cannot open Packages index using db3 - Permission denied (13) # yum.Errors.YumBaseError: Error: rpmdb open failed self.base.doConfigSetup() except YumBaseError as ex: self.unmute_stdout() print(_("Error initializing yum (YumBase.doConfigSetup): '{0!s}'").format(str(ex))) #return 1 - can't do this in constructor exit(1) self.unmute_stdout() # make yumdownloader work as non root user if not self.base.setCacheDir(): print(_("Error: can't make cachedir, exiting")) return RETURN_FAILURE # disable all not needed for repo in self.base.repos.listEnabled(): try: repo.close() self.base.repos.disableRepo(repo.id) except YumBaseError as ex: print(_("Can't disable repository '{0!s}': {1!s}").format(repo.id, str(ex)))
def prepare(self): self.mute_stdout() #self.conf.cache = os.geteuid() != 0 # Setup yum (Ts, RPM db, Repo & Sack) # doConfigSetup() takes some time, let user know what we are doing try: # Saw this exception here: # cannot open Packages index using db3 - Permission denied (13) # yum.Errors.YumBaseError: Error: rpmdb open failed self.base.doConfigSetup() except YumBaseError as ex: self.unmute_stdout() print( _("Error initializing yum (YumBase.doConfigSetup): '{0!s}'"). format(str(ex))) #return 1 - can't do this in constructor exit(1) self.unmute_stdout() # make yumdownloader work as non root user if not self.base.setCacheDir(): print(_("Error: can't make cachedir, exiting")) return RETURN_FAILURE # disable all not needed for repo in self.base.repos.listEnabled(): try: repo.close() self.base.repos.disableRepo(repo.id) except YumBaseError as ex: print( _("Can't disable repository '{0!s}': {1!s}").format( repo.id, str(ex)))
def __init__(self, cache, tmp, repo_pattern="*debug*", keep_rpms=False, noninteractive=True): self.old_stdout = -1 self.cachedir = cache self.tmpdir = tmp global TMPDIR TMPDIR = tmp self.keeprpms = keep_rpms self.noninteractive = noninteractive self.repo_pattern=repo_pattern YumBase.__init__(self) self.mute_stdout() #self.conf.cache = os.geteuid() != 0 # Setup yum (Ts, RPM db, Repo & Sack) # doConfigSetup() takes some time, let user know what we are doing print _("Initializing yum") try: # Saw this exception here: # cannot open Packages index using db3 - Permission denied (13) # yum.Errors.YumBaseError: Error: rpmdb open failed self.doConfigSetup() except YumBaseError, ex: self.unmute_stdout() print _("Error initializing yum (YumBase.doConfigSetup): '{0!s}'").format(ex) #return 1 - can't do this in constructor exit(1)
def download(self, files, download_exact_files=False): """ @files - """ installed_size = 0 total_pkgs = 0 todownload_size = 0 downloaded_pkgs = 0 # nothing to download? if not files: return #if verbose == 0: # # this suppress yum messages about setting up repositories # mute_stdout() # make yumdownloader work as non root user if not self.setCacheDir(): self.logger.error("Error: can't make cachedir, exiting") exit(50) # disable all not needed for repo in self.repos.listEnabled(): try: repo.close() self.repos.disableRepo(repo.id) except Exception, ex: print _("Can't disable repository '{0!s}': {1!s}").format(repo.id, str(ex))
def exIOError(self, e): if e.errno == 32: self.logger.critical(_('\n\nExiting on Broken Pipe')) else: self.logger.critical(_('\n\n%s') % str(e)) if self.unlock(): return 200 return 1
def download(self, files, download_exact_files=False): """ @files - """ installed_size = 0 total_pkgs = 0 todownload_size = 0 downloaded_pkgs = 0 # nothing to download? if not files: return RETURN_FAILURE #if verbose == 0: # # this suppress yum messages about setting up repositories # mute_stdout() # make yumdownloader work as non root user if not self.setCacheDir(): print _("Error: can't make cachedir, exiting") return RETURN_FAILURE # disable all not needed for repo in self.repos.listEnabled(): try: repo.close() self.repos.disableRepo(repo.id) except Exception, ex: print _("Can't disable repository '{0!s}': {1!s}").format( repo.id, str(ex))
def updateProgress(self, name, frac, fread, ftime): pct = int(frac * 100) if pct == self.last_pct: log2("percentage is the same, not updating progress") return self.last_pct = pct # if run from terminal we can have fancy output if sys.stdout.isatty(): sys.stdout.write( "\033[sDownloading (%i of %i) %s: %3u%%\033[u" % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct)) if pct == 100: print( _("Downloading (%i of %i) %s: %3u%%") % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct)) # but we want machine friendly output when spawned from abrt-server else: t = time.time() if self.last_time == 0: self.last_time = t # update only every 10 seconds if pct == 100 or self.last_time > t or t - self.last_time >= 10: print( _("Downloading (%i of %i) %s: %3u%%") % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct)) self.last_time = t if pct == 100: self.last_time = 0 sys.stdout.flush()
def updateProgress(self, name, frac, fread, ftime): pct = int(frac * 100) if pct == self.last_pct: log2("percentage is the same, not updating progress") return self.last_pct = pct # if run from terminal we can have fancy output if sys.stdout.isatty(): sys.stdout.write("\033[sDownloading (%i of %i) %s: %3u%%\033[u" % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) ) if pct == 100: print (_("Downloading (%i of %i) %s: %3u%%") % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) ) # but we want machine friendly output when spawned from abrt-server else: t = time.time() if self.last_time == 0: self.last_time = t # update only every 10 seconds if pct == 100 or self.last_time > t or t - self.last_time >= 10: print (_("Downloading (%i of %i) %s: %3u%%") % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) ) self.last_time = t if pct == 100: self.last_time = 0 sys.stdout.flush()
def downloadErrorCallback(callBackObj): print _( "Problem '{0!s}' occured while downloading from mirror: '{1!s}'. Trying next one" ).format(callBackObj.exception, callBackObj.mirror) # explanation of the return value can be found here: # /usr/lib/python2.7/site-packages/urlgrabber/mirror.py return {'fail': 0}
def unpack_rpm(package_file_name, files, tmp_dir, destdir, keeprpm, exact_files=False): """ Unpacks a single rpm located in tmp_dir into destdir. Arguments: package_file_name - name of the rpm file files - files to extract from the rpm tmp_dir - temporary directory where the rpm file is located destdir - destination directory for the rpm package extraction keeprpm - check if the user wants to delete rpms from the tmp directory exact_files - extract only specified files Returns: RETURN_FAILURE in case of a serious problem """ package_full_path = tmp_dir + "/" + package_file_name log1("Extracting %s to %s", package_full_path, destdir) log2("%s", files) print _("Extracting cpio from {0}").format(package_full_path) unpacked_cpio_path = tmp_dir + "/unpacked.cpio" try: unpacked_cpio = open(unpacked_cpio_path, 'wb') except IOError, ex: print _("Can't write to '{0}': {1}").format(unpacked_cpio_path, ex) return RETURN_FAILURE
def _getpluginconf(self, modname): '''Parse the plugin specific configuration file and return a IncludingConfigParser instance representing it. Returns None if there was an error reading or parsing the configuration file. ''' for dir in self.pluginconfpath: conffilename = os.path.join(dir, modname + ".conf") if os.access(conffilename, os.R_OK): # Found configuration file break self.verbose_logger.log( logginglevels.INFO_2, _("Configuration file %s not found") % conffilename) else: # for # Configuration files for the plugin not found self.verbose_logger.log( logginglevels.INFO_2, _("Unable to find configuration file for plugin %s") % modname) return None parser = ConfigParser() confpp_obj = ConfigPreProcessor(conffilename) try: parser.readfp(confpp_obj) except ParsingError, e: raise Errors.ConfigError("Couldn't parse %s: %s" % (conffilename, str(e)))
def exIOError(e): if e.errno == 32: logger.critical(_('\n\nExiting on Broken Pipe')) else: logger.critical(_('\n\n%s') % exception2msg(e)) if unlock(): return 200 return 1
def exIOError(self, e): if e.errno == 32: self.logger.critical(_('\n\nExiting on Broken Pipe')) else: self.logger.critical(_('\n\n%s') % exception2msg(e)) if self.unlock(): return 200 return 1
def exIOError(e): if e.errno == 32: logger.critical(_("\n\nExiting on Broken Pipe")) else: logger.critical(_("\n\n%s") % exception2msg(e)) if unlock(): return 200 return 1
def exRepoError(e): # For RepoErrors ... help out by forcing new repodata next time. # XXX: clean only the repo that has failed? try: base.cleanExpireCache() except Errors.YumBaseError: # Let's not confuse the user further (they don't even know we tried # the clean). pass msg = _("""\ One of the configured repositories failed (%(repo)s), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=%(repoid)s ... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable %(repoid)s or subscription-manager repos --disable=%(repoid)s 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=%(repoid)s.skip_if_unavailable=true """) repoui = _('Unknown') repoid = _('<repoid>') try: repoid = e.repo.id repoui = e.repo.name except AttributeError: pass msg = msg % {'repoid' : repoid, 'repo' : repoui} logger.critical('\n\n%s\n%s', msg, exception2msg(e)) if unlock(): return 200 return 1
def exRepoError(e): # For RepoErrors ... help out by forcing new repodata next time. # XXX: clean only the repo that has failed? try: base.cleanExpireCache() except Errors.YumBaseError: # Let's not confuse the user further (they don't even know we tried # the clean). pass msg = _("""\ One of the configured repositories failed (%(repo)s), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=%(repoid)s ... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable %(repoid)s or subscription-manager repos --disable=%(repoid)s 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=%(repoid)s.skip_if_unavailable=true """) repoui = _('Unknown') repoid = _('<repoid>') try: repoid = e.repo.id repoui = e.repo.name except AttributeError: pass msg = msg % {'repoid' : repoid, 'repo' : repoui} logger.critical('\n\n%s\n%s', msg, exception2msg(e)) if unlock(): return 200 return 1
def downloadErrorCallback(callBackObj): """ A callback function for mirror errors. """ print _("Problem '{0!s}' occured while downloading from mirror: '{1!s}'. Trying next one").format( callBackObj.exception, callBackObj.mirror) # explanation of the return value can be found here: # /usr/lib/python2.7/site-packages/urlgrabber/mirror.py return {'fail':0}
def unpack_rpm(package_file_name, files, tmp_dir, destdir, keeprpm, exact_files=False): package_full_path = tmp_dir + "/" + package_file_name log1("Extracting %s to %s", package_full_path, destdir) log2("%s", files) print _("Extracting cpio from {0}").format(package_full_path) unpacked_cpio_path = tmp_dir + "/unpacked.cpio" try: unpacked_cpio = open(unpacked_cpio_path, 'wb') except IOError, ex: print _("Can't write to '{0}': {1}").format(unpacked_cpio_path, ex) return RETURN_FAILURE
def rpmdb_warn_checks(): try: probs = base._rpmdb_warn_checks(out=verbose_logger.info, warn=False) except Errors.YumBaseError as e: # This is mainly for PackageSackError from rpmdb. verbose_logger.info(_(" Yum checks failed: %s"), exception2msg(e)) probs = [] if not probs: verbose_logger.info( _(" You could try running: rpm -Va --nofiles --nodigest"))
def unpack_rpm(package_nevra, files, tmp_dir, destdir, keeprpm): package_name = package_nevra + ".rpm" package_full_path = tmp_dir + "/" + package_name log1("Extracting %s to %s", package_full_path, destdir) log2("%s", files) print _("Extracting cpio from %s") % (package_full_path) unpacked_cpio_path = tmp_dir + "/unpacked.cpio" try: unpacked_cpio = open(unpacked_cpio_path, 'wb') except IOError, ex: print _("Can't write to '%s': %s") % (unpacked_cpio_path, ex) return RETURN_FAILURE
def snapshot(self, percentage=100, prefix='', postfix=None, tags={}): """ Attempt to take a snapshot, note that errors can happen after this function succeeds. """ if postfix is None: postfix = '%s%s' % (self.postfix_static, datetime.now().strftime("%Y%m%d%H%M%S.%f")) ret = [] for vgname in self._vgnames: use = self._use_dev(vgname) if use is not None and not use: continue vg = lvm.vgOpen(vgname, 'w') if not vg: raise _ResultError( _("Unknown error when opening volume group ") + vgname) for lv in vg.listLVs(): lvname = lv.getName() if not self._use_dev(vgname, lv): continue nlvname = "%s%s%s" % (prefix, lvname, postfix) nlv = lv.snapshot(nlvname, (lv.getSize() * percentage) / 100) if not nlv: # Failed here ... continuing seems bad. vg.close() raise _ResultError( _("Unknown error when creating snapshot ") + nlvname) odev = "%s/%s" % (vgname, lvname) ndev = "%s/%s" % (vgname, nlvname) # FIXME: yum_fssnapshot_pre_lv_name=<blah> eq_tags = set() for val in (ndev, odev, '*'): for tag in tags.get(val, []): if '=' in tag: eq_tag_key, eq_tag_val = tag.split('=', 1) if eq_tag_key in eq_tags: continue eq_tags.add(eq_tag_key) nlv.addTag(tag) ret.append((odev, ndev)) vg.close() return ret
def exIOError(self, e): """Output a message stating that the program is exiting due to an IO exception. :param e: the IO exception :return: the exit code """ if e.errno == 32: self.logger.critical(_('\n\nExiting on Broken Pipe')) else: self.logger.critical(_('\n\n%s') % exception2msg(e)) if self.unlock(): return 200 return 1
def __init__(self): yum.rpmtrans.RPMBaseCallback.__init__(self) self.messages = {} self.failed = [] self.action = { yum.constants.TS_UPDATE: yum._('Updating'), yum.constants.TS_ERASE: yum._('Erasing'), yum.constants.TS_INSTALL: yum._('Installing'), yum.constants.TS_TRUEINSTALL: yum._('Installing'), yum.constants.TS_OBSOLETED: yum._('Obsoleted'), yum.constants.TS_OBSOLETING: yum._('Installing'), yum.constants.TS_UPDATED: yum._('Cleanup'), 'repackaging': yum._('Repackaging') } # The fileaction are not translated, most sane IMHO / Tim self.fileaction = { yum.constants.TS_UPDATE: 'Updated', yum.constants.TS_ERASE: 'Erased', yum.constants.TS_INSTALL: 'Installed', yum.constants.TS_TRUEINSTALL: 'Installed', yum.constants.TS_OBSOLETED: 'Obsoleted', yum.constants.TS_OBSOLETING: 'Installed', yum.constants.TS_UPDATED: 'Cleanup' } self.logger = logging.getLogger( 'yum.filelogging.RPMInstallCallback')
def doUtilBuildTransaction(self, unfinished_transactions_check=True): """Build the transaction. :param unfinished_transactions_check: whether to check if an unfinished transaction has been saved """ try: (result, resultmsgs) = self.buildTransaction( unfinished_transactions_check=unfinished_transactions_check) except plugins.PluginYumExit as e: return self.exPluginExit(e) except Errors.YumBaseError as e: result = 1 resultmsgs = [exception2msg(e)] except KeyboardInterrupt: return self.exUserCancel() except IOError as e: return self.exIOError(e) # Act on the depsolve result if result == 0: # Normal exit if self.unlock(): return 200 return 0 elif result == 1: # Fatal error for prefix, msg in self.pretty_output_restring(resultmsgs): self.logger.critical(prefix, msg) if not self.conf.skip_broken: self.verbose_logger.info( _(" You could try using --skip-broken to work around the problem" )) if not self._rpmdb_warn_checks(out=self.verbose_logger.info, warn=False): self.verbose_logger.info( _(" You could try running: rpm -Va --nofiles --nodigest")) if self.unlock(): return 200 return 1 elif result == 2: # Continue on pass else: self.logger.critical(_('Unknown Error(s): Exit Code: %d:'), result) for msg in resultmsgs: self.logger.critical(msg) if self.unlock(): return 200 return 3 self.verbose_logger.log(logginglevels.INFO_2, _('\nDependencies Resolved'))
def __init__(self): yum.rpmtrans.RPMBaseCallback.__init__(self) self.messages = {} self.failed = [] self.action = { yum.constants.TS_UPDATE: yum._("Updating"), yum.constants.TS_ERASE: yum._("Erasing"), yum.constants.TS_INSTALL: yum._("Installing"), yum.constants.TS_TRUEINSTALL: yum._("Installing"), yum.constants.TS_OBSOLETED: yum._("Obsoleted"), yum.constants.TS_OBSOLETING: yum._("Installing"), yum.constants.TS_UPDATED: yum._("Cleanup"), "repackaging": yum._("Repackaging"), } # The fileaction are not translated, most sane IMHO / Tim self.fileaction = { yum.constants.TS_UPDATE: "Updated", yum.constants.TS_ERASE: "Erased", yum.constants.TS_INSTALL: "Installed", yum.constants.TS_TRUEINSTALL: "Installed", yum.constants.TS_OBSOLETED: "Obsoleted", yum.constants.TS_OBSOLETING: "Installed", yum.constants.TS_UPDATED: "Cleanup", } self.logger = logging.getLogger("yum.filelogging.RPMInstallCallback")
def __init__(self): self.messages = {} self.failed = [] self.action = { yum.constants.TS_UPDATE: yum._('Updating'), yum.constants.TS_ERASE: yum._('Erasing'), yum.constants.TS_INSTALL: yum._('Installing'), yum.constants.TS_TRUEINSTALL: yum._('Installing'), yum.constants.TS_OBSOLETED: yum._('Obsoleted'), yum.constants.TS_OBSOLETING: yum._('Installing'), yum.constants.TS_UPDATED: yum._('Cleanup'), 'repackaging': yum._('Repackaging') } # The fileaction are not translated, most sane IMHO / Tim self.fileaction = { yum.constants.TS_UPDATE: 'Updated', yum.constants.TS_ERASE: 'Erased', yum.constants.TS_INSTALL: 'Installed', yum.constants.TS_TRUEINSTALL: 'Installed', yum.constants.TS_OBSOLETED: 'Obsoleted', yum.constants.TS_OBSOLETING: 'Installed', yum.constants.TS_UPDATED: 'Cleanup' } self.logger = logging.getLogger( 'yum.filelogging.RPMInstallCallback')
def snapshot(self, percentage=100, prefix="", postfix=None, tags={}): """ Attempt to take a snapshot, note that errors can happen after this function succeeds. """ if postfix is None: postfix = "%s%s" % (self.postfix_static, datetime.now().strftime("%Y%m%d%H%M%S.%f")) ret = [] for vgname in self._vgnames: use = self._use_dev(vgname) if use is not None and not use: continue vg = lvm.vgOpen(vgname, "w") if not vg: raise _ResultError(_("Unknown error when opening volume group ") + vgname) for lv in vg.listLVs(): lvname = lv.getName() if not self._use_dev(vgname, lv): continue nlvname = "%s%s%s" % (prefix, lvname, postfix) nlv = lv.snapshot(nlvname, (lv.getSize() * percentage) / 100) if not nlv: # Failed here ... continuing seems bad. vg.close() raise _ResultError(_("Unknown error when creating snapshot ") + nlvname) odev = "%s/%s" % (vgname, lvname) ndev = "%s/%s" % (vgname, nlvname) # FIXME: yum_fssnapshot_pre_lv_name=<blah> eq_tags = set() for val in (ndev, odev, "*"): for tag in tags.get(val, []): if "=" in tag: eq_tag_key, eq_tag_val = tag.split("=", 1) if eq_tag_key in eq_tags: continue eq_tags.add(eq_tag_key) nlv.addTag(tag) ret.append((odev, ndev)) vg.close() return ret
def ask_yes_no(prompt, retries=4): while True: try: response = raw_input(prompt) except EOFError: log1("got eof, probably executed from helper, assuming - yes") return True if response in (_("y")): # for translators -> y/Y as yes return True if response in ("", _("n")): # for translators -> N/n as no return False retries = retries - 1 if retries < 0: break return False
def _importplugins(self, types): '''Load plugins matching the given types. ''' # Initialise plugin dict self._plugins = {} self._pluginfuncs = {} for slot in SLOTS: self._pluginfuncs[slot] = [] # Import plugins self._used_disable_plugin = set() self._used_enable_plugin = set() for dir in self.searchpath: if not os.path.isdir(dir): continue for modulefile in sorted(glob.glob('%s/*.py' % dir)): self._loadplugin(modulefile, types) # If we are in verbose mode we get the full 'Loading "blah" plugin' lines if (self._plugins and not self.verbose_logger.isEnabledFor(logginglevels.DEBUG_3)): # Mostly copied from YumOutput._outKeyValFill() key = _("Loaded plugins: ") val = ", ".join(sorted(self._plugins)) nxt = ' ' * (utf8_width(key) - 2) + ': ' width = 80 if hasattr(self.base, 'term'): width = self.base.term.columns self.verbose_logger.log( logginglevels.INFO_2, fill(val, width=width, initial_indent=key, subsequent_indent=nxt)) if self.disabledPlugins: for wc in self.disabledPlugins: if wc not in self._used_disable_plugin: self.verbose_logger.log(logginglevels.INFO_2, _("No plugin match for: %s") % wc) del self._used_disable_plugin if self.enabledPlugins: for wc in self.enabledPlugins: if wc not in self._used_enable_plugin: self.verbose_logger.log(logginglevels.INFO_2, _("No plugin match for: %s") % wc) del self._used_enable_plugin
def clean_up(): if tmpdir: try: shutil.rmtree(tmpdir) except OSError, ex: if ex.errno != errno.ENOENT: error_msg(_("Can't remove '{0}': {1}").format(tmpdir, ex))
def has_space(self, percentage=100): """ See if we have enough space to try a snapshot. """ ret = False for vgname in self._vgnames: use = self._use_dev(vgname) if use is not None and not use: continue vg = lvm.vgOpen(vgname, 'r') if not vg: raise _ResultError( _("Unknown error when opening volume group ") + vgname) vgfsize = vg.getFreeSize() lvssize = 0 for lv in vg.listLVs(): if not self._use_dev(vgname, lv): continue lvssize += lv.getSize() vg.close() if not lvssize: continue ret = True if (lvssize * percentage) > (100 * vgfsize): return False return ret
def has_space(self, percentage=100): """ See if we have enough space to try a snapshot. """ ret = False for vgname in self._vgnames: use = self._use_dev(vgname) if use is not None and not use: continue vg = lvm.vgOpen(vgname, "r") if not vg: raise _ResultError(_("Unknown error when opening volume group ") + vgname) vgfsize = vg.getFreeSize() lvssize = 0 for lv in vg.listLVs(): if not self._use_dev(vgname, lv): continue lvssize += lv.getSize() vg.close() if not lvssize: continue ret = True if (lvssize * percentage) > (100 * vgfsize): return False return ret
def _list_vg_names(): try: names = lvm.listVgNames() except LibLVMError: # Try to use the lvm binary instead names = [] if not names: # Could be just broken... p = subprocess.Popen(["/sbin/lvm", "vgs", "-o", "vg_name"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) err = p.wait() if err: raise _ResultError(_("Failed to obtain volume group names")) output = p.communicate()[0] output = output.split('\n') if not output: return [] header = output[0].strip() if header != 'VG': return [] names = [] for name in output[1:]: if not name: break names.append(name.strip()) return names
def _list_vg_names(): try: names = lvm.listVgNames() except LibLVMError: # Try to use the lvm binary instead names = [] if not names: # Could be just broken... p = subprocess.Popen(["/sbin/lvm", "vgs", "-o", "vg_name"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) err = p.wait() if err: raise _ResultError(_("Failed to obtain volume group names")) output = p.communicate()[0] output = output.split("\n") if not output: return [] header = output[0].strip() if header != "VG": return [] names = [] for name in output[1:]: if not name: break names.append(name.strip()) return names
def rpmdb_warn_checks(): try: probs = base._rpmdb_warn_checks(out=verbose_logger.info, warn=False) except Errors.YumBaseError, e: # This is mainly for PackageSackError from rpmdb. verbose_logger.info(_(" Yum checks failed: %s"), exception2msg(e)) probs = []
def waitForLock(self): lockerr = "" while True: try: self.doLock() except Errors.LockError, e: if exception2msg(e) != lockerr: lockerr = exception2msg(e) self.logger.critical(lockerr) if not self.conf.exit_on_lock: self.logger.critical("Another app is currently holding the yum lock; waiting for it to exit...") show_lock_owner(e.pid, self.logger) time.sleep(2) else: raise Errors.YumBaseError, _("Another app is currently holding the yum lock; exiting as configured by exit_on_lock") else: break
def waitForLock(self): lockerr = "" while True: try: self.doLock() except Errors.LockError, e: if "%s" %(e.msg,) != lockerr: lockerr = "%s" %(e.msg,) self.logger.critical(lockerr) if not self.conf.exit_on_lock: self.logger.critical("Another app is currently holding the yum lock; waiting for it to exit...") show_lock_owner(e.pid, self.logger) time.sleep(2) else: raise Errors.YumBaseError, _("Another app is currently holding the yum lock; exiting as configured by exit_on_lock") else: break
def updateProgress(self, name, frac, fread, ftime): """ A method used to update the progress Arguments: name - filename frac - progress fracment (0 -> 1) fread - formated string containing BytesRead ftime - formated string containing remaining or elapsed time """ pct = int(frac * 100) if pct == self.last_pct: log2("percentage is the same, not updating progress") return self.last_pct = pct # if run from terminal we can have fancy output if sys.stdout.isatty(): sys.stdout.write("\033[sDownloading (%i of %i) %s: %3u%%\033[u" % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) ) if pct == 100: #print (_("Downloading (%i of %i) %s: %3u%%") # % (self.downloaded_pkgs + 1, self.total_pkgs, name, pct) #) print (_("Downloading ({0} of {1}) {2}: {3:3}%").format( self.downloaded_pkgs + 1, self.total_pkgs, name, pct ) ) # but we want machine friendly output when spawned from abrt-server else: t = time.time() if self.last_time == 0: self.last_time = t # update only every 5 seconds if pct == 100 or self.last_time > t or t - self.last_time >= 5: print (_("Downloading ({0} of {1}) {2}: {3:3}%").format( self.downloaded_pkgs + 1, self.total_pkgs, name, pct ) ) self.last_time = t if pct == 100: self.last_time = 0 sys.stdout.flush()
def initialize_repositories(self): # setting-up repos one-by-one, so we can skip the broken ones... # this helps when users are using 3rd party repos like rpmfusion # in rawhide it results in: Can't find valid base url... for r in self.base.repos.findRepos(pattern=self.repo_pattern): try: rid = self.base.repos.enableRepo(r.id) self.base.repos.doSetup(thisrepo=str(r.id)) log1("enabled repo %s", rid) setattr(r, "skip_if_unavailable", True) # yes, we want async download, otherwise our progressCallback # is not called and the internal yum's one is used, # which causes artifacts on output try: setattr(r, "_async", False) except (NameError, AttributeError) as ex: print(str(ex)) print( _("Can't disable async download, the output might contain artifacts!" )) except YumBaseError as ex: print( _("Can't setup {0}: {1}, disabling").format(r.id, str(ex))) self.base.repos.disableRepo(r.id) # This is somewhat "magic", it unpacks the metadata making it usable. # Looks like this is the moment when yum talks to remote servers, # which takes time (sometimes minutes), let user know why # we have "paused": try: self.base.repos.populateSack(mdtype='metadata', cacheonly=1) except YumBaseError as ex: print(_("Error retrieving metadata: '{0!s}'").format(str(ex))) #we don't want to die here, some metadata might be already retrieved # so there is a chance we already have what we need #return 1 try: # Saw this exception here: # raise Errors.NoMoreMirrorsRepoError, errstr # NoMoreMirrorsRepoError: failure: # repodata/7e6632b82c91a2e88a66ad848e231f14c48259cbf3a1c3e992a77b1fc0e9d2f6-filelists.sqlite.bz2 # from fedora-debuginfo: [Errno 256] No more mirrors to try. self.base.repos.populateSack(mdtype='filelists', cacheonly=1) except YumBaseError as ex: print(_("Error retrieving filelists: '{0!s}'").format(str(ex)))
def doUtilConfigSetup(self, args=sys.argv[1:], pluginsTypes=(plugins.TYPE_CORE, )): """Parse command line options, and perform configuration. :param args: list of arguments to use for configuration :param pluginsTypes: a sequence specifying the types of plugins to load :return: a dictionary containing the values of command line options """ # Parse only command line options that affect basic yum setup opts = self._parser.firstParse(args) # go through all the setopts and set the global ones self._parseSetOpts(opts.setopts) if self.main_setopts: for opt in self.main_setopts.items: setattr(opts, opt, getattr(self.main_setopts, opt)) # Just print out the version if that's what the user wanted if opts.version: self._printUtilVersion() sys.exit(0) # get the install root to use root = self._parser.getRoot(opts) if opts.quiet: opts.debuglevel = 0 if opts.verbose: opts.debuglevel = opts.errorlevel = 6 # Read up configuration options and initialise plugins try: pc = self.preconf pc.fn = opts.conffile pc.root = root pc.init_plugins = not opts.noplugins pc.plugin_types = pluginsTypes pc.optparser = self._parser pc.debuglevel = opts.debuglevel pc.errorlevel = opts.errorlevel if hasattr(opts, "disableplugins"): pc.disabled_plugins = self._parser._splitArg( opts.disableplugins) if hasattr(opts, "enableplugins"): pc.enabled_plugins = self._parser._splitArg(opts.enableplugins) if hasattr(opts, "releasever"): pc.releasever = opts.releasever self.conf # now set all the non-first-start opts from main from our setopts if self.main_setopts: for opt in self.main_setopts.items: setattr(self.conf, opt, getattr(self.main_setopts, opt)) except Errors.ConfigError, e: self.logger.critical(_('Config Error: %s'), exception2msg(e)) sys.exit(1)
def _importplugins(self, types): '''Load plugins matching the given types. ''' # Initialise plugin dict self._plugins = {} self._pluginfuncs = {} for slot in SLOTS: self._pluginfuncs[slot] = [] # Import plugins self._used_disable_plugin = set() self._used_enable_plugin = set() for dir in self.searchpath: if not os.path.isdir(dir): continue for modulefile in sorted(glob.glob('%s/*.py' % dir)): self._loadplugin(modulefile, types) # If we are in verbose mode we get the full 'Loading "blah" plugin' lines if (self._plugins and not self.verbose_logger.isEnabledFor(logginglevels.DEBUG_3)): # Mostly copied from YumOutput._outKeyValFill() key = _("Loaded plugins: ") val = ", ".join(sorted(self._plugins)) nxt = ' ' * (utf8_width(key) - 2) + ': ' width = 80 if hasattr(self.base, 'term'): width = self.base.term.columns self.verbose_logger.log(logginglevels.INFO_2, fill(val, width=width, initial_indent=key, subsequent_indent=nxt)) if self.disabledPlugins: for wc in self.disabledPlugins: if wc not in self._used_disable_plugin: self.verbose_logger.log(logginglevels.INFO_2, _("No plugin match for: %s") % wc) del self._used_disable_plugin if self.enabledPlugins: for wc in self.enabledPlugins: if wc not in self._used_enable_plugin: self.verbose_logger.log(logginglevels.INFO_2, _("No plugin match for: %s") % wc) del self._used_enable_plugin
def __init__(self, cache, tmp, keep_rpms=False): self.cachedir = cache self.tmpdir = tmp self.keeprpms = keep_rpms YumBase.__init__(self) mute_stdout() #self.conf.cache = os.geteuid() != 0 # Setup yum (Ts, RPM db, Repo & Sack) try: # Saw this exception here: # cannot open Packages index using db3 - Permission denied (13) # yum.Errors.YumBaseError: Error: rpmdb open failed self.doConfigSetup() except Exception, e: unmute_stdout() print _("Error initializing yum (YumBase.doConfigSetup): '%s'") % str(e) #return 1 - can't do this in constructor exit(1)
def exUserCancel(self): """Output a message stating that the operation was cancelled by the user. :return: the exit code """ self.logger.critical(_('\n\nExiting on user cancel')) if self.unlock(): return 200 return 1
def __init__(self, cache, tmp, keep_rpms=False): self.cachedir = cache self.tmpdir = tmp self.keeprpms = keep_rpms YumBase.__init__(self) mute_stdout() #self.conf.cache = os.geteuid() != 0 # Setup yum (Ts, RPM db, Repo & Sack) try: # Saw this exception here: # cannot open Packages index using db3 - Permission denied (13) # yum.Errors.YumBaseError: Error: rpmdb open failed self.doConfigSetup() except Exception, e: unmute_stdout() print _("Error initializing yum (YumBase.doConfigSetup): '%s'" ) % str(e) #return 1 - can't do this in constructor exit(1)
def initialize_repositories(self): # setting-up repos one-by-one, so we can skip the broken ones... # this helps when users are using 3rd party repos like rpmfusion # in rawhide it results in: Can't find valid base url... for r in self.base.repos.findRepos(pattern=self.repo_pattern): try: rid = self.base.repos.enableRepo(r.id) self.base.repos.doSetup(thisrepo=str(r.id)) log1("enabled repo %s", rid) setattr(r, "skip_if_unavailable", True) # yes, we want async download, otherwise our progressCallback # is not called and the internal yum's one is used, # which causes artifacts on output try: setattr(r, "_async", False) except (NameError, AttributeError) as ex: print(str(ex)) print(_("Can't disable async download, the output might contain artifacts!")) except YumBaseError as ex: print(_("Can't setup {0}: {1}, disabling").format(r.id, str(ex))) self.base.repos.disableRepo(r.id) # This is somewhat "magic", it unpacks the metadata making it usable. # Looks like this is the moment when yum talks to remote servers, # which takes time (sometimes minutes), let user know why # we have "paused": try: self.base.repos.populateSack(mdtype='metadata', cacheonly=1) except YumBaseError as ex: print(_("Error retrieving metadata: '{0!s}'").format(str(ex))) #we don't want to die here, some metadata might be already retrieved # so there is a chance we already have what we need #return 1 try: # Saw this exception here: # raise Errors.NoMoreMirrorsRepoError, errstr # NoMoreMirrorsRepoError: failure: # repodata/7e6632b82c91a2e88a66ad848e231f14c48259cbf3a1c3e992a77b1fc0e9d2f6-filelists.sqlite.bz2 # from fedora-debuginfo: [Errno 256] No more mirrors to try. self.base.repos.populateSack(mdtype='filelists', cacheonly=1) except YumBaseError as ex: print(_("Error retrieving filelists: '{0!s}'").format(str(ex)))
def download(self, files): """ @files - """ installed_size = 0 total_pkgs = 0 todownload_size = 0 downloaded_pkgs = 0 # nothing to download? if not files: return #if verbose == 0: # # this suppress yum messages about setting up repositories # mute_stdout() # make yumdownloader work as non root user if not self.setCacheDir(): self.logger.error("Error: can't make cachedir, exiting") exit(50) # disable all not needed for repo in self.repos.listEnabled(): repo.close() self.repos.disableRepo(repo.id) # enable -debuginfo repos for repo in self.repos.findRepos(pattern="*debuginfo*"): #print repo repo.enable() rid = self.repos.enableRepo(repo.id) log1("enabled repo %s", rid) setattr(repo, "skip_if_unavailable", True) self.repos.doSetup() # This is somewhat "magic", it unpacks the metadata making it usable. # Looks like this is the moment when yum talks to remote servers, # which takes time (sometimes minutes), let user know why # we have "paused": print _("Looking for needed packages in repositories") try: self.repos.populateSack(mdtype='metadata', cacheonly=1) except Exception, e: print _("Error retrieving metadata: '%s'") % str(e) return 1
def doUtilConfigSetup(self,args = sys.argv[1:],pluginsTypes=(plugins.TYPE_CORE,)): """Parse command line options, and perform configuration. :param args: list of arguments to use for configuration :param pluginsTypes: a sequence specifying the types of plugins to load :return: a dictionary containing the values of command line options """ # Parse only command line options that affect basic yum setup opts = self._parser.firstParse(args) # go through all the setopts and set the global ones self._parseSetOpts(opts.setopts) if self.main_setopts: for opt in self.main_setopts.items: setattr(opts, opt, getattr(self.main_setopts, opt)) # Just print out the version if that's what the user wanted if opts.version: self._printUtilVersion() sys.exit(0) # get the install root to use root = self._parser.getRoot(opts) if opts.quiet: opts.debuglevel = 0 if opts.verbose: opts.debuglevel = opts.errorlevel = 6 # Read up configuration options and initialise plugins try: pc = self.preconf pc.fn = opts.conffile pc.root = root pc.init_plugins = not opts.noplugins pc.plugin_types = pluginsTypes pc.optparser = self._parser pc.debuglevel = opts.debuglevel pc.errorlevel = opts.errorlevel if hasattr(opts, "disableplugins"): pc.disabled_plugins =self._parser._splitArg(opts.disableplugins) if hasattr(opts, "enableplugins"): pc.enabled_plugins = self._parser._splitArg(opts.enableplugins) if hasattr(opts, "releasever"): pc.releasever = opts.releasever self.conf # now set all the non-first-start opts from main from our setopts if self.main_setopts: for opt in self.main_setopts.items: setattr(self.conf, opt, getattr(self.main_setopts, opt)) except Errors.ConfigError, e: self.logger.critical(_('Config Error: %s'), exception2msg(e)) sys.exit(1)
def __init__(self, base, searchpath, optparser=None, types=None, pluginconfpath=None, disabled=None, enabled=None): '''Initialise the instance. @param base: The @param searchpath: A list of paths to look for plugin modules. @param optparser: The OptionParser instance for this run (optional). Use to allow plugins to extend command line options. @param types: A sequence specifying the types of plugins to load. This should be sequnce containing one or more of the TYPE_... constants. If None (the default), all plugins will be loaded. @param pluginconfpath: A list of paths to look for plugin configuration files. Defaults to "/etc/yum/pluginconf.d". ''' if not pluginconfpath: pluginconfpath = ['/etc/yum/pluginconf.d'] self.searchpath = searchpath self.pluginconfpath = pluginconfpath self.base = weakref(base) self.optparser = optparser self.cmdline = (None, None) self.verbose_logger = logging.getLogger("yum.verbose.YumPlugins") self.disabledPlugins = disabled self.enabledPlugins = enabled if types is None: types = ALL_TYPES if not isinstance(types, (list, tuple)): types = (types, ) if id(TYPE_INTERFACE) in [id(t) for t in types]: self.verbose_logger.log( logginglevels.INFO_2, 'Deprecated constant TYPE_INTERFACE during plugin ' 'initialization.\nPlease use TYPE_INTERACTIVE instead.') self._importplugins(types) self.cmdlines = {} # Call close handlers when yum exit's if self._pluginfuncs['close']: self.verbose_logger.error( _('One or more plugins uses "close" handling but should use atexit directly.' )) atexit.register(self.run, 'close') # Let plugins register custom config file options self.run('config')
def show_lock_owner(pid, logger): if not pid: return ps = get_process_info(pid) # This yumBackend isn't very friendly, so... if ps is not None and ps['name'] == 'yumBackend.py': nmsg = _(" The other application is: PackageKit") else: nmsg = _(" The other application is: %s") % ps['name'] logger.critical("%s", nmsg) logger.critical(_(" Memory : %5s RSS (%5sB VSZ)") % (format_number(int(ps['vmrss']) * 1024), format_number(int(ps['vmsize']) * 1024))) ago = seconds_to_ui_time(int(time.time()) - ps['start_time']) logger.critical(_(" Started: %s - %s ago") % (time.ctime(ps['start_time']), ago)) logger.critical(_(" State : %s, pid: %d") % (ps['state'], pid))
def registerCommand(self, command): """Register a new command. :param command: the command to register :raises: :class:`yum.Errors.ConfigError` if the registration of commands is not supported """ if hasattr(self._base, 'registerCommand'): self._base.registerCommand(command) else: raise Errors.ConfigError(_('registration of commands not supported'))
def clean_up(): """ Removes the temporary directory. """ if TMPDIR: try: shutil.rmtree(TMPDIR) except OSError, ex: if ex.errno != errno.ENOENT: error_msg(_("Can't remove '{0}': {1}").format(TMPDIR, ex))
def registerCommand(self, command): """Register a new command. :param command: the command to register :raises: :class:`yum.Errors.ConfigError` if the registration of commands is not supported """ if hasattr(self._base, 'registerCommand'): self._base.registerCommand(command) else: raise Errors.ConfigError( _('registration of commands not supported'))