from mic import msger
from mic.utils import errors, proxy, misc
-from mic.utils.rpmmisc import readRpmHeader, RPMInstallCallback
+from mic.utils.rpmmisc import readRpmHeader, RPMCallback
from mic.chroot import cleanup_mounts, setup_chrootenv, cleanup_chrootenv
from mic.conf import configmgr
from functools import reduce
# run transaction
self.ts.order()
- cb = RPMInstallCallback(self.ts)
+ cb = RPMCallback(self.ts)
errs = self.ts.run(cb.callback, '')
# ts.run() exit codes are, hmm, "creative": None means all ok, empty
from mic.utils.proxy import get_proxy_for
from mic.utils import runner
-class RPMInstallCallback:
+class RPMCallback:
""" Command line callback class for callbacks from the RPM library.
"""
self.total_installed = 0
self.total_installing = 0
self.installed_pkg_names = []
- self.total_removed = 0
- self.total_removing = 0
+ self.total_uninstalled = 0
+ self.total_uninstalling = 0
self.mark = "+"
self.marks = 40
self.lastmsg = None
fmt_bar = "%-" + width + "s"
if progress:
bar = fmt_bar % (self.mark * int(marks * (percent / 100.0)), )
- fmt = "%-10.10s: %-50.50s " + bar + " " + done
+ fmt = "%s: %-50.50s " + bar + " " + done
else:
bar = fmt_bar % (self.mark * marks, )
- fmt = "%-10.10s: %-50.50s " + bar + " " + done
+ fmt = "%s: %-50.50s " + bar + " " + done
return fmt
def _logPkgString(self, hdr):
return pkg
+ def _getPkgName(self, rpmloc):
+ pkgname = ""
+ if rpmloc is not None:
+ m = re.match(r"(.*)-(\d+.*)-(\d+\.\d+)\.(.+)\.rpm", os.path.basename(rpmloc))
+ if m:
+ pkgname = m.group(1)
+ else:
+ pkgname = os.path.basename(rpmloc)
+ return pkgname
+
def callback(self, what, bytes, total, h, user):
if what == rpm.RPMCALLBACK_TRANS_START:
if bytes == 6:
rpmloc = h
hdr = readRpmHeader(self.ts, h)
- m = re.match(r"(.*)-(\d+.*)-(\d+\.\d+)\.(.+)\.rpm", os.path.basename(rpmloc))
- if m:
- pkgname = m.group(1)
- else:
- pkgname = os.path.basename(rpmloc)
- msger.info("Next install: %s " % pkgname)
+ msger.info("Next install: %s " % self._getPkgName(rpmloc))
handle = self._makeHandle(hdr)
fd = os.open(rpmloc, os.O_RDONLY)
elif what == rpm.RPMCALLBACK_INST_PROGRESS:
if h is not None:
- percent = (self.total_installed*100)/self.total_actions
+ actions = self.total_installing + self.total_uninstalling
+ percent = (actions*100)/self.total_actions
if total > 0:
try:
hdr, rpmloc = h
except:
rpmloc = h
- m = re.match(r"(.*)-(\d+.*)-(\d+\.\d+)\.(.+)\.rpm", os.path.basename(rpmloc))
- if m:
- pkgname = m.group(1)
- else:
- pkgname = os.path.basename(rpmloc)
+ pkgname = self._getPkgName(rpmloc)
if self.output:
- fmt = self._makefmt(self.total_installing, percent)
+ fmt = self._makefmt(actions, percent)
msg = fmt % ("Installing", pkgname)
if msg != self.lastmsg:
self.lastmsg = msg
msger.info(msg)
- if self.total_installed == self.total_actions:
+ if actions == self.total_actions:
msger.raw('')
msger.verbose('\n'.join(self.logString))
elif what == rpm.RPMCALLBACK_UNINST_START:
- self.total_removing += 1
+ self.total_uninstalling += 1
+ if h is not None:
+ try:
+ hdr, rpmloc = h
+ except:
+ rpmloc = h
+
+ msger.info("Next uninstall: %s " % self._getPkgName(rpmloc))
elif what == rpm.RPMCALLBACK_UNINST_PROGRESS:
if h is not None:
- percent = (self.total_removed*100)/self.total_actions
+ actions = self.total_installing + self.total_uninstalling
+ percent = (actions*100)/self.total_actions
if total > 0:
try:
hdr, rpmloc = h
except:
rpmloc = h
- m = re.match(r"(.*)-(\d+.*)-(\d+\.\d+)\.(.+)\.rpm", os.path.basename(rpmloc))
- if m:
- pkgname = m.group(1)
- else:
- pkgname = os.path.basename(rpmloc)
+ pkgname = self._getPkgName(rpmloc)
if self.output:
- fmt = self._makefmt(self.total_removing, percent)
+ fmt = self._makefmt(actions, percent)
msg = fmt % ("Uninstalling", pkgname)
if msg != self.lastmsg:
self.lastmsg = msg
-
msger.info(msg)
- if self.total_installed == self.total_actions:
- msger.raw('')
- msger.verbose('\n'.join(self.logString))
-
elif what == rpm.RPMCALLBACK_UNINST_STOP:
- self.total_removed += 1
+ pass
elif what == rpm.RPMCALLBACK_REPACKAGE_START:
pass
self.__initialize_transaction()
self.ts_pre.order()
- cb = rpmmisc.RPMInstallCallback(self.ts_pre)
+ cb = rpmmisc.RPMCallback(self.ts_pre)
cb.headmsg = "Preinstall"
installlogfile = "%s/__catched_stderr.buf" % (self.instroot)
for pkg_bak in self.pkgs_bak:
self.ts.addInstall(pkg_bak["header"], pkg_bak["rpmpath"], 'u')
self.ts.order()
- cb = rpmmisc.RPMInstallCallback(self.ts)
+ cb = rpmmisc.RPMCallback(self.ts)
installlogfile = "%s/__catched_stderr.buf" % (self.instroot)
# start to catch stderr output from librpm
self.show_unresolved_dependencies_msg(unresolved_dependencies)
raise RpmError("Unresolved dependencies, transaction failed.")
- cb = rpmmisc.RPMInstallCallback(self.ts)
+ cb = rpmmisc.RPMCallback(self.ts)
logfile = "%s/__catched_stderr.buf" % (self.instroot)
# start to catch stderr output from librpm