Hi I have a python script I am using to update my Macbooks at work that calls the jamfBinary to display a hud that allows the user to defer updates.
At this time it only presents the hud once with 5 options,
What I want is it to display the prompt again minus the options that preceded it.
So if the input is 5 mins, then in roughly five minutes the hud reappears with
I want them to be able to defer multiple times until the max deferral time period has been reached.
I have attached the script.
I was thinking I could just re-use this section of code however many times I need it to prompt but I am not sure if I am thinking about this correctly as I am not a Python Pro but I have some experience programming in C++.
My apologies. Any guidance is much appreciated.
***This is the code I believe I can reuse to accomplish the hud being prompted, I am just not sure if I am logically approaching this the right way.
At this time it only presents the hud once with 5 options,
- "Start Now",
- "5 minutes",
- "2 hours",
- "4 hours",
- "8 hours".
What I want is it to display the prompt again minus the options that preceded it.
So if the input is 5 mins, then in roughly five minutes the hud reappears with
- "Start Now",
- "2 hours",
- "4 hours",
- "8 hours".
I want them to be able to defer multiple times until the max deferral time period has been reached.
I have attached the script.
I was thinking I could just re-use this section of code however many times I need it to prompt but I am not sure if I am thinking about this correctly as I am not a Python Pro but I have some experience programming in C++.
My apologies. Any guidance is much appreciated.
***This is the code I believe I can reuse to accomplish the hud being prompted, I am just not sure if I am logically approaching this the right way.
def display_prompt():
"""Displays prompt to allow user to schedule update installation
Args:
None
Returns:
(int) defer_seconds: Number of seconds user wishes to defer policy
OR
None if an error occurs
"""
cmd = [JAMFHELPER,
'-windowType', 'hud',
'-title', GUI_WINDOW_TITLE,
'-heading', GUI_HEADING,
'-icon', GUI_ICON,
'-description', GUI_MESSAGE,
'-button1', GUI_BUTTON,
'-showDelayOptions',
' '.join(GUI_DEFER_OPTIONS),
'-lockHUD']
error_values = ['2', '3', '239', '243', '250', '255']
# Instead of returning an error code to stderr, jamfHelper always returns 0
# and possibly returns an 'error value' to stdout. This makes it somewhat
# spotty to check for some deferrment values including 0 for 'Start Now'.
# The return value is an integer, so leading zeroes are dropped. Selecting
# 'Start Now' should technically return '01'; instead, only '1' is returned
# which matches the 'error value' for 'The Jamf Helper was unable to launch'
# All we can do is make sure the subprocess doesn't raise an error, then
# assume (yikes!) a return value of '1' equates to 'Start Now'
try:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = proc.communicate()
# Check that the return value does not represent an 'error value'
if not out in error_values:
# Special case for 'Start Now' which returns '1'
if out == '1':
return 0
else:
return int(out[:-1])
else:
return None
except:
# Catch possible CalledProcessError and OSError
print "An error occurred when displaying the user prompt."
return None
