[yum-cvs] yum/misc.py

Seth Vidal skvidal at linux.duke.edu
Thu Dec 6 21:35:50 UTC 2007


 yum/misc.py |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

New commits:
commit f69fba359126dd92bfb494ead69b7b8614742cc8
Author: Seth Vidal <skvidal at fedoraproject.org>
Date:   Thu Dec 6 16:35:35 2007 -0500

    commit find_ts_remaining():
           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.
    
    will be used to allow yum to auto-cleanup failed transactions.

diff --git a/yum/misc.py b/yum/misc.py
index 5f17758..33fe68c 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -398,3 +398,56 @@ 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.
+
+    """
+    to_complete_items = []
+    
+    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.','')
+    tsdonepath = '%s/%s.%s' % (yumlibpath,'transaction-done', timestamp)
+    tsdone_items = []
+    
+    if os.path.exists(tsdonepath):
+        tsdone_fo = open(tsdonepath, 'r')
+        tsdone_items = tsdone_fo.readlines()
+        tsdone_fo.close()     
+    
+    tsall_fo = open(tsallpath, 'r')
+    tsall_items = tsall_fo.readlines()
+    tsall_fo.close()
+    
+    for item in tsdone_items:
+        #print 'cleaning out already run:  %s' % item
+        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