def laterBtnClicked(self): if munki.thereAreUpdatesToBeForcedSoon(): deadline = munki.earliestForceInstallDate() time_til_logout = deadline.timeIntervalSinceNow() if time_til_logout > 0: deadline_str = munki.stringFromDate(deadline) formatString = NSLocalizedString( (u"One or more updates must be installed by %s. A logout " "may be forced if you wait too long to update."), None) infoText = formatString % deadline_str else: infoText = NSLocalizedString( (u"One or more mandatory updates are overdue for " "installation. A logout will be forced soon."), None) alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( NSLocalizedString(u"Manadatory Updates Pending", None), NSLocalizedString(u"Show updates", None), NSLocalizedString(u"Update later", None), objc.nil, infoText) self._currentAlert = alert alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_( self.mainWindowController.theWindow, self, self.confirmLaterAlertDidEnd_returnCode_contextInfo_, objc.nil) else: munki.log("user", "exit_later_clicked") NSApp.terminate_(self)
def forcedLogoutWarning(self, notification_obj): NSApp.activateIgnoringOtherApps_(True) info = notification_obj.userInfo() moreText = NSLocalizedString( (u"\nAll pending updates will be installed. Unsaved work will be " "lost.\nYou may avoid the forced logout by logging out now."), None) logout_time = None if info: logout_time = info.get('logout_time') elif munki.thereAreUpdatesToBeForcedSoon(): logout_time = munki.earliestForceInstallDate() if not logout_time: return time_til_logout = int(logout_time.timeIntervalSinceNow() / 60) if time_til_logout > 55: deadline_str = munki.stringFromDate(logout_time) munki.log("user", "forced_logout_warning_initial") formatString = NSLocalizedString( u"A logout will be forced at approximately %s.", None) infoText = formatString % deadline_str + moreText elif time_til_logout > 0: munki.log("user", "forced_logout_warning_%s" % time_til_logout) formatString = NSLocalizedString( u"A logout will be forced in less than %s minutes.", None) infoText = formatString % time_til_logout + moreText else: munki.log("user", "forced_logout_warning_final") infoText = NSLocalizedString( (u"A logout will be forced in less than a minute.\nAll pending " "updates will be installed. Unsaved work will be lost."), None) # Set the OK button to default, unless less than 5 minutes to logout # in which case only the Logout button should be displayed. self._force_warning_logout_btn = NSLocalizedString( u"Log out and update now", None) self._force_warning_ok_btn = NSLocalizedString(u"OK", None) if time_til_logout > 5: self._force_warning_btns = { NSAlertDefaultReturn: self._force_warning_ok_btn, NSAlertAlternateReturn: self._force_warning_logout_btn, } else: self._force_warning_btns = { NSAlertDefaultReturn: self._force_warning_logout_btn, NSAlertAlternateReturn: objc.nil, } if self._currentAlert: NSApp.endSheet_(self._currentAlert.window()) self._currentAlert = None alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( NSLocalizedString( u"Forced Logout for Mandatory Install", None), self._force_warning_btns[NSAlertDefaultReturn], self._force_warning_btns[NSAlertAlternateReturn], objc.nil, infoText) self._currentAlert = alert alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_( self.mainWindowController.theWindow, self, self.forceLogoutWarningDidEnd_returnCode_contextInfo_, objc.nil)
def alertToPendingUpdates(self): '''Alert user to pending updates before quitting the application''' self._alertedUserToOutstandingUpdates = True # show the updates self.loadUpdatesPage_(self) if munki.thereAreUpdatesToBeForcedSoon(): alertTitle = NSLocalizedString(u"Mandatory Updates Pending", u"Mandatory Updates Pending text") deadline = munki.earliestForceInstallDate() time_til_logout = deadline.timeIntervalSinceNow() if time_til_logout > 0: deadline_str = munki.stringFromDate(deadline) formatString = NSLocalizedString( (u"One or more updates must be installed by %s. A logout " "may be forced if you wait too long to update."), u"Mandatory Updates Pending detail") alertDetail = formatString % deadline_str else: alertDetail = NSLocalizedString( (u"One or more mandatory updates are overdue for " "installation. A logout will be forced soon."), u"Mandatory Updates Imminent detail") else: alertTitle = NSLocalizedString(u"Pending updates", u"Pending Updates alert title") alertDetail = NSLocalizedString(u"There are pending updates for this computer.", u"Pending Updates alert detail text") alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( alertTitle, NSLocalizedString(u"Quit", u"Quit button title"), nil, NSLocalizedString(u"Update now", u"Update Now button title"), u"%@", alertDetail) alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_( self.window(), self, self.updateAlertDidEnd_returnCode_contextInfo_, objc.nil)
def forcedLogoutWarning(self, notification_obj): NSApp.activateIgnoringOtherApps_(True) info = notification_obj.userInfo() moreText = NSLocalizedString( u"\nAll pending updates will be installed. Unsaved work will be lost.\nYou may avoid the forced logout by logging out now.", None) logout_time = None if info: logout_time = info.get('logout_time') elif munki.thereAreUpdatesToBeForcedSoon(): logout_time = munki.earliestForceInstallDate() if not logout_time: return time_til_logout = int(logout_time.timeIntervalSinceNow() / 60) if time_til_logout > 55: deadline_str = munki.stringFromDate(logout_time) munki.log("user", "forced_logout_warning_initial") infoText = NSLocalizedString( u"A logout will be forced at approximately %s.", None) % deadline_str + moreText elif time_til_logout > 0: munki.log("user", "forced_logout_warning_%s" % time_til_logout) infoText = NSLocalizedString( u"A logout will be forced in less than %s minutes.", None) % time_til_logout + moreText else: munki.log("user", "forced_logout_warning_final") infoText = NSLocalizedString( u"A logout will be forced in less than a minute.\nAll pending updates will be installed. Unsaved work will be lost.", None) # Set the OK button to default, unless less than 5 minutes to logout # in which case only the Logout button should be displayed. self._force_warning_logout_btn = NSLocalizedString( u"Logout and update now", None) self._force_warning_ok_btn = NSLocalizedString(u"OK", None) if time_til_logout > 5: self._force_warning_btns = { NSAlertDefaultReturn: self._force_warning_ok_btn, NSAlertAlternateReturn: self._force_warning_logout_btn, } else: self._force_warning_btns = { NSAlertDefaultReturn: self._force_warning_logout_btn, NSAlertAlternateReturn: objc.nil, } if self._currentAlert: NSApp.endSheet_(self._currentAlert.window()) self._currentAlert = None alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( NSLocalizedString(u"Forced Logout for Mandatory Install", None), self._force_warning_btns[NSAlertDefaultReturn], self._force_warning_btns[NSAlertAlternateReturn], objc.nil, infoText) self._currentAlert = alert alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_( self.mainWindowController.theWindow, self, self.forceLogoutWarningDidEnd_returnCode_contextInfo_, objc.nil)
def displayUpdatesWindow(self): self.buildUpdateTableData() if self._optionalInstalls: self.buildOptionalInstallsData() self.mainWindowController.theWindow.makeKeyAndOrderFront_(self) if munki.thereAreUpdatesToBeForcedSoon(hours=2): NSApp.activateIgnoringOtherApps_(True) else: NSApp.requestUserAttention_(NSCriticalRequest)
def applicationDidFinishLaunching_(self, sender): '''NSApplication delegate method called at launch''' # Prevent automatic relaunching at login on Lion+ if NSApp.respondsToSelector_('disableRelaunchOnLogin'): NSApp.disableRelaunchOnLogin() ver = NSBundle.mainBundle().infoDictionary().get( 'CFBundleShortVersionString') msclog.log("MSC", "launched", "VER=%s" % ver) # if we're running under Snow Leopard, swap out the Dock icon for one # without the Retina assets to avoid an appearance issue when the # icon has a badge in the Dock (and App Switcher) # Darwin major version 10 is Snow Leopard (10.6) if os.uname()[2].split('.')[0] == '10': myImage = NSImage.imageNamed_("Managed Software Center 10_6") NSApp.setApplicationIconImage_(myImage) # setup client logging msclog.setup_logging() # have the statuscontroller register for its own notifications self.statusController.registerForNotifications() # user may have launched the app manually, or it may have # been launched by /usr/local/munki/managedsoftwareupdate # to display available updates if munki.thereAreUpdatesToBeForcedSoon(hours=2): # skip the check and just display the updates # by pretending the lastcheck is now lastcheck = NSDate.date() else: lastcheck = munki.pref('LastCheckDate') max_cache_age = munki.pref('CheckResultsCacheSeconds') # if there is no lastcheck timestamp, check for updates. if not lastcheck: self.mainWindowController.checkForUpdates() elif lastcheck.timeIntervalSinceNow() * -1 > int(max_cache_age): # check for updates if the last check is over the # configured manualcheck cache age max. self.mainWindowController.checkForUpdates() elif MunkiItems.updateCheckNeeded(): # check for updates if we have optional items selected for install # or removal that have not yet been processed self.mainWindowController.checkForUpdates() # load the initial view only if we are not already loading something else. # enables launching the app to a specific panel, eg. from URL handler if not self.mainWindowController.webView.isLoading(): self.mainWindowController.loadInitialView()
def applicationDidFinishLaunching_(self, sender): '''NSApplication delegate method called at launch''' # Prevent automatic relaunching at login on Lion+ if NSApp.respondsToSelector_('disableRelaunchOnLogin'): NSApp.disableRelaunchOnLogin() ver = NSBundle.mainBundle().infoDictionary().get('CFBundleShortVersionString') msclog.log("MSC", "launched", "VER=%s" % ver) # if we're running under Snow Leopard, swap out the Dock icon for one # without the Retina assets to avoid an appearance issue when the # icon has a badge in the Dock (and App Switcher) # Darwin major version 10 is Snow Leopard (10.6) if os.uname()[2].split('.')[0] == '10': myImage = NSImage.imageNamed_("Managed Software Center 10_6") NSApp.setApplicationIconImage_(myImage) # setup client logging msclog.setup_logging() # have the statuscontroller register for its own notifications self.statusController.registerForNotifications() # user may have launched the app manually, or it may have # been launched by /usr/local/munki/managedsoftwareupdate # to display available updates if munki.thereAreUpdatesToBeForcedSoon(hours=2): # skip the check and just display the updates # by pretending the lastcheck is now lastcheck = NSDate.date() else: lastcheck = munki.pref('LastCheckDate') max_cache_age = munki.pref('CheckResultsCacheSeconds') # if there is no lastcheck timestamp, check for updates. if not lastcheck: self.mainWindowController.checkForUpdates() elif lastcheck.timeIntervalSinceNow() * -1 > int(max_cache_age): # check for updates if the last check is over the # configured manualcheck cache age max. self.mainWindowController.checkForUpdates() elif MunkiItems.updateCheckNeeded(): # check for updates if we have optional items selected for install # or removal that have not yet been processed self.mainWindowController.checkForUpdates() # load the initial view only if we are not already loading something else. # enables launching the app to a specific panel, eg. from URL handler if not self.mainWindowController.webView.isLoading(): self.mainWindowController.loadInitialView()
def appShouldTerminate(self): '''called by app delegate when it receives applicationShouldTerminate:''' if self.getUpdateCount() == 0: # no pending updates return YES if self.currentPageIsUpdatesPage() and not munki.thereAreUpdatesToBeForcedSoon(): # We're already at the updates view, so user is aware of the # pending updates, so OK to just terminate # (unless there are some updates to be forced soon) return YES if self.currentPageIsUpdatesPage() and self._alertedUserToOutstandingUpdates: return YES # we have pending updates and we have not yet warned the user # about them self.alertToPendingUpdates() return NO
def laterBtnClicked(self): if munki.thereAreUpdatesToBeForcedSoon(): deadline = munki.earliestForceInstallDate() time_til_logout = deadline.timeIntervalSinceNow() if time_til_logout > 0: deadline_str = munki.stringFromDate(deadline) infoText = NSLocalizedString( "One or more updates must be installed by %s. A logout may be forced if you wait too long to update.", None) % deadline_str else: infoText = NSLocalizedString( "One or more mandatory updates are overdue for installation. A logout will be forced soon.", None) alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( NSLocalizedString(u"Manadatory Updates Pending", None), NSLocalizedString(u"Show updates", None), NSLocalizedString(u"Update later", None), objc.nil, infoText) self._currentAlert = alert alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_( self.mainWindowController.theWindow, self, self.confirmLaterAlertDidEnd_returnCode_contextInfo_, objc.nil) else: munki.log("user", "exit_later_clicked") NSApp.terminate_(self)
def forcedLogoutWarning(self, notification_obj): '''Display a forced logout warning''' NSApp.activateIgnoringOtherApps_(True) info = notification_obj.userInfo() moreText = NSLocalizedString( u"All pending updates will be installed. Unsaved work will be lost." "\nYou may avoid the forced logout by logging out now.", u"Forced Logout warning detail") logout_time = None if info: logout_time = info.get('logout_time') elif munki.thereAreUpdatesToBeForcedSoon(): logout_time = munki.earliestForceInstallDate() if not logout_time: return time_til_logout = int(logout_time.timeIntervalSinceNow() / 60) if time_til_logout > 55: deadline_str = munki.stringFromDate(logout_time) msclog.log("user", "forced_logout_warning_initial") formatString = NSLocalizedString( u"A logout will be forced at approximately %s.", u"Logout warning string when logout is an hour or more away") infoText = formatString % deadline_str + u"\n" + moreText elif time_til_logout > 0: msclog.log("user", "forced_logout_warning_%s" % time_til_logout) formatString = NSLocalizedString( u"A logout will be forced in less than %s minutes.", u"Logout warning string when logout is in < 60 minutes") infoText = formatString % time_til_logout + u"\n" + moreText else: msclog.log("user", "forced_logout_warning_final") infoText = NSLocalizedString( u"A logout will be forced in less than a minute.\nAll pending " "updates will be installed. Unsaved work will be lost.", u"Logout warning string when logout is in less than a minute") # Set the OK button to default, unless less than 5 minutes to logout # in which case only the Logout button should be displayed. self._force_warning_logout_btn = NSLocalizedString( u"Log out and update now", u"Logout and Update Now button text") self._force_warning_ok_btn = NSLocalizedString(u"OK", u"OK button title") if time_til_logout > 5: self._force_warning_btns = { NSAlertDefaultReturn: self._force_warning_ok_btn, NSAlertAlternateReturn: self._force_warning_logout_btn, } else: self._force_warning_btns = { NSAlertDefaultReturn: self._force_warning_logout_btn, NSAlertAlternateReturn: nil, } if self.window.attachedSheet(): # there's an existing sheet open NSApp.endSheet_(self.window.attachedSheet()) alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( NSLocalizedString(u"Forced Logout for Mandatory Install", u"Forced Logout title text"), self._force_warning_btns[NSAlertDefaultReturn], self._force_warning_btns[NSAlertAlternateReturn], nil, u"%@", infoText) alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_( self.window, self, self.forceLogoutWarningDidEnd_returnCode_contextInfo_, nil)
def applicationDidFinishLaunching_(self, sender): NSLog(u"Managed Software Update finished launching.") ver = NSBundle.mainBundle().infoDictionary().get( 'CFBundleShortVersionString') NSLog("MSU GUI version: %s" % ver) munki.log("MSU", "launched", "VER=%s" % ver) runmode = NSUserDefaults.standardUserDefaults().stringForKey_("mode") or \ os.environ.get("ManagedSoftwareUpdateMode") if runmode: self.runmode = runmode NSLog("Runmode: %s" % runmode) # Prevent automatic relaunching at login on Lion if NSApp.respondsToSelector_('disableRelaunchOnLogin'): NSApp.disableRelaunchOnLogin() # register for notification messages so we can be told if available updates # change while we are open notification_center = NSDistributedNotificationCenter.defaultCenter() notification_center.addObserver_selector_name_object_suspensionBehavior_( self, self.updateAvailableUpdates, 'com.googlecode.munki.ManagedSoftwareUpdate.update', None, NSNotificationSuspensionBehaviorDeliverImmediately) # register for notification messages so we can be told to # display a logout warning notification_center = NSDistributedNotificationCenter.defaultCenter() notification_center.addObserver_selector_name_object_suspensionBehavior_( self, self.forcedLogoutWarning, 'com.googlecode.munki.ManagedSoftwareUpdate.logoutwarn', None, NSNotificationSuspensionBehaviorDeliverImmediately) consoleuser = munki.getconsoleuser() if consoleuser == None or consoleuser == u"loginwindow": # Status Window only NSMenu.setMenuBarVisible_(NO) self.munkiStatusController.startMunkiStatusSession() elif self.runmode == "MunkiStatus": self.munkiStatusController.startMunkiStatusSession() else: # user may have launched the app manually, or it may have # been launched by /usr/local/munki/managedsoftwareupdate # to display available updates if munki.thereAreUpdatesToBeForcedSoon(hours=2): # skip the check and just display the updates # by pretending the lastcheck is now lastcheck = NSDate.date() else: lastcheck = NSDate.dateWithString_(munki.pref('LastCheckDate')) if not lastcheck or lastcheck.timeIntervalSinceNow() < -60: # it's been more than a minute since the last check self.checkForUpdates() return # do we have existing updates to display? if not self._listofupdates: self.getAvailableUpdates() if self._listofupdates: self.displayUpdatesWindow() else: # no updates available. Should we check for some? self.checkForUpdates()
def forcedLogoutWarning(self, notification_obj): '''Display a forced logout warning''' NSApp.activateIgnoringOtherApps_(True) info = notification_obj.userInfo() moreText = NSLocalizedString( (u"All pending updates will be installed. Unsaved work will be lost." "\nYou may avoid the forced logout by logging out now."), u"Forced Logout warning detail") logout_time = None if info: logout_time = info.get('logout_time') elif munki.thereAreUpdatesToBeForcedSoon(): logout_time = munki.earliestForceInstallDate() if not logout_time: return time_til_logout = int(logout_time.timeIntervalSinceNow() / 60) if time_til_logout > 55: deadline_str = munki.stringFromDate(logout_time) msclog.log("user", "forced_logout_warning_initial") formatString = NSLocalizedString( u"A logout will be forced at approximately %s.", u"Logout warning string when logout is an hour or more away") infoText = formatString % deadline_str + u"\n" + moreText elif time_til_logout > 0: msclog.log("user", "forced_logout_warning_%s" % time_til_logout) formatString = NSLocalizedString( u"A logout will be forced in less than %s minutes.", u"Logout warning string when logout is in < 60 minutes") infoText = formatString % time_til_logout + u"\n" + moreText else: msclog.log("user", "forced_logout_warning_final") infoText = NSLocalizedString( (u"A logout will be forced in less than a minute.\nAll pending " "updates will be installed. Unsaved work will be lost."), u"Logout warning string when logout is in less than a minute") # Set the OK button to default, unless less than 5 minutes to logout # in which case only the Logout button should be displayed. self._force_warning_logout_btn = NSLocalizedString( u"Log out and update now", u"Logout and Update Now button text") self._force_warning_ok_btn = NSLocalizedString(u"OK", u"OK button title") if time_til_logout > 5: self._force_warning_btns = { NSAlertDefaultReturn: self._force_warning_ok_btn, NSAlertAlternateReturn: self._force_warning_logout_btn, } else: self._force_warning_btns = { NSAlertDefaultReturn: self._force_warning_logout_btn, NSAlertAlternateReturn: nil, } if self.window.attachedSheet(): # there's an existing sheet open NSApp.endSheet_(self.window.attachedSheet()) alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_( NSLocalizedString( u"Forced Logout for Mandatory Install", u"Forced Logout title text"), self._force_warning_btns[NSAlertDefaultReturn], self._force_warning_btns[NSAlertAlternateReturn], nil, u"%@", infoText) alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_( self.window, self, self.forceLogoutWarningDidEnd_returnCode_contextInfo_, nil)
def applicationDidFinishLaunching_(self, sender): NSLog(u"Managed Software Update finished launching.") ver = NSBundle.mainBundle().infoDictionary().get( 'CFBundleShortVersionString') NSLog("MSU GUI version: %s" % ver) munki.log("MSU", "launched", "VER=%s" % ver) runmode = (NSUserDefaults.standardUserDefaults().stringForKey_("mode") or os.environ.get("ManagedSoftwareUpdateMode")) if runmode: self.runmode = runmode NSLog("Runmode: %s" % runmode) else: consoleuser = munki.getconsoleuser() if consoleuser == None or consoleuser == u"loginwindow": # we're at the loginwindow, so display MunkiStatus self.runmode = "MunkiStatus" # Prevent automatic relaunching at login on Lion if NSApp.respondsToSelector_('disableRelaunchOnLogin'): NSApp.disableRelaunchOnLogin() # register for notification messages so we can be told if available # updates change while we are open notification_center = NSDistributedNotificationCenter.defaultCenter() notification_center.addObserver_selector_name_object_suspensionBehavior_( self, self.updateAvailableUpdates, 'com.googlecode.munki.ManagedSoftwareUpdate.update', None, NSNotificationSuspensionBehaviorDeliverImmediately) # register for notification messages so we can be told to # display a logout warning notification_center = NSDistributedNotificationCenter.defaultCenter() notification_center.addObserver_selector_name_object_suspensionBehavior_( self, self.forcedLogoutWarning, 'com.googlecode.munki.ManagedSoftwareUpdate.logoutwarn', None, NSNotificationSuspensionBehaviorDeliverImmediately) if self.runmode == "MunkiStatus": self.munkiStatusController.startMunkiStatusSession() else: # user may have launched the app manually, or it may have # been launched by /usr/local/munki/managedsoftwareupdate # to display available updates if munki.thereAreUpdatesToBeForcedSoon(hours=2): # skip the check and just display the updates # by pretending the lastcheck is now lastcheck = NSDate.date() else: lastcheck = NSDate.dateWithString_(munki.pref('LastCheckDate')) # if there is no lastcheck timestamp, check for updates. if not lastcheck: self.checkForUpdates() return # otherwise, only check for updates if the last check is over the # configured manualcheck cache age max. max_cache_age = ( munki.pref('CheckResultsCacheSeconds') or DEFAULT_GUI_CACHE_AGE_SECS) if lastcheck.timeIntervalSinceNow() * -1 > int(max_cache_age): self.checkForUpdates() return # if needed, get updates from InstallInfo. if not self._listofupdates: self.getAvailableUpdates() # if updates exist, display them. if self._listofupdates: self.displayUpdatesWindow() else: # only check for updates if cache secs config is not defined. if munki.pref('CheckResultsCacheSeconds'): self.mainWindowController.theWindow.makeKeyAndOrderFront_( self) self.noUpdatesAlert() else: self.checkForUpdates()