Updater for Eole scheduler configuration

sched.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. import sys
  3. from creole.loader import creole_loader, config_save_values
  4. def usage():
  5. print(u"Usage : {0} WEEKTASKSDAY MONTHTASKSDAY HOUR MINUTE\n".format(sys.argv[0]))
  6. print(u"\t Weekly tasks day : [1-7] 1=Monday")
  7. print(u"\t Weekly tasks day : [1-7] 1=Monday")
  8. print(u"\t Hour : [0-24]")
  9. print(u"\t Minute : [0-59]")
  10. sys.exit(3)
  11. if len(sys.argv) < 5:
  12. usage()
  13. weekday = int(sys.argv[1])
  14. monthday = int(sys.argv[2])
  15. hour = int(sys.argv[3])
  16. minute = int(sys.argv[4])
  17. print(u"Updating Schedule\n")
  18. print(u"Weekly tasks day : {0}".format(weekday))
  19. print(u"Monthly tasks day : {0}".format(monthday))
  20. print(u"Hour: {0}".format(hour))
  21. print(u"Minute: {0}".format(minute))
  22. if weekday == monthday :
  23. print("ERROR : Weekly taks and monthly tasks can't be the same day !")
  24. sys.exit(2)
  25. action = raw_input("\nApply configuration to schedule ? (y|n)")
  26. if action == "y" or action == "yes" or action == "o" or action == "oui":
  27. c=creole_loader(rw=True, load_extra=True)
  28. c.schedule.schedule.monthday = None
  29. # 1 == lundi
  30. c.schedule.schedule.weekday = weekday
  31. c.schedule.schedule.monthday = monthday
  32. c.schedule.schedule.hour = hour
  33. c.schedule.schedule.minute = minute
  34. config_save_values(c, 'schedule')
  35. else:
  36. sys.exit(0)