Commits

Chris Adams  committed 2047664

Updated check_site to use Jinja2 for text reports

  • Participants
  • Parent commits 8b7faa4

Comments (0)

Files changed (2)

File bin/check_site.py

             self.generate_text(output)
 
     def generate_html(self, output):
+        self.generate_report(output, "check_site_report.html")
+
+    def generate_text(self, output):
+        self.generate_report(output, "check_site_report.txt")
+
+    def generate_report(self, output, template_name):
         from jinja2 import Environment, PackageLoader
         env = Environment(autoescape=True, loader=PackageLoader('webtoolbox', 'templates'))
 
-        template = env.get_template("check_site_report.html")
+        template = env.get_template(template_name)
         output.write(template.render(
             messages=self.messages,
             pages=self.pages,
             **self.extra_context
         ))
 
-    def generate_text(self, output):
-        print "%(title)s" % self.extra_context
-        print "Retrieved %(urls_total)d URLs in %(elapsed_time)0.2f seconds with %(urls_error)d errors" % self.extra_context
-
-        for level in self.REPORT_ORDER:
-            if not level in self.messages:
-                continue
-
-            print >> output, "%s:" % self.SEVERITY_LEVELS[level]
-            categories = self.messages[level]
-
-            for category in sorted(categories.keys()):
-                summaries = categories[category]
-                print >> output, "\t%s:" % category
-
-                for summary, data in summaries.items():
-                    print >> output, "\t\t%s: %d pages" % (summary, len(data['urls']))
-                    print >> output, "\t\t\t%s" % "\n\t\t\t".join(sorted(data['urls']))
-                    print >> output
-
-            print >> output
-
 
 class QASpider(Spider):
     def __init__(self, validate_html=False, log_name="QASpider", **kwargs):

File webtoolbox/templates/check_site_report.txt

+=============================================================================
+{{ title }}
+=============================================================================
+
+Processed {{ urls_total }} URLs in {{ "%0.1f"|format(elapsed_time) }} seconds with {{ urls_error }} errors
+{% for level in severity_levels if level in messages %}
+{{ severity_levels[level]|title }}
+===================================
+
+{% for category in messages[level]|sort %}{{ category }}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+{% for summary, data in messages[level][category]|dictsort %}
+{{ summary|safe }}
+-----------------------------------
+{% for url in data['urls']|sort %}
+    {{ url }}{% endfor %}
+{% endfor %}{% endfor %}{% endfor %}
+
+All Pages
+---------
+{% for url in pages|sort %}
+    {{ url }}{% endfor %}
+
+All Resources
+-------------
+{% for url in resources|sort %}
+    {{ url }}{% endfor %}
+
+All Media
+---------
+{% for url in media|sort %}
+    {{ url }}{% endfor %}
+
+_______________________
+Generated by check_site, part of the open source webtoolbox package
+See http://acdha.github.com/webtoolbox/ for more information