예제 #1
0
 def alertedToRunningOnBatteryAndCancelled(self):
     '''Returns True if we are running on battery and user clicks
     the Cancel button'''
     power_info = munki.getPowerInfo()
     if (power_info.get('PowerSource') == 'Battery Power'
             and power_info.get('BatteryCharge', 0) < 50):
         alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
             NSLocalizedString(
                 u"Your computer is not connected to a power source.",
                 u"No Power Source Warning text"),
             NSLocalizedString(u"Continue", u"Continue button text"),
             NSLocalizedString(u"Cancel",
                               u"Cancel button title/short action text"),
             nil, u"%@",
             NSLocalizedString(
                 u"For best results, you should connect your computer to a "
                 "power source before updating. Are you sure you want to "
                 "continue the update?", u"No Power Source Warning detail"))
         msclog.log("MSU", "alert_on_battery_power")
         # making UI consistent with Apple Software Update...
         # set Cancel button to be activated by return key
         alert.buttons()[1].setKeyEquivalent_('\r')
         # set Continue button to be activated by Escape key
         alert.buttons()[0].setKeyEquivalent_(chr(27))
         buttonPressed = alert.runModal()
         if buttonPressed == NSAlertAlternateReturn:
             return True
     return False
예제 #2
0
 def alertedToFirmwareUpdatesAndCancelled(self):
     '''Returns True if we have one or more firmware updates and
     the user clicks the Cancel button'''
     firmware_alert_info = self.getFirmwareAlertInfo()
     if not firmware_alert_info:
         return False
     power_info = munki.getPowerInfo()
     on_battery_power = (power_info.get('PowerSource') == 'Battery Power')
     for item in firmware_alert_info:
         alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
             item['name'],
             NSLocalizedString(u"Continue", u"Continue button text"),
             NSLocalizedString(u"Cancel",
                               u"Cancel button title/short action text"),
             nil, u"")
         if on_battery_power:
             alert_text = NSLocalizedString(
                 u"Your computer is not connected to a power source.",
                 u"No Power Source Warning text")
             alert_text += "\n\n" + item['alert_text']
         else:
             alert_text = item['alert_text']
         alert.setInformativeText_(alert_text)
         alert.setAlertStyle_(NSCriticalAlertStyle)
         if on_battery_power:
             # set Cancel button to be activated by return key
             alert.buttons()[1].setKeyEquivalent_('\r')
             # set Continue button to be activated by Escape key
             alert.buttons()[0].setKeyEquivalent_(chr(27))
         buttonPressed = alert.runModal()
         if buttonPressed == NSAlertAlternateReturn:
             return True
     return False
예제 #3
0
 def alertedToRunningOnBatteryAndCancelled(self):
     '''Returns True if we are running on battery and user clicks
     the Cancel button'''
     power_info = munki.getPowerInfo()
     if (power_info.get('PowerSource') == 'Battery Power'
         and power_info.get('BatteryCharge', 0) < 50):
         alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
             NSLocalizedString(
                 u"Your computer is not connected to a power source.", u"No Power Source Warning text"),
             NSLocalizedString(u"Continue", u"Continue button text"),
             NSLocalizedString(u"Cancel", u"Cancel button title/short action text"),
             nil,
             u"%@", NSLocalizedString(
                 (u"For best results, you should connect your computer to a "
                 "power source before updating. Are you sure you want to "
                 "continue the update?"), u"No Power Source Warning detail"))
         msclog.log("MSU", "alert_on_battery_power")
         # making UI consistent with Apple Software Update...
         # set Cancel button to be activated by return key
         alert.buttons()[1].setKeyEquivalent_('\r')
         # set Continue button to be activated by Escape key
         alert.buttons()[0].setKeyEquivalent_(chr(27))
         buttonPressed = alert.runModal()
         if buttonPressed == NSAlertAlternateReturn:
             return True
     return False
예제 #4
0
 def alertedToFirmwareUpdatesAndCancelled(self):
     '''Returns True if we have one or more firmware updates and 
     the user clicks the Cancel button'''
     firmware_alert_info = self.getFirmwareAlertInfo()
     if not firmware_alert_info:
         return False
     power_info = munki.getPowerInfo()
     on_battery_power = (power_info.get('PowerSource') == 'Battery Power')
     for item in firmware_alert_info:
         alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(item['name'],
               NSLocalizedString(u"Continue", u"Continue button text"),
               NSLocalizedString(u"Cancel", u"Cancel button title/short action text"),
               nil,
               u"")
         if on_battery_power:
             alert_text = NSLocalizedString(
                 u"Your computer is not connected to a power source.",
                 u"No Power Source Warning text")
             alert_text += "\n\n" + item['alert_text']
         else:
             alert_text = item['alert_text']
         alert.setInformativeText_(alert_text)
         alert.setAlertStyle_(NSCriticalAlertStyle)
         if on_battery_power:
             # set Cancel button to be activated by return key
             alert.buttons()[1].setKeyEquivalent_('\r')
             # set Continue button to be activated by Escape key
             alert.buttons()[0].setKeyEquivalent_(chr(27))
         buttonPressed = alert.runModal()
         if buttonPressed == NSAlertAlternateReturn:
             return True
     return False
예제 #5
0
 def alertIfRunnningOnBattery(self):
     power_info = munki.getPowerInfo()
     if (power_info.get('PowerSource') == 'Battery Power'
             and power_info.get('BatteryCharge', 0) < 50):
         alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
             NSLocalizedString(
                 u"Your computer is not connected to a power source.",
                 None), NSLocalizedString(u"Continue", None),
             NSLocalizedString(u"Cancel", None), objc.nil,
             NSLocalizedString(
                 u"For best results, you should connect your computer to a power source before updating. Are you sure you want to continue the update?",
                 None))
         munki.log("MSU", "alert_on_battery_power")
         # making UI consistent with Apple Software Update...
         # set Cancel button to be activated by return key
         alert.buttons()[1].setKeyEquivalent_('\r')
         # set Ccontinue button to be activated by Escape key
         alert.buttons()[0].setKeyEquivalent_(chr(27))
         buttonPressed = alert.runModal()
         if buttonPressed == NSAlertAlternateReturn:
             return True
     return False
예제 #6
0
 def alertIfRunnningOnBattery(self):
     power_info = munki.getPowerInfo()
     if (power_info.get('PowerSource') == 'Battery Power'
         and power_info.get('BatteryCharge', 0) < 50):
         alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
             NSLocalizedString(
                 u"Your computer is not connected to a power source.", None),
             NSLocalizedString(u"Continue", None),
             NSLocalizedString(u"Cancel", None),
             objc.nil,
             NSLocalizedString(
                 (u"For best results, you should connect your computer to a "
                 "power source before updating. Are you sure you want to "
                 "continue the update?"), None))
         munki.log("MSU", "alert_on_battery_power")
         # making UI consistent with Apple Software Update...
         # set Cancel button to be activated by return key
         alert.buttons()[1].setKeyEquivalent_('\r')
         # set Continue button to be activated by Escape key
         alert.buttons()[0].setKeyEquivalent_(chr(27))
         buttonPressed = alert.runModal()
         if buttonPressed == NSAlertAlternateReturn:
             return True
     return False