[Yum-devel] [PATCH] Add skipped_packages to history.
James Antill
james at and.org
Thu Apr 22 22:53:55 UTC 2010
---
output.py | 23 +++++++++++++++++-
yum/__init__.py | 3 +-
yum/history.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 88 insertions(+), 4 deletions(-)
diff --git a/output.py b/output.py
index 452f8a2..4274b3f 100755
--- a/output.py
+++ b/output.py
@@ -1313,6 +1313,8 @@ to exit.
# We don't check .errors, because return_code will be non-0
elif old.output:
rmark = lmark = 'E'
+ elif old.trans_skip:
+ rmark = lmark = 'S'
if old.altered_lt_rpmdb:
rmark = '<'
if old.altered_gt_rpmdb:
@@ -1465,11 +1467,28 @@ to exit.
state = _('Updated')
elif ipkgs[0] < hpkg:
state = _('Downgraded')
- else: # multiple versions installed, both older and newer
- state = _('Weird')
+ else:
+ assert False, "Impossible, installed not newer and not older"
print "%s%s %s" % (prefix, utf8_width_fill(state, 12), hpkg)
print _("Packages Altered:")
self.historyInfoCmdPkgsAltered(old, pats)
+ print _("Packages Skipped:")
+ for hpkg in old.trans_skip:
+ prefix = " " * 4
+ state = _('Installed')
+ ipkgs = self.rpmdb.searchNames([hpkg.name])
+ ipkgs.sort()
+ if not ipkgs:
+ state = _('Not installed')
+ elif hpkg.pkgtup in (ipkg.pkgtup for ipkg in ipkgs):
+ pass
+ elif ipkgs[-1] > hpkg:
+ state = _('Older')
+ elif ipkgs[0] < hpkg:
+ state = _('Newer')
+ else:
+ assert False, "Impossible, installed not newer and not older"
+ print "%s%s %s" % (prefix, utf8_width_fill(state, 12), hpkg)
if old.output:
print _("Scriptlet output:")
num = 0
diff --git a/yum/__init__.py b/yum/__init__.py
index 4fee2c7..87644a1 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1201,7 +1201,8 @@ class YumBase(depsolve.Depsolve):
if lastdbv is None or rpmdbv != lastdbv:
self._rpmdb_warn_checks(warn=lastdbv is not None)
if self.conf.history_record:
- self.history.beg(rpmdbv, using_pkgs, list(self.tsInfo))
+ self.history.beg(rpmdbv, using_pkgs, list(self.tsInfo),
+ self.skipped_packages)
# Just before we update the transaction, update what we think the
# rpmdb will look like. This needs to be done before the run, so that if
diff --git a/yum/history.py b/yum/history.py
index 3ef5f74..1865cdb 100644
--- a/yum/history.py
+++ b/yum/history.py
@@ -128,6 +128,7 @@ class YumHistoryTransaction:
self._loaded_TW = None
self._loaded_TD = None
+ self._loaded_TS = None
self._loaded_ER = None
self._loaded_OT = None
@@ -153,9 +154,14 @@ class YumHistoryTransaction:
if self._loaded_TD is None:
self._loaded_TD = sorted(self._history._old_data_pkgs(self.tid))
return self._loaded_TD
+ def _getTransSkip(self):
+ if self._loaded_TS is None:
+ self._loaded_TS = sorted(self._history._old_skip_pkgs(self.tid))
+ return self._loaded_TS
trans_with = property(fget=lambda self: self._getTransWith())
trans_data = property(fget=lambda self: self._getTransData())
+ trans_skip = property(fget=lambda self: self._getTransSkip())
def _getErrors(self):
if self._loaded_ER is None:
@@ -308,6 +314,17 @@ class YumHistory:
VALUES (?, ?)""", (self._tid, pid))
return cur.lastrowid
+ def trans_skip_pid(self, pid):
+ cur = self._get_cursor()
+ if cur is None or not self._update_db_file_1_2():
+ return None
+
+ res = executeSQL(cur,
+ """INSERT INTO trans_skip_pkgs
+ (tid, pkgtupid)
+ VALUES (?, ?)""", (self._tid, pid))
+ return cur.lastrowid
+
def trans_data_pid_beg(self, pid, state):
assert state is not None
if not hasattr(self, '_tid') or state is None:
@@ -335,7 +352,7 @@ class YumHistory:
self._commit()
return cur.lastrowid
- def beg(self, rpmdb_version, using_pkgs, txmbrs):
+ def beg(self, rpmdb_version, using_pkgs, txmbrs, skip_packages=[]):
cur = self._get_cursor()
if cur is None:
return
@@ -356,6 +373,10 @@ class YumHistory:
state = self.txmbr2state(txmbr)
self.trans_data_pid_beg(pid, state)
+ for pkg in skip_packages:
+ pid = self.pkg2pid(pkg)
+ self.trans_skip_pid(pid)
+
self._commit()
def _log_errors(self, errors):
@@ -464,6 +485,20 @@ class YumHistory:
obj.state_installed = False
ret.append(obj)
return ret
+ def _old_skip_pkgs(self, tid):
+ cur = self._get_cursor()
+ if cur is None or not self._update_db_file_1_2():
+ return []
+ executeSQL(cur,
+ """SELECT name, arch, epoch, version, release, checksum
+ FROM trans_skip_pkgs JOIN pkgtups USING(pkgtupid)
+ WHERE tid = ?
+ ORDER BY name ASC, epoch ASC""", (tid,))
+ ret = []
+ for row in cur:
+ obj = YumHistoryPackage(row[0],row[1],row[2],row[3],row[4], row[5])
+ ret.append(obj)
+ return ret
def old(self, tids=[], limit=None, complete_transactions_only=False):
""" Return a list of the last transactions, note that this includes
@@ -607,6 +642,33 @@ class YumHistory:
tids.add(row[0])
return tids
+ _update_ops_1_2 = ['''\
+\
+ CREATE TABLE trans_skip_pkgs (
+ tid INTEGER NOT NULL REFERENCES trans_beg,
+ pkgtupid INTEGER NOT NULL REFERENCES pkgtups);
+''']
+
+ def _update_db_file_1_2(self):
+ """ Update from before trans_skip_pkgs to after. """
+ cur = self._get_cursor()
+ if cur is None:
+ return False
+ if hasattr(self, '_cached_updated_1_2'):
+ return self._cached_updated_1_2
+
+ executeSQL(cur, "PRAGMA table_info(trans_skip_pkgs)")
+ # If we get anything, we're fine. There might be a better way of
+ # saying "anything" but this works.
+ for ob in cur:
+ break
+ else:
+ for op in self._update_ops_1_2:
+ cur.execute(op)
+ self._commit()
+ self._cached_updated_1_2 = True
+ return True
+
def _create_db_file(self):
""" Create a new history DB file, populating tables etc. """
@@ -668,6 +730,8 @@ class YumHistory:
''']
for op in ops:
cur.execute(op)
+ for op in self._update_ops_1_2:
+ cur.execute(op)
self._commit()
# Pasted from sqlitesack
--
1.6.6.1
More information about the Yum-devel
mailing list