func/minion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 func/minion/modules/yumcmd.py |   55 +++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 24 deletions(-)

New commits:
commit 26056432f5d991aeb0784aa844421183c56e7b37
Author: Seth Vidal <skvidal@xxxxxxxxxxxxxxxxx>
Date:   Fri Jul 8 17:52:11 2011 -0400

    add a multiple action command (func equiv to yum shell)

diff --git a/func/minion/modules/yumcmd.py b/func/minion/modules/yumcmd.py
index 1bc0930..4b28be7 100644
--- a/func/minion/modules/yumcmd.py
+++ b/func/minion/modules/yumcmd.py
@@ -12,7 +12,6 @@
 
 # TODOS:
 # - config_dict handling
-# multiple commands in a single call - multiple() == yum shell
 # - permanent config changes
 # - better _makeresults() that doesn't make me kinda hurl and makes the output more sensible
 
@@ -35,28 +34,29 @@ def _makeresults(tsInfo):
 
     return results
 
-def _singleAction(action, items=[], config_dict={}, **kwargs):
-    #FIXME - config_dict needs to do the equiv of --setopt in the yumcli
+def _multiActions(action_tuples, config_dict={}, **kwargs):
+    #action tuple is action name(install/remove/erase/update) + item list
     import yum
     ayum = yum.YumBase()
     ayum.doGenericSetup()
     ayum.doRepoSetup()
-    if type(items) == type([]):
-        pkglist = []
-        for p in items:
-            pkglist.extend(p.split(' '))
-    else:
-        if items:
-            pkglist = items.split(' ')
-        else:
+    ayum.doLock()
+    results = ''
+    for (action, items) in action_tuples:
+        if type(items) == type([]):
             pkglist = []
-
-    if len(pkglist) == 0 and action not in ('update', 'upgrade'):
-        raise FuncException("%s requires at least one pkg" % action)
-
-    results = 'command: %s %s\n' % (action, ' '.join(pkglist))
-    try:
-        ayum.doLock()
+            for p in items:
+                pkglist.extend(p.split(' '))
+        else:
+            if items:
+                pkglist = items.split(' ')
+            else:
+                pkglist = []
+
+        if len(pkglist) == 0 and action not in ('update', 'upgrade'):
+            raise FuncException("%s requires at least one pkg" % action)
+        
+        results += 'command: %s %s\n' % (action, ' '.join(pkglist))
         if pkglist:
             for p in pkglist:
                 tx_mbrs = []
@@ -73,15 +73,17 @@ def _singleAction(action, items=[], config_dict={}, **kwargs):
 
         else:
             ayum.update()
-
+    try:
         ayum.buildTransaction()
-        ayum.processTransaction(
-                callback=DummyCallback())
+        ayum.processTransaction(callback=DummyCallback())
     finally:
         results += _makeresults(ayum.tsInfo)
         ayum.closeRpmDB()
         ayum.doUnlock()
     return results
+    
+def _singleAction(action, items=[], config_dict={}, **kwargs):
+    return _multiActions([(action, items)], config_dict, *kwargs)
 
 class Yum(func_module.FuncModule):
 
@@ -108,9 +110,14 @@ class Yum(func_module.FuncModule):
     def remove(self, pkg=None, config_dict={}):
         return _singleAction('remove', items=pkg, config_dict=config_dict)
 
-    #def multiple(self, cmdlist=[]):
-    #    """take multiple commands as a single transaction - equiv of yum shell"""
-    #    raise FuncException("Not Implemented Yet!"
+    def multiple(self, cmdlist=[], config_dict={}):
+        """take multiple commands as a single transaction - equiv of yum shell"""
+        action_tuples = [] # it's a list of tuples, yes
+        for c in cmdlist:
+            cmd  = c.split()[0]
+            items = c.split()[1:]
+            action_tuples.append((cmd, items))
+        return _multiActions(action_tuples, config_dict={})
 
     def get_package_lists(self, pkgspec='installed,available,obsoletes,updates,extras', config_dict={}):
         import yum


_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list


[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux