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 description(self): warning = '' dependent_items = '' if not self['status'] == 'will-be-removed': force_install_after_date = self.get('force_install_after_date') if force_install_after_date: # insert installation deadline into description try: local_date = munki.discardTimeZoneFromDate( force_install_after_date) except munki.BadDateError: # some issue with the stored date pass else: date_str = munki.stringFromDate(local_date) forced_date_text = NSLocalizedString( u"This item must be installed by %s", u"Forced Date warning") warning = ('<span class="warning">' + forced_date_text % date_str + '</span><br><br>') if self.get('dependent_items'): dependent_items = self.dependency_description() return warning + dependent_items + self['raw_description']
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 getAvailableUpdates(self): updatelist = [] installinfo = munki.getInstallInfo() if installinfo: updatelist = installinfo.get("managed_installs", []) for update in updatelist: force_install_after_date = update.get('force_install_after_date') if force_install_after_date: # insert installation deadline into description local_date = munki.discardTimeZoneFromDate(force_install_after_date) date_str = munki.stringFromDate(local_date) forced_date_text = NSLocalizedString(u"This item must be installed by ", None) description = update["description"] # prepend deadline info to description. This will fail if the description is HTML... update["description"] = forced_date_text + date_str + "\n\n" + description if installinfo.get("removals"): removallist = installinfo.get("removals") restartNeeded = False showRemovalDetail = munki.getRemovalDetailPrefs() for item in removallist: if item.get("RestartAction") == "RequireRestart" or item.get("RestartAction") == "RecommendRestart": restartNeeded = True if showRemovalDetail: item["display_name"] = ((item.get("display_name") or item.get("name", "")) + NSLocalizedString(u" (will be removed)", None)) item["description"] = NSLocalizedString(u"This item will be removed.", None) updatelist.append(item) if not showRemovalDetail: row = {} row["display_name"] = NSLocalizedString(u"Software removals", None) row["version"] = "" row["description"] = NSLocalizedString(u"Scheduled removal of managed software.", None) if restartNeeded: row["RestartAction"] = "RequireRestart" updatelist.append(row) if updatelist: self._listofupdates = updatelist self.enableUpdateNowBtn_(YES) #self.performSelector_withObject_afterDelay_("enableUpdateNowBtn:", YES, 4) self.getOptionalInstalls() else: appleupdates = munki.getAppleUpdates() if appleupdates: munki.log("MSU", "appleupdates") self._listofupdates = appleupdates.get("AppleUpdates", []) self.update_view_controller.updateNowBtn.setEnabled_(YES) self.update_view_controller.optionalSoftwareBtn.setHidden_(YES) else: self.update_view_controller.updateNowBtn.setEnabled_(NO) self.getOptionalInstalls()
def get_warning_text(): '''Return localized text warning about forced installs and/or logouts and/or restarts''' item_list = MunkiItems.getEffectiveUpdateList() warning_text = u'' forced_install_date = munki.earliestForceInstallDate(item_list) if forced_install_date: date_str = munki.stringFromDate(forced_install_date) forced_date_text = NSLocalizedString( u"One or more items must be installed by %s", u"Forced Install Date summary") warning_text = forced_date_text % date_str restart_text = getRestartActionForUpdateList(item_list) if restart_text: if warning_text: warning_text += u' • ' + restart_text else: warning_text = restart_text return warning_text
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 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 getAvailableUpdates(self): updatelist = [] installinfo = munki.getInstallInfo() if installinfo: updatelist = installinfo.get("managed_installs", []) for update in updatelist: force_install_after_date = update.get( 'force_install_after_date') if force_install_after_date: # insert installation deadline into description local_date = munki.discardTimeZoneFromDate( force_install_after_date) date_str = munki.stringFromDate(local_date) forced_date_text = NSLocalizedString( u"This item must be installed by ", None) description = update["description"] # prepend deadline info to description. This will fail if the description is HTML... update[ "description"] = forced_date_text + date_str + "\n\n" + description if installinfo.get("removals"): removallist = installinfo.get("removals") restartNeeded = False showRemovalDetail = munki.getRemovalDetailPrefs() for item in removallist: if item.get( "RestartAction") == "RequireRestart" or item.get( "RestartAction") == "RecommendRestart": restartNeeded = True if showRemovalDetail: item["display_name"] = ( (item.get("display_name") or item.get("name", "")) + NSLocalizedString(u" (will be removed)", None)) item["description"] = NSLocalizedString( u"This item will be removed.", None) updatelist.append(item) if not showRemovalDetail: row = {} row["display_name"] = NSLocalizedString( u"Software removals", None) row["version"] = "" row["description"] = NSLocalizedString( u"Scheduled removal of managed software.", None) if restartNeeded: row["RestartAction"] = "RequireRestart" updatelist.append(row) if updatelist: self._sortUpdateList(updatelist) self._listofupdates = updatelist self.enableUpdateNowBtn_(YES) #self.performSelector_withObject_afterDelay_("enableUpdateNowBtn:", YES, 4) self.getOptionalInstalls() else: appleupdates = munki.getAppleUpdates() if appleupdates: munki.log("MSU", "appleupdates") self._listofupdates = appleupdates.get("AppleUpdates", []) self.update_view_controller.updateNowBtn.setEnabled_(YES) self.update_view_controller.optionalSoftwareBtn.setHidden_(YES) else: self._listofupdates = [] self.update_view_controller.updateNowBtn.setEnabled_(NO) self.getOptionalInstalls()