Add handling for the install all updates option 37/5737/2
authorWilliam Douglas <william.douglas@intel.com>
Mon, 8 Jul 2013 20:10:56 +0000 (13:10 -0700)
committerWilliam Douglas <william.douglas@intel.com>
Wed, 17 Jul 2013 16:32:40 +0000 (09:32 -0700)
Currently updates are installed by calling swup one update at a time.
Add support to swup for installing all the applicable available
updates in one run.

Change-Id: Ieaeacf6812b016b580873f14456636e564ed71d7
Signed-off-by: William Douglas <william.douglas@intel.com>
swup.py

diff --git a/swup.py b/swup.py
index 6073105..307d36c 100755 (executable)
--- a/swup.py
+++ b/swup.py
@@ -9,6 +9,7 @@ import hashlib
 import os
 import tempfile
 import shutil
+import copy
 import sys
 import zipfile
 import rpm
@@ -269,6 +270,19 @@ def list_updates():
             print "%s" %u['id']
             print "    %s" %u['title']
 
+def get_uninstalled_updates(updates):
+    uninstalled = copy.deepcopy(updates)
+    if os.path.isdir("%s/installed/" % update_cache):
+        update_ids = sorted(uninstalled.keys(), reverse=True)
+        installed = sorted(os.listdir("%s/installed/" % update_cache), reverse=True)
+        if len(installed) != 0:
+            latest = installed[0]
+            if update_ids.count(latest) != 0:
+                for i in update_ids[update_ids.index(latest):]:
+                    uninstalled.pop(i)
+
+    return uninstalled
+
 def get_options():
     parser = OptionParser()
     parser.add_option("-V", "--os-version", action="store_true", dest="osver", default=False,
@@ -344,6 +358,13 @@ def run_action(options):
         download_update(u)
         install_update(u)
 
+    if options.install_all:
+        updates = parse_updates()
+        uninstalled_updates = get_uninstalled_updates(updates)
+        for u in uninstalled_updates.values():
+            download_update(u)
+            install_update(u)
+
 if __name__ == '__main__':
     try:
         options = get_options()