Skip to content

Commit

Permalink
Merge pull request #20 from zaytiri/add-status-argument
Browse files Browse the repository at this point in the history
add status argument
  • Loading branch information
zaytiri authored Mar 27, 2023
2 parents 6a9014e + 4dae815 commit e65200f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
44 changes: 30 additions & 14 deletions progscheduler/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ def validate_global_settings(arguments):
show('Option: \"exit-when-done\" is enabled. This windows will close automatically when all jobs are done.')


def run_scheduler(arguments):
show('The program will now start running the scheduler.\n\n\t\t\t*NOTE:* While this is running this window should not be closed. If you are '
'certain that all scheduled jobs are already finished, then it is safe to close this window.')

scheduler = Scheduler()

for program in arguments['Specific']:
do_scheduled_job(scheduler, arguments['Specific'][program])

scheduler.run(arguments['Generic'].exit_when_done.value)

if arguments['Generic'].exit_when_done.value:
os.system('title kill_current_terminal_window')
os.system(f'taskkill /f /fi "WINDOWTITLE eq kill_current_terminal_window"')


def is_time_to_stop_valid(program_name, time_to_stop):
if time_to_stop != 'off'.lower():
now = datetime.utcnow()
Expand All @@ -45,27 +61,27 @@ def is_scheduled_today(days_to_schedule):
return now.strftime("%A").lower() in days_to_schedule


def run_scheduler(arguments):
show('The program will now start running the scheduler.\n\n\t\t\t*NOTE:* While this is running this window should not be closed. If you are '
'certain that all scheduled jobs are already finished, then it is safe to close this window.')
def is_status_valid(program_name, status):
if status.lower() == 'off'.lower():
show('\"' + program_name + '\" is inactive and it will not run. Status: OFF.')
return True

scheduler = Scheduler()

for program in arguments['Specific']:
do_scheduled_job(scheduler, arguments['Specific'][program])
def scheduled_job_invalid(program):
if not is_scheduled_today(program.days.value):
return True

scheduler.run(arguments['Generic'].exit_when_done.value)
if is_time_to_stop_valid(program.alias.value, program.time_to_stop.value):
return True

if arguments['Generic'].exit_when_done.value:
os.system('title kill_current_terminal_window')
os.system(f'taskkill /f /fi "WINDOWTITLE eq kill_current_terminal_window"')
if is_status_valid(program.alias.value, program.status.value):
return True

return False

def do_scheduled_job(scheduler, program):
if not is_scheduled_today(program.days.value):
return

if is_time_to_stop_valid(program.alias.value, program.time_to_stop.value):
def do_scheduled_job(scheduler, program):
if scheduled_job_invalid(program):
return

scheduler.set_method_to_schedule(lambda: open_program(program.path.value))
Expand Down
21 changes: 18 additions & 3 deletions progscheduler/settings/specific_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,22 @@ def __init__(self):
self.time_to_stop = Argument(name='time_to_stop',
abbreviation_name='-ts',
full_name='--time-to-stop',
help_message='If a time is set, the scheduled job will not run, after specified time. If this argument equals '
'\"off\", this setting will be ignored. Time is expected to be according to 24 hours cycle. '
help_message='If a time is set, the scheduled job will not run, after specified time in a day. If this argument '
'equals \"off\", this setting will be ignored. Time is expected to be according to 24 hours cycle. '
'example: -ss 13:30 (meaning the job will not run if time exceeds 13:30), -ss off',
metavar="",
to_save=True,
default='off')

self.status = Argument(name='status',
abbreviation_name='-st',
full_name='--status',
help_message='This indicates if a scheduled job is active or inactive. Default value is \"on\". example -st on, '
'-st off',
metavar="",
to_save=True,
default='on')

def set_are_configs_saved(self, are_configs_saved):
self.are_configs_saved = are_configs_saved

Expand Down Expand Up @@ -84,13 +93,19 @@ def add_arguments(self, args_parser):
type=str,
help=self.time.help_message,
metavar=self.time.metavar,
default=self.time.default)
default=argparse.SUPPRESS)

args_parser.add_argument(self.time_to_stop.abbreviation_name, self.time_to_stop.full_name,
help=self.time_to_stop.help_message,
metavar=self.time_to_stop.metavar,
default=argparse.SUPPRESS)

args_parser.add_argument(self.status.abbreviation_name, self.status.full_name,
choices=['on', 'off'],
help=self.status.help_message,
metavar=self.status.metavar,
default=argparse.SUPPRESS)

def process_arguments(self, settings):
self.__check_any_errors(settings[0].user_arguments)
self.__process_days(settings[0].user_arguments)
Expand Down

0 comments on commit e65200f

Please sign in to comment.