2012-11-28 17:15:12 +00:00
|
|
|
#!/usr/bin/env python
|
2012-11-29 05:46:58 +00:00
|
|
|
# Copyright (C) 2012 Bastian Kleineidam
|
2012-11-28 17:15:12 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
from dosagelib.scraper import get_scrapers
|
|
|
|
|
|
|
|
htmltemplate = """
|
2012-12-17 20:28:20 +00:00
|
|
|
---
|
|
|
|
extends: base.j2
|
|
|
|
title: Dosage by Bastian Kleineidam
|
|
|
|
description: a commandline webcomic downloader and archiver
|
|
|
|
---
|
2012-12-17 21:01:02 +00:00
|
|
|
{% block js %}
|
|
|
|
<script src="media/js/masonry.min.js"></script>
|
|
|
|
{% endblock js %}
|
2012-12-17 20:28:20 +00:00
|
|
|
|
2012-12-17 21:01:02 +00:00
|
|
|
{% block content %}
|
2012-12-17 20:28:20 +00:00
|
|
|
<div class="inner clearfix">
|
|
|
|
<section id="main-content">
|
|
|
|
|
|
|
|
<h2>Dosage test results from %(date)s</h2>
|
|
|
|
<p>Note that it is almost impossible to get a 100%% OK test run
|
|
|
|
due to temporary site failures.</p>
|
|
|
|
<div id="testresults">
|
2012-12-05 20:52:52 +00:00
|
|
|
%(content)s
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
window.onload = function() {
|
|
|
|
var wall = new Masonry( document.getElementById('container'), {
|
|
|
|
columnWidth: 240
|
|
|
|
});
|
|
|
|
};
|
|
|
|
</script>
|
2012-12-17 21:01:02 +00:00
|
|
|
{% endblock content %}
|
2012-11-28 17:15:12 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def get_mtime (filename):
|
|
|
|
"""Return modification time of filename."""
|
2012-12-17 20:28:20 +00:00
|
|
|
return os.path.getmtime(filename)
|
2012-11-28 17:15:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def strdate(t):
|
|
|
|
return time.strftime("%d.%m.%Y", time.localtime(t))
|
|
|
|
|
|
|
|
|
|
|
|
def get_test_name(line):
|
|
|
|
classname = line.split('::')[1][4:]
|
|
|
|
for scraper in get_scrapers():
|
|
|
|
if scraper.__name__ == classname:
|
|
|
|
try:
|
|
|
|
url = scraper.starter()
|
|
|
|
except Exception:
|
|
|
|
url = None
|
|
|
|
return scraper.get_name(), url
|
|
|
|
raise ValueError("Scraper %r not found" % classname)
|
|
|
|
|
|
|
|
|
|
|
|
def get_test(line):
|
|
|
|
name, url = get_test_name(line)
|
2012-12-12 16:41:29 +00:00
|
|
|
result = "OK" if line.startswith(". ") else "FAILED"
|
|
|
|
return [name, url, result, ""]
|
2012-11-28 17:15:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_content(filename):
|
|
|
|
tests = []
|
|
|
|
with open(filename, "r") as f:
|
|
|
|
print("Tests parsed: 0", end=" ", file=sys.stderr)
|
|
|
|
num_tests = 0
|
2012-12-13 20:05:27 +00:00
|
|
|
add_reason = False
|
2012-11-28 17:15:12 +00:00
|
|
|
for line in f:
|
|
|
|
if line.startswith((". ", "F ")) and "test_comics" in line:
|
2012-12-13 20:05:27 +00:00
|
|
|
add_reason = line.startswith("F ")
|
2012-11-28 17:15:12 +00:00
|
|
|
num_tests += 1
|
2012-12-02 17:35:06 +00:00
|
|
|
try:
|
|
|
|
tests.append(get_test(line))
|
|
|
|
except Exception as msg:
|
|
|
|
print("WARNING:", msg, file=sys.stderr)
|
2012-12-13 20:05:27 +00:00
|
|
|
continue
|
2012-12-12 16:41:29 +00:00
|
|
|
elif add_reason and line.startswith(" E "):
|
|
|
|
reason = line[3:].strip()
|
|
|
|
tests[-1][-1] = reason
|
2012-11-28 17:15:12 +00:00
|
|
|
if num_tests % 5 == 0:
|
|
|
|
print(num_tests, end=" ", file=sys.stderr)
|
|
|
|
tests.sort()
|
|
|
|
res = []
|
2012-12-12 16:41:29 +00:00
|
|
|
for name, url, result, reason in tests:
|
|
|
|
css = result.lower()
|
2012-12-07 23:45:18 +00:00
|
|
|
if len(name) > 25 and '/' in name:
|
|
|
|
name = name.replace('/', '/ ')
|
2012-11-28 17:15:12 +00:00
|
|
|
if url:
|
2012-12-12 16:41:29 +00:00
|
|
|
inner = '<a href="%s" title="%s" class="%s">%s %s</a>' % (url, reason, css, name, result)
|
2012-11-28 17:15:12 +00:00
|
|
|
else:
|
2012-12-12 16:41:29 +00:00
|
|
|
inner = '<span title="%s" class="%s">%s %s</span>' % (reason, css, name, result)
|
2012-12-05 20:52:52 +00:00
|
|
|
res.append(' <div class="item">%s</div>' % inner)
|
2012-11-28 17:15:12 +00:00
|
|
|
return os.linesep.join(res)
|
|
|
|
|
|
|
|
|
|
|
|
def main(args):
|
2012-12-07 23:45:18 +00:00
|
|
|
filename = args[0]
|
2012-11-28 17:15:12 +00:00
|
|
|
modified = get_mtime(filename)
|
|
|
|
content = get_content(filename)
|
|
|
|
attrs = {"date": strdate(modified), "content": content}
|
|
|
|
print(htmltemplate % attrs)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv[1:]))
|