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.

53 lines
2.3 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("node", lexers.JavascriptLexer())
  28. _process("python_urllib2", lexers.PythonLexer())
  29. _process("python_requests", lexers.PythonLexer())
  30. _process("python_requests_fail", lexers.PythonLexer())
  31. _process("php", lexers.PhpLexer())
  32. _process("powershell", lexers.shell.PowerShellLexer())
  33. _process("powershell_inline", lexers.shell.BashLexer())
  34. _process("ruby", lexers.RubyLexer())
  35. # API examples
  36. _process("list_checks_request", lexers.BashLexer())
  37. _process("list_checks_response", lexers.JsonLexer())
  38. _process("create_check_request_a", lexers.BashLexer())
  39. _process("create_check_request_b", lexers.BashLexer())
  40. _process("update_check_request_a", lexers.BashLexer())
  41. _process("update_check_request_b", lexers.BashLexer())
  42. _process("create_check_response", lexers.JsonLexer())
  43. _process("pause_check_request", lexers.BashLexer())
  44. _process("pause_check_response", lexers.JsonLexer())
  45. _process("delete_check_request", lexers.BashLexer())