[yum-commits] Branch 'yum-3_2_X' - 3 commits - yum/history.py yum/__init__.py yum/plugins.py
skvidal at osuosl.org
skvidal at osuosl.org
Tue Jun 22 21:05:50 UTC 2010
yum/__init__.py | 7 ++++--
yum/history.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
yum/plugins.py | 7 ++++++
3 files changed, 71 insertions(+), 3 deletions(-)
New commits:
commit 473a482885d86339377eeb9e976138ffdb67b399
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Tue Jun 22 16:41:13 2010 -0400
- move historyend call to before history.end()
- fix a couple of typos
- check to make sure we're not saving _nothing_
diff --git a/yum/__init__.py b/yum/__init__.py
index 5665617..9a0bc15 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1351,8 +1351,9 @@ class YumBase(depsolve.Depsolve):
else:
if self.conf.history_record and not self.ts.isTsFlagSet(rpm.RPMTRANS_FLAG_TEST):
herrors = [to_unicode(to_str(x)) for x in errors]
+ self.plugins.run('historyend')
self.history.end(rpmdbv, 2, errors=herrors)
- self.plugins.run('historyend')
+
self.logger.critical(_("Transaction couldn't start:"))
for e in errors:
@@ -1473,6 +1474,7 @@ class YumBase(depsolve.Depsolve):
ret = -1
if resultobject is not None:
ret = resultobject.return_code
+ self.plugins.run('historyend')
self.history.end(self.rpmdb.simpleVersion(main_only=True)[0], ret)
self.rpmdb.dropCachedData()
diff --git a/yum/history.py b/yum/history.py
index f785b1a..f84ca61 100644
--- a/yum/history.py
+++ b/yum/history.py
@@ -580,14 +580,21 @@ class YumHistory:
def write_addon_data(dataname, data):
"""append data to an arbitrary-named file in the history
- addon_path/transaction id location"""
+ addon_path/transaction id location,
+ returns True if write succeeded, False if not"""
if not hasattr(self, '_tid'):
# maybe we should raise an exception or a warning here?
return False
+ if not dataname:
+ return False
+
+ if not data:
+ return False
+
# make sure the tid dir exists
- tid_dir = self.conf.addon_path + '/' + self._tid)
+ tid_dir = self.conf.addon_path + '/' + self._tid
if self.conf.writable and not os.path.exists(tid_dir):
try:
@@ -612,7 +619,6 @@ class YumHistory:
# return
return True
-
def _old_with_pkgs(self, tid):
cur = self._get_cursor()
commit eeba965b6f1b1479e003783a2bc04d3fe3ddf1a3
Merge: 8455356... 50aad03...
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Mon Jun 21 17:39:17 2010 -0400
Merge branch 'yum-3_2_X' of ssh://yum.baseurl.org/srv/projects/yum/git/yum into yum-3_2_X
* 'yum-3_2_X' of ssh://yum.baseurl.org/srv/projects/yum/git/yum:
Document the semi-special running kernel protection.
Protect kernel from any kind of removal, in the protection code.
Protect users from manually remove/reinstall the running kernel.
Make "yum list kmod\*" look better (ie. repoid is always overflowing).
Fix/allow reinstalls of installonly packages (BZ 605226):
commit 84553562c8adb24c5d2383d11c8d86b733293aad
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Mon Jun 21 17:37:42 2010 -0400
- add historyend and historybegin plugin conduits
- add history write_addon_data and an addon_data path so we can write out arbitrary
data to a file stored per history file and per transaction id
- add historypluginconduit which gives the user access to yumbase.history directly
diff --git a/yum/__init__.py b/yum/__init__.py
index 4fbf342..6bcc666 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1315,7 +1315,7 @@ class YumBase(depsolve.Depsolve):
cmdline = ' '.join(self.cmds)
self.history.beg(rpmdbv, using_pkgs, list(self.tsInfo),
self.skipped_packages, rpmdb_problems, cmdline)
-
+ self.plugins.run('historybegin')
# 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
# "something" happens and the rpmdb is different from what we think it
@@ -1341,7 +1341,8 @@ class YumBase(depsolve.Depsolve):
if self.conf.history_record and not self.ts.isTsFlagSet(rpm.RPMTRANS_FLAG_TEST):
herrors = [to_unicode(to_str(x)) for x in errors]
self.history.end(rpmdbv, 2, errors=herrors)
-
+ self.plugins.run('historyend')
+
self.logger.critical(_("Transaction couldn't start:"))
for e in errors:
self.logger.critical(e[0]) # should this be 'to_unicoded'?
diff --git a/yum/history.py b/yum/history.py
index ca87335..f785b1a 100644
--- a/yum/history.py
+++ b/yum/history.py
@@ -262,11 +262,26 @@ class YumHistory:
except ValueError:
continue
+ self._db_date = '%s-%s-%s' % (pieces[0], pieces[1], pieces[2])
self._db_file = d
break
if self._db_file is None:
self._create_db_file()
+
+ # make an addon path for where we're going to stick
+ # random additional history info - probably from plugins and what-not
+ self.conf.addon_path = self.conf.db_path + '/' + self._db_date
+ if not os.path.exists(self.conf.addon_path):
+ try:
+ os.makedirs(self.conf.addon_path)
+ except (IOError, OSError), e:
+ # some sort of useful thing here? A warning?
+ return
+ else:
+ if os.access(self.conf.addon_path, os.W_OK):
+ self.conf.writable = True
+
def __del__(self):
self.close()
@@ -563,6 +578,42 @@ class YumHistory:
self._log_errors(errors)
del self._tid
+ def write_addon_data(dataname, data):
+ """append data to an arbitrary-named file in the history
+ addon_path/transaction id location"""
+
+ if not hasattr(self, '_tid'):
+ # maybe we should raise an exception or a warning here?
+ return False
+
+ # make sure the tid dir exists
+ tid_dir = self.conf.addon_path + '/' + self._tid)
+
+ if self.conf.writable and not os.path.exists(tid_dir):
+ try:
+ os.makedirs(tid_dir, mode=0700)
+ except (IOError, OSError), e:
+ # emit a warning/raise an exception?
+ return False
+
+ # cleanup dataname
+ safename = dataname.replace('/', '_')
+ data_fn = tid_dir + '/' + safename
+ try:
+ # open file in append
+ fo = open(data_fn, 'w+')
+ # write data
+ fo.write(data)
+ # flush data
+ fo.flush()
+ fo.close()
+ except (IOError, OSError), e:
+ return False
+ # return
+ return True
+
+
+
def _old_with_pkgs(self, tid):
cur = self._get_cursor()
executeSQL(cur,
@@ -883,9 +934,10 @@ class YumHistory:
def _create_db_file(self):
""" Create a new history DB file, populating tables etc. """
+ self._db_date = time.strftime('%Y-%m-%d')
_db_file = '%s/%s-%s.%s' % (self.conf.db_path,
'history',
- time.strftime('%Y-%m-%d'),
+ self._db_date,
'sqlite')
if self._db_file == _db_file:
os.rename(_db_file, _db_file + '.old')
diff --git a/yum/plugins.py b/yum/plugins.py
index c8ed4ab..a71c10f 100644
--- a/yum/plugins.py
+++ b/yum/plugins.py
@@ -94,6 +94,8 @@ SLOT_TO_CONDUIT = {
'exclude': 'MainPluginConduit',
'preresolve': 'DepsolvePluginConduit',
'postresolve': 'DepsolvePluginConduit',
+ 'historybegin': 'HistoryPluginConduit',
+ 'historyend': 'HistoryPluginConduit',
}
# Enumerate all slot names
@@ -609,6 +611,11 @@ class DepsolvePluginConduit(MainPluginConduit):
self.resultstring = restring
+class HistoryPluginConduit(MainPluginConduit):
+ def __init__(self, parent, base, conf, rescode=None, restring=[]):
+ MainPluginConduit.__init__(self, parent, base, conf)
+ self.history = self._base.history
+
def parsever(apiver):
maj, min = apiver.split('.')
return int(maj), int(min)
More information about the Yum-commits
mailing list