Fixed pylint errors in yumhelper.py
This commit is contained in:
parent
ea6139f125
commit
c062a954f7
@ -39,23 +39,23 @@ from sysutils import joinpaths
|
|||||||
|
|
||||||
class LoraxYumHelper(object):
|
class LoraxYumHelper(object):
|
||||||
|
|
||||||
def __init__(self, yb):
|
def __init__(self, ybo):
|
||||||
self.yb = yb
|
self.ybo = ybo
|
||||||
|
|
||||||
# create our own installroot, the pungi one may be poluted
|
# create our own installroot, the pungi one may be poluted
|
||||||
installroot = joinpaths(self.yb.conf.installroot, "installroot")
|
installroot = joinpaths(self.ybo.conf.installroot, "installroot")
|
||||||
os.makedirs(installroot)
|
os.makedirs(installroot)
|
||||||
self.yb.conf.installroot = installroot
|
self.ybo.conf.installroot = installroot
|
||||||
|
|
||||||
self.installroot = self.yb.conf.installroot
|
self.installroot = self.ybo.conf.installroot
|
||||||
self.installed_packages = self.get_packages("installed")
|
self.installed_packages = self.get_packages("installed")
|
||||||
|
|
||||||
def install(self, pattern):
|
def install(self, pattern):
|
||||||
try:
|
try:
|
||||||
self.yb.install(name=pattern)
|
self.ybo.install(name=pattern)
|
||||||
except yum.Errors.InstallError:
|
except yum.Errors.InstallError:
|
||||||
try:
|
try:
|
||||||
self.yb.install(pattern=pattern)
|
self.ybo.install(pattern=pattern)
|
||||||
except yum.Errors.InstallError as e:
|
except yum.Errors.InstallError as e:
|
||||||
msg = "cannot install {0}: {1}"
|
msg = "cannot install {0}: {1}"
|
||||||
logger.error(msg.format(pattern, e))
|
logger.error(msg.format(pattern, e))
|
||||||
@ -71,7 +71,7 @@ class LoraxYumHelper(object):
|
|||||||
logger.error(msg.format(package))
|
logger.error(msg.format(package))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# XXX match every file if no pattern specified
|
# match every file if no pattern specified
|
||||||
if None in pattern_list:
|
if None in pattern_list:
|
||||||
if len(pattern_list) > 1:
|
if len(pattern_list) > 1:
|
||||||
msg = "redundant patterns specified, " \
|
msg = "redundant patterns specified, " \
|
||||||
@ -132,34 +132,34 @@ class LoraxYumHelper(object):
|
|||||||
|
|
||||||
def process_transaction(self, skip_broken=True):
|
def process_transaction(self, skip_broken=True):
|
||||||
# skip broken
|
# skip broken
|
||||||
self.yb.conf.skip_broken = skip_broken
|
self.ybo.conf.skip_broken = skip_broken
|
||||||
self.yb.buildTransaction()
|
self.ybo.buildTransaction()
|
||||||
|
|
||||||
self.yb.repos.setProgressBar(LoraxDownloadCallback())
|
self.ybo.repos.setProgressBar(LoraxDownloadCallback())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.yb.processTransaction(callback=LoraxTransactionCallback(),
|
self.ybo.processTransaction(callback=LoraxTransactionCallback(),
|
||||||
rpmDisplay=LoraxRpmCallback())
|
rpmDisplay=LoraxRpmCallback())
|
||||||
except yum.Errors.YumRPMCheckError as e:
|
except yum.Errors.YumRPMCheckError as e:
|
||||||
logger.error("yum transaction error: {0}".format(e))
|
logger.error("yum transaction error: {0}".format(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
self.yb.closeRpmDB()
|
self.ybo.closeRpmDB()
|
||||||
|
|
||||||
self.installed_packages = self.get_packages("installed")
|
self.installed_packages = self.get_packages("installed")
|
||||||
|
|
||||||
def search(self, pattern):
|
def search(self, pattern):
|
||||||
pl = self.yb.doPackageLists(patterns=[pattern])
|
pl = self.ybo.doPackageLists(patterns=[pattern])
|
||||||
return pl.installed, pl.available
|
return pl.installed, pl.available
|
||||||
|
|
||||||
def get_packages(self, type="available"):
|
def get_packages(self, ptype="available"):
|
||||||
if type not in ("available", "installed"):
|
if ptype not in ("available", "installed"):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
pl = self.yb.doPackageLists(pkgnarrow=type)
|
pl = self.ybo.doPackageLists(pkgnarrow=ptype)
|
||||||
|
|
||||||
d = {}
|
d = {}
|
||||||
for pkgobj in getattr(pl, type):
|
for pkgobj in getattr(pl, ptype):
|
||||||
d[pkgobj.name] = pkgobj
|
d[pkgobj.name] = pkgobj
|
||||||
|
|
||||||
return d
|
return d
|
||||||
@ -183,15 +183,15 @@ class LoraxDownloadCallback(yum.callbacks.DownloadBaseCallback):
|
|||||||
@param ftime: formated string containing remaining or elapsed time
|
@param ftime: formated string containing remaining or elapsed time
|
||||||
"""
|
"""
|
||||||
|
|
||||||
m = self.pattern.match(name)
|
match = self.pattern.match(name)
|
||||||
|
|
||||||
pkgno = 0
|
pkgno = 0
|
||||||
total = 0
|
total = 0
|
||||||
pkgname = "error"
|
pkgname = "error"
|
||||||
if m:
|
if match:
|
||||||
pkgno = int(m.group("pkgno"))
|
pkgno = int(match.group("pkgno"))
|
||||||
total = int(m.group("total"))
|
total = int(match.group("total"))
|
||||||
pkgname = m.group("pkgname")
|
pkgname = match.group("pkgname")
|
||||||
|
|
||||||
info = "({0:3d}/{1:3d}) [{2:3.0f}%] downloading "
|
info = "({0:3d}/{1:3d}) [{2:3.0f}%] downloading "
|
||||||
info = info.format(pkgno, total, frac * 100)
|
info = info.format(pkgno, total, frac * 100)
|
||||||
@ -212,7 +212,6 @@ class LoraxTransactionCallback(object):
|
|||||||
self.output = output.LoraxOutput()
|
self.output = output.LoraxOutput()
|
||||||
|
|
||||||
def event(self, state, data=None):
|
def event(self, state, data=None):
|
||||||
# XXX
|
|
||||||
if state == yum.callbacks.PT_DOWNLOAD:
|
if state == yum.callbacks.PT_DOWNLOAD:
|
||||||
self.output.write("downloading packages\n")
|
self.output.write("downloading packages\n")
|
||||||
elif state == yum.callbacks.PT_DOWNLOAD_PKGS:
|
elif state == yum.callbacks.PT_DOWNLOAD_PKGS:
|
||||||
|
Loading…
Reference in New Issue
Block a user