A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

45 lignes
1.4 KiB

  1. from datetime import datetime
  2. import os
  3. import re
  4. from shlex import split
  5. from subprocess import check_output, CalledProcessError, STDOUT
  6. os.environ["SGE_ROOT"] = "/sge/GE"
  7. def collect_status_info(context):
  8. try:
  9. result = str(check_output(split("qstat -j earwigbot"), stderr=STDOUT))
  10. except CalledProcessError:
  11. return ["offline", None, None, None]
  12. if result.startswith("Following jobs do not exist:"):
  13. return ["offline", None, None, None]
  14. lines = result.splitlines()[1:]
  15. data = {}
  16. for line in lines:
  17. re_key = re.match(r"(.*?):\s", line)
  18. re_val = re.search(r":\s*(.*?)$", line)
  19. if re_key and re_val:
  20. data[re_key.group(1)] = re_val
  21. since, uptime = _format_date(data["submission_time"])
  22. host = data["sge_o_host"]
  23. return ["online", since, uptime, host]
  24. def _format_date(time):
  25. start = datetime.strptime(time, "%a %b %d %H:%M:%S %Y")
  26. since = start.strftime("%b %d, %Y %H:%M:%S UTC")
  27. diff = (datetime.utcnow() - start)
  28. if diff.days:
  29. uptime = "{0} days".format(diff.days)
  30. if diff.seconds >= 3600:
  31. uptime += ", {0} hours".format(diff.seconds / 3600)
  32. else:
  33. if diff.seconds > 3600:
  34. uptime = "{0} hours".format(diff.seconds / 3600)
  35. elif diff.seconds > 60:
  36. uptime = "{0} minutes".format(diff.seconds / 60)
  37. else:
  38. uptime = "{0} seconds".format(diff.seconds)
  39. return (since, uptime)