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
#2
I'm not entirely sure if this is what your looking for and it can probably be improved upon.
class ChoiceError(Exception):
    pass

class RestartChoices():

    def __init__(self):
        self.reset_choices()

    def reset_choices(self):
        self.choices = ["Start Now", "5 minutes", "2 hours", "4 hours",
                        "8 hours"]
        self.last_choice = ''

    def make_choice(self, choice):
        if choice not in self.choices:
            raise ChoiceError('invalid choice')
        self.last_choice = choice
        if choice == self.choices[-1] or choice == self.choices[0]:
            self.choices = []
            return

        choice_index = self.choices.index(choice) + 1
        self.choices = self.choices[:1] + self.choices[choice_index:]

restart_choices = RestartChoices()
restart_choices.make_choice('5 minutes')
print(f'choice: {restart_choices.last_choice}')
print(f'Remaining: {restart_choices.choices}')

restart_choices.make_choice('4 hours')
print(f'choice: {restart_choices.last_choice}')
print(f'Remaining: {restart_choices.choices}')

restart_choices.make_choice('8 hours')
print(f'choice: {restart_choices.last_choice}')
print(f'Remaining: {restart_choices.choices}')

restart_choices.reset_choices()
restart_choices.make_choice('2 hours')
print(f'choice: {restart_choices.last_choice}')
print(f'Remaining: {restart_choices.choices}')

restart_choices.reset_choices()
restart_choices.make_choice('Start Now')
print(f'choice: {restart_choices.last_choice}')
print(f'Remaining: {restart_choices.choices}')
Output:
choice: 5 minutes Remaining: ['Start Now', '2 hours', '4 hours', '8 hours'] choice: 4 hours Remaining: ['Start Now', '8 hours'] choice: 8 hours Remaining: [] choice: 2 hours Remaining: ['Start Now', '4 hours', '8 hours'] choice: Start Now Remaining: []
Reply


Messages In This Thread
RE: Python script that calls jamfHelper binary - by Yoriz - May-01-2019, 10:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  search API calls in different format pythonnewbieee 4 1,459 Sep-23-2024, 04:14 AM
Last Post: Pedroski55
  Python Code for Preorder Traversal of a Binary Tree Bolt 1 2,075 Sep-22-2023, 09:32 AM
Last Post: Gribouillis
  How do I read and write a binary file in Python? blackears 6 26,693 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  How to assigned value to each different binary in python... ZYSIA 2 2,993 Jul-12-2021, 11:01 AM
Last Post: Gribouillis
  Calls to Attributes of a Class SKarimi 3 4,734 Apr-22-2021, 04:18 PM
Last Post: SKarimi
  How to convert a python code to binary? rsurathu 0 2,393 Aug-02-2020, 08:09 AM
Last Post: rsurathu
  python read binary file Pyguys 4 6,358 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 8,265 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 3,049 May-28-2020, 05:27 PM
Last Post: micseydel
  Binary to decimal script ThorOdinson12521 1 2,502 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