You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.6 KiB

  1. from django.core.management.base import BaseCommand
  2. def _process(name, lexer):
  3. from pygments import highlight
  4. from pygments.formatters import HtmlFormatter
  5. source = open("templates/front/snippets/%s.txt" % name).read()
  6. processed = highlight(source, lexer, HtmlFormatter())
  7. processed = processed.replace("PING_URL", "{{ ping_url }}")
  8. processed = processed.replace("SITE_ROOT", "{{ SITE_ROOT }}")
  9. processed = processed.replace("PING_ENDPOINT", "{{ PING_ENDPOINT }}")
  10. with open("templates/front/snippets/%s.html" % name, "w") as out:
  11. out.write(processed)
  12. class Command(BaseCommand):
  13. help = "Compiles snippets with Pygments"
  14. def handle(self, *args, **options):
  15. try:
  16. from pygments import lexers
  17. except ImportError:
  18. self.stdout.write("This command requires Pygments package.")
  19. self.stdout.write("Please install it with:\n\n")
  20. self.stdout.write(" pip install Pygments\n\n")
  21. return
  22. # Invocation examples
  23. _process("bash_curl", lexers.BashLexer())
  24. _process("bash_wget", lexers.BashLexer())
  25. _process("browser", lexers.JavascriptLexer())
  26. _process("crontab", lexers.BashLexer())
  27. _process("cs", lexers.CSharpLexer())
  28. _process("node", lexers.JavascriptLexer())
  29. _process("python_urllib2", lexers.PythonLexer())
  30. _process("python_requests", lexers.PythonLexer())
  31. _process("python_requests_fail", lexers.PythonLexer())
  32. _process("python_requests_start", lexers.PythonLexer())
  33. _process("python_requests_payload", lexers.PythonLexer())
  34. _process("php", lexers.PhpLexer())
  35. _process("powershell", lexers.shell.PowerShellLexer())
  36. _process("powershell_inline", lexers.shell.BashLexer())
  37. _process("ruby", lexers.RubyLexer())
  38. # API examples
  39. _process("list_checks_request", lexers.BashLexer())
  40. _process("list_checks_response", lexers.JsonLexer())
  41. _process("list_channels_request", lexers.BashLexer())
  42. _process("list_channels_response", lexers.JsonLexer())
  43. _process("create_check_request_a", lexers.BashLexer())
  44. _process("create_check_request_b", lexers.BashLexer())
  45. _process("update_check_request_a", lexers.BashLexer())
  46. _process("update_check_request_b", lexers.BashLexer())
  47. _process("create_check_response", lexers.JsonLexer())
  48. _process("pause_check_request", lexers.BashLexer())
  49. _process("pause_check_response", lexers.JsonLexer())
  50. _process("delete_check_request", lexers.BashLexer())