---
output.py | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
yum/history.py | 29 ++++++++++++++++++
yumcommands.py | 40 +++++++++++++++++++++++++-
3 files changed, 156 insertions(+), 1 deletions(-)
diff --git a/output.py b/output.py
index 00a938d..da34382 100755
--- a/output.py
+++ b/output.py
@@ -47,6 +47,8 @@ import yum.history
from yum.i18n import utf8_width, utf8_width_fill, utf8_text_fill
+import locale
+
def _term_width():
""" Simple terminal width, limit to 20 chars. and make 0 == 80. """
if not hasattr(urlgrabber.progress, 'terminal_width_cached'):
@@ -2445,6 +2447,92 @@ to exit.
if lastdbv.end_rpmdbversion != rpmdbv:
self._rpmdb_warn_checks()
+ def historyPackageInfoCmd(self, extcmds):
+ """Print information about packages in history transactions.
+
+ :param extcmds: list of extra command line arguments
+ """
+ tids = self.history.search(extcmds)
+ limit = None
+ if extcmds and not tids:
+ self.logger.critical(_('Bad transaction IDs, or package(s),
given'))
+ return 1, ['Failed history packages-info']
+ if not tids:
+ limit = 20
+
+ all_uistates = self._history_state2uistate
+
+ num = 0
+ for old in self.history.old(tids, limit=limit):
+ if limit is not None and num and (num +len(old.trans_data)) >
limit:
+ break
+ last = None
+
+ for hpkg in old.trans_data: # Find a pkg to go with each cmd...
+ if limit is None:
+ x,m,u = yum.packages.parsePackages([hpkg], extcmds)
+ if not x and not m:
+ continue
+
+ uistate = all_uistates.get(hpkg.state, hpkg.state)
+ if num:
+ print ""
+ print _("Transaction ID :"), old.tid
+ tm = time.ctime(old.beg_timestamp)
+ print _("Begin time :"), tm
+ print _("Package :"), hpkg.ui_nevra
+ print _("State :"), uistate
+ if hpkg.size is not None:
+ num = int(hpkg.size)
+ print _("Size :"), locale.format("%d", num, True)
+ if hpkg.buildhost is not None:
+ print _("Build host :"), hpkg.buildhost
+ if hpkg.buildtime is not None:
+ tm = time.ctime(int(hpkg.buildtime))
+ print _("Build time :"), tm
+ if hpkg.packager is not None:
+ print _("Packager :"), hpkg.packager
+ if hpkg.vendor is not None:
+ print _("Vendor :"), hpkg.vendor
+ if hpkg.license is not None:
+ print _("License :"), hpkg.license
+ if hpkg.url is not None:
+ print _("URL :"), hpkg.url
+ if hpkg.sourcerpm is not None:
+ print _("Source RPM :"), hpkg.sourcerpm
+ if hpkg.committime is not None:
+ tm = time.ctime(int(hpkg.committime))
+ print _("Commit Time :"), tm
+ if hpkg.committer is not None:
+ print _("Committer :"), hpkg.committer
+ if hpkg.yumdb_info.reason is not None:
+ print _("Reason :"), hpkg.yumdb_info.reason
+ if hpkg.yumdb_info.command_line is not None:
+ print _("Command Line :"), hpkg.yumdb_info.command_line
+ if hpkg.yumdb_info.from_repo is not None:
+ print _("From repo :"), hpkg.yumdb_info.from_repo
+ if hpkg.yumdb_info.installed_by is not None:
+ uid = int(hpkg.yumdb_info.installed_by)
+ name = self._pwd_ui_username(uid)
+ print _("Installed by :"), name
+ if hpkg.yumdb_info.changed_by is not None:
+ uid = int(hpkg.yumdb_info.changed_by)
+ name = self._pwd_ui_username(uid)
+ print _("Changed by :"), name
+
+ num += 1
+
+ # And, again, copy and paste...
+ lastdbv = self.history.last()
+ if lastdbv is None:
+ self._rpmdb_warn_checks(warn=False)
+ else:
+ # If this is the last transaction, is good and it doesn't
+ # match the current rpmdb ... then mark it as bad.
+ rpmdbv = self.rpmdb.simpleVersion(main_only=True)[0]
+ if lastdbv.end_rpmdbversion != rpmdbv:
+ self._rpmdb_warn_checks()
+
class DepSolveProgressCallBack:
"""A class to provide text output callback functions for Dependency Solver
callback."""
diff --git a/yum/history.py b/yum/history.py
index 609394f..c91c33a 100644
--- a/yum/history.py
+++ b/yum/history.py
@@ -1350,6 +1350,35 @@ class YumHistory:
self._commit()
return True
+ def _pkg_stats(self):
+ """ Some stats about packages in the DB. """
+
+ ret = {'nevrac' : 0,
+ 'nevra' : 0,
+ 'nevr' : 0,
+ 'na' : 0,
+ 'rpmdb' : 0,
+ 'yumdb' : 0,
+ }
+ cur = self._get_cursor()
+ if cur is None or not self._update_db_file_3():
+ return False
+
+ data = (('nevrac', "COUNT(*)", "pkgtups"),
+ ('na', "COUNT(DISTINCT(name || arch))", "pkgtups"),
+
('nevra',"COUNT(DISTINCT(name||version||epoch||release||arch))",
+ "pkgtups"),
+ ('nevr', "COUNT(DISTINCT(name||version||epoch||release))",
+ "pkgtups"),
+ ('rpmdb', "COUNT(DISTINCT(pkgtupid))", "pkg_rpmdb"),
+ ('yumdb', "COUNT(DISTINCT(pkgtupid))", "pkg_yumdb"))
+
+ for key, bsql, esql in data:
+ executeSQL(cur, "SELECT %s FROM %s" % (bsql, esql))
+ for row in cur:
+ ret[key] = row[0]
+ return ret
+
def _yieldSQLDataList(self, patterns, fields, ignore_case):
"""Yields all the package data for the given params. """
diff --git a/yumcommands.py b/yumcommands.py
index 3a985c3..d9c70f3 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -2425,6 +2425,36 @@ class HistoryCommand(YumCommand):
def _hcmd_new(self, base, extcmds):
base.history._create_db_file()
+ def _hcmd_stats(self, base, extcmds):
+ print "File :", base.history._db_file
+ num = os.stat(base.history._db_file).st_size
+ print "Size :", locale.format("%d", num, True)
+ counts = base.history._pkg_stats()
+ trans_1 = base.history.old("1")[0]
+ trans_N = base.history.last()
+ print _("Transactions:"), trans_N.tid
+ print _("Begin time :"), time.ctime(trans_1.beg_timestamp)
+ print _("End time :"), time.ctime(trans_N.end_timestamp)
+ print _("Counts :")
+ print _(" NEVRAC :"), locale.format("%6d", counts['nevrac'], True)
+ print _(" NEVRA :"), locale.format("%6d", counts['nevra'], True)
+ print _(" NA :"), locale.format("%6d", counts['na'], True)
+ print _(" NEVR :"), locale.format("%6d", counts['nevr'], True)
+ print _(" rpm DB :"), locale.format("%6d", counts['rpmdb'], True)
+ print _(" yum DB :"), locale.format("%6d", counts['yumdb'], True)
+
+ def _hcmd_sync(self, base, extcmds):
+ extcmds = extcmds[1:]
+ if not extcmds:
+ extcmds = None
+ for ipkg in sorted(base.rpmdb.returnPackages(patterns=extcmds)):
+ if base.history.pkg2pid(ipkg, create=False) is None:
+ continue
+
+ print "Syncing rpm/yum DB data for:", ipkg, "...",
+ base.history.sync_alldb(ipkg)
+ print "Done."
+
def doCheck(self, base, basecmd, extcmds):
"""Verify that conditions are met so that this command can
run. The exact conditions checked will vary depending on the
@@ -2437,8 +2467,10 @@ class HistoryCommand(YumCommand):
cmds = ('list', 'info', 'summary', 'repeat', 'redo', 'undo', 'new',
'rollback',
'addon', 'addon-info',
+ 'stats', 'statistics', 'sync', 'synchronize'
'pkg', 'pkgs', 'pkg-list', 'pkgs-list',
- 'package', 'package-list', 'packages', 'packages-list')
+ 'package', 'package-list', 'packages', 'packages-list',
+ 'pkg-info', 'pkgs-info', 'package-info', 'packages-info')
if extcmds and extcmds[0] not in cmds:
base.logger.critical(_('Invalid history sub-command, use: %s.'),
", ".join(cmds))
@@ -2488,6 +2520,12 @@ class HistoryCommand(YumCommand):
ret = self._hcmd_rollback(base, extcmds)
elif vcmd == 'new':
ret = self._hcmd_new(base, extcmds)
+ elif vcmd in ('stats', 'statistics'):
+ ret = self._hcmd_stats(base, extcmds)
+ elif vcmd in ('sync', 'synchronize'):
+ ret = self._hcmd_sync(base, extcmds)
+ elif vcmd in ('pkg-info', 'pkgs-info', 'package-info',
'packages-info'):
+ ret = base.historyPackageInfoCmd(extcmds)
if ret is None:
return 0, ['history %s' % (vcmd,)]
--
1.7.6
_______________________________________________
Yum-devel mailing list
[email protected]
http://lists.baseurl.org/mailman/listinfo/yum-devel