Case-insensitive sort MSU GUI update list, preferring forced install items, then preferring display_name to name.

This commit is contained in:
Justin McWilliams
2011-11-17 12:50:16 -05:00
parent 1930c76981
commit 19fbb4ed56
+43 -1
View File
@@ -22,6 +22,7 @@ from AppKit import *
from objc import YES, NO
import os
import munki
import subprocess
import PyObjCTools
munki.setupLogging()
@@ -56,7 +57,23 @@ class MSUAppDelegate(NSObject):
ver = NSBundle.mainBundle().infoDictionary().get(
'CFBundleShortVersionString')
NSLog("MSU GUI version: %s" % ver)
munki.log("MSU", "launched", "VER=%s" % ver)
if os.environ.get('MACOSX_DEPLOYMENT_TARGET', None):
from_gui = False
else:
from_gui = True
try:
cmd = ['/bin/ps', '-p', '%d' % os.getppid(), '-x', '-o',
'user=,pid=,comm=']
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(output, unused_err) = proc.communicate()
output = output.strip()
munki.log(
"MSU", "launched",
"VER=%s GUI=%s Parent Process=%s" % (ver, from_gui, output))
except OSError, e:
munki.log("MSU", "launched", "VER=%s ERR=%s" % (ver, str(e)))
runmode = NSUserDefaults.standardUserDefaults().stringForKey_("mode") or \
os.environ.get("ManagedSoftwareUpdateMode")
@@ -118,6 +135,29 @@ class MSUAppDelegate(NSObject):
# no updates available. Should we check for some?
self.checkForUpdates()
def _sortUpdateList(self, l):
# pop any forced install items off the list.
forced_items = []
i = 0
while i < len(l):
if l[i].get('force_install_after_date'):
forced_items.append(l.pop(i))
else:
i += 1
# sort the regular update list, preferring display_name to name.
sort_lambda = lambda i: (i.get('display_name') or i.get('name')).lower()
l.sort(key=sort_lambda)
# if there were any forced items, add them to the top of the list.
if forced_items:
# sort forced items by datetime, reversed so soonest is last.
forced_items.sort(
key=lambda i: i.get('force_install_after_date'), reverse=True)
# insert items at top of the list one by one, so soonest is first.
for i in forced_items:
l.insert(0, i)
def updateAvailableUpdates(self):
NSLog(u"Managed Software Update got update notification")
if self.mainWindowController.theWindow.isVisible():
@@ -290,6 +330,7 @@ class MSUAppDelegate(NSObject):
if installinfo:
optionalInstalls = installinfo.get("optional_installs", [])
if optionalInstalls:
self._sortUpdateList(optionalInstalls)
self._optionalInstalls = optionalInstalls
self.update_view_controller.optionalSoftwareBtn.setHidden_(NO)
else:
@@ -338,6 +379,7 @@ class MSUAppDelegate(NSObject):
updatelist.append(row)
if updatelist:
self._sortUpdateList(updatelist)
self._listofupdates = updatelist
self.enableUpdateNowBtn_(YES)
#self.performSelector_withObject_afterDelay_("enableUpdateNowBtn:", YES, 4)