Python Forum
Python script that calls jamfHelper binary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python script that calls jamfHelper binary
#18
(May-05-2019, 07:26 AM)SheeppOSU Wrote:
(May-05-2019, 05:49 AM)kennethdean2010 Wrote: it just keeps looping
That's because there is no break. You need to break it eventually. Here's an example of how it is uses -
import random loopTimes = random.randint(1, 10) while True: for x in range(1, loopTimes + 1): if x == loopTimes + 1: break #Breaks out of the while loop
Could implement break after something reaches a specific value

Ok so how would place the counter into the code:

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
    """

#counter to loop through display_prompt X amount of times.

    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),
           '- ']
    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."
        count = 0
        return None
        count = 0
        while True:
            count += 1
            display_prompt()
            if str(count) in GUI_DEFER_OPTIONS:
                for x in range(1, loopTimes + 1):
                    def display_prompt()
                    break
Right now I have it below the def display_prompt() function with a break :) however it just does the update after I select the 5 min deferral option. It does not re-prompt with 2 4 & 8 hours + the Start Now option.
Reply


Messages In This Thread
RE: Python script that calls jamfHelper binary - by kennethdean2010 - May-06-2019, 08:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Code for Preorder Traversal of a Binary Tree Bolt 1 682 Sep-22-2023, 09:32 AM
Last Post: Gribouillis
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,604 Jun-29-2023, 11:57 AM
Last Post: gologica
  How do I read and write a binary file in Python? blackears 6 7,817 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  How to assigned value to each different binary in python... ZYSIA 2 2,129 Jul-12-2021, 11:01 AM
Last Post: Gribouillis
  Calls to Attributes of a Class SKarimi 3 3,521 Apr-22-2021, 04:18 PM
Last Post: SKarimi
  How to convert a python code to binary? rsurathu 0 1,862 Aug-02-2020, 08:09 AM
Last Post: rsurathu
  python read binary file Pyguys 4 4,067 Jul-13-2020, 02:34 AM
Last Post: Pyguys
  How to kill a bash script running as root from a python script? jc_lafleur 4 6,117 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,395 May-28-2020, 05:27 PM
Last Post: micseydel
  Binary to decimal script ThorOdinson12521 1 1,921 May-19-2020, 04:22 PM
Last Post: ThorOdinson12521

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020