[yum-cvs] yum/misc.py
Seth Vidal
skvidal at linux.duke.edu
Fri Dec 7 21:54:13 UTC 2007
yum/misc.py | 53 +++++++++++++++++++++++++++++++----------------------
1 file changed, 31 insertions(+), 22 deletions(-)
New commits:
commit 33a13b05dc231fa46f23a25f0c321c3da9934f3b
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Fri Dec 7 16:53:49 2007 -0500
add misc.find_unfinished_transactions() - makes it easier to deal with multiple
unfinished transactions.
diff --git a/yum/misc.py b/yum/misc.py
index 33fe68c..1d3eb11 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -398,34 +398,43 @@ def get_running_kernel_version_release(ts):
return (None, None)
-def find_ts_remaining(yumlibpath='/var/lib/yum'):
- """this function takes the path to the yum lib dir (defaults to /var/lib/yum)
- returns a list of tuples(action, pkgspec) for the unfinished transaction
- elements. Returns an empty list if none. If there is more than one unfinished
- transaction it operates only on the most recent one. In general there shouldn't
- be more than one but weird things happen.
+def find_unfinished_transactions(yumlibpath='/var/lib/yum'):
+ """returns a list of the timestamps from the filenames of the unfinished
+ transactions remaining in the yumlibpath specified.
"""
- to_complete_items = []
-
+ timestamps = []
tsallg = '%s/%s' % (yumlibpath, 'transaction-all*')
tsdoneg = '%s/%s' % (yumlibpath, 'transaction-done*')
tsalls = glob.glob(tsallg)
tsdones = glob.glob(tsdoneg)
- if len(tsalls) == 0 or len(tsdones) == 0:
- #print 'no transactions found to fix'
- return to_complete_items
-
- if len(tsalls) > 1 or len(tsdones) > 1:
- #print "More than one failed transaction, operating on only the most recent"
- tsalls.sort()
- tsallpath = tsalls[-1]
- trans = os.path.basename(tsallpath)
- timestamp = trans.replace('transaction-all.','')
+ for fn in tsalls:
+ trans = os.path.basename(fn)
+ timestamp = trans.replace('transaction-all.','')
+ timestamps.append(timestamp)
+
+ timestamps.sort()
+ return timestamps
+
+def find_ts_remaining(timestamp, yumlibpath='/var/lib/yum',):
+ """this function takes the timestamp of the transaction to look at and
+ the path to the yum lib dir (defaults to /var/lib/yum)
+ returns a list of tuples(action, pkgspec) for the unfinished transaction
+ elements. Returns an empty list if none.
+
+ """
+
+ to_complete_items = []
+ tsallpath = '%s/%s.%s' % (yumlibpath, 'transaction-all', timestamp)
tsdonepath = '%s/%s.%s' % (yumlibpath,'transaction-done', timestamp)
tsdone_items = []
-
+
+ if not os.path.exists(tsallpath):
+ # something is wrong, here, probably need to raise _something_
+ return to_complete_items
+
+
if os.path.exists(tsdonepath):
tsdone_fo = open(tsdonepath, 'r')
tsdone_items = tsdone_fo.readlines()
@@ -436,16 +445,16 @@ def find_ts_remaining(yumlibpath='/var/lib/yum'):
tsall_fo.close()
for item in tsdone_items:
- #print 'cleaning out already run: %s' % item
+ # this probably shouldn't happen but it's worth catching anyway
+ if item not in tsall_items:
+ continue
tsall_items.remove(item)
-
for item in tsall_items:
item = item.replace('\n', '')
if item == '':
continue
(action, pkgspec) = item.split()
- #print '%s :: %s' % (action, pkgspec)
to_complete_items.append((action, pkgspec))
return to_complete_items
More information about the Yum-cvs-commits
mailing list