CmdUpdate.py 722 B

1234567891011121314151617181920212223242526
  1. import os
  2. import re
  3. class CmdUpdate:
  4. def __init__(self, config):
  5. self.config = config
  6. def execute(self):
  7. print("Updating...")
  8. stream = os.popen("crontab -l")
  9. crontab = stream.read()
  10. result = crontab
  11. begin = re.search("\s*#\s*BEGIN\(ALERTS\).*", crontab)
  12. if begin:
  13. fragment = ""
  14. with open(self.config["CronFragment"]) as file:
  15. fragment = file.read()
  16. result = crontab[:begin.span()[1]] + "\n"
  17. result += fragment
  18. end = re.search("\s*#\s*END\(ALERTS\).*", crontab)
  19. if end:
  20. result += crontab[end.span()[0]:]
  21. print(result)