本文整理汇总了Python中yum._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download
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))
示例2: unpack_rpm
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
示例3: exIOError
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
示例4: updateProgress
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()
示例5: __init__
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)
示例6: prepare
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)))
示例7: exIOError
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
示例8: exRepoError
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
示例9: downloadErrorCallback
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}
示例10: unpack_rpm
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
示例11: unpack_rpm
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
示例12: exIOError
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
示例13: __init__
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')
示例14: __init__
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")
示例15: snapshot
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