def add_job_in_crontab(alarm): """ use the crontab manager to add a new job :param alarm: AlarmClock :return: """ day_of_week = _get_day_of_week(alarm) current_script_path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) run_script_path = get_root_path(current_script_path) + os.sep + "run_mp3_playback.py" # new_job: <minute> <hour> * * <day_of_week> <run_script_path> <mp3playback_id> new_job = "%s %s * * %s python3.5 %s %s " % (alarm.minute, alarm.hour, day_of_week, run_script_path, alarm.mp3_playback.id) if alarm.auto_stop_seconds is not 0: # new_job: <minute> <hour> * * <day_of_week> <run_script_path> <alarm_id> <auto_stop_seconds> new_job += "%s " % alarm.auto_stop_seconds # new_job: <minute> <hour> * * <day_of_week> <run_script_path> <alarm_id> [<auto_stop_minute>] # alertrug<alarm_id> new_job += " > /tmp/cron.tmp 2> /tmp/cron2.tmp # alertrug%s" % alarm.id if not alarm.is_active: line = "# " new_job = line + new_job print( "Crontab job line: %s" % new_job ) CrontabManager.add_job(new_job)
def add_job_in_crontab(alarm): """ use the crontab manager to add a new job :param alarm: AlarmClock :return: """ day_of_week = _get_day_of_week(alarm) current_script_path = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) run_script_path = get_root_path( current_script_path) + os.sep + "run_web_radio.py" # new_job: <minute> <hour> * * <day_of_week> <run_script_path> <webradio_id> new_job = "%s %s * * %s python %s %s " % (alarm.minute, alarm.hour, day_of_week, run_script_path, alarm.webradio.id) if alarm.auto_stop_minutes is not 0: # new_job: <minute> <hour> * * <day_of_week> <run_script_path> <alarm_id> <auto_stop_minute> new_job += "%s " % alarm.auto_stop_minutes # new_job: <minute> <hour> * * <day_of_week> <run_script_path> <alarm_id> [<auto_stop_minute>] # piclodio<alarm_id> new_job += "# piclodio%s" % alarm.id if not alarm.is_active: line = "# " new_job = line + new_job print "Crontab job line: %s" % new_job CrontabManager.add_job(new_job)