3
if os.sep + 'dosage' in os.path.abspath(sys.argv[0]):
4
sys.path.insert(0, os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir)))
11
This tool builds a list of all comic modules dosage supports, gets some support
12
data from a CSV table and generates a nice HTML table to compare Dosage against
13
other webcomic aggregators.
16
def constructRow(header, dataDict, count, url = None):
18
url = url or dataDict['URL']
20
celldata = dataDict[x]
21
if celldata.split()[0] == '-':
25
if dataDict["broken"] != 'yes':
26
count[x].add(celldata)
29
if dataDict["broken"] == 'yes':
31
count['broken'].add(celldata)
33
celldata = '<a href="%s">%s</a>' % (url, celldata)
34
row.append((cellclass, celldata))
38
def simpleTable(datarows, headerrows = [], footerrows = []):
39
html = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
40
"http://www.w3.org/TR/html4/strict.dtd">
41
<html><head><title>Dosage Comparison</title>
42
<script src="sortable.js"></script>
43
<meta http-equiv="Content-Type" value="text/html; charset=utf-8">
44
<link rel="stylesheet" type="text/css" href="compare-table.css">
45
</head><body><p>For easier reading this table is color coded. For the first
46
column green fields show that this comic was found on the net the last time
47
someone checked, red means the comic seems to have disappered. For all
48
other columns green shows a supported comic and red an unsupported
50
<table class="sortable" id="comparison"><thead>
52
for row in headerrows:
53
html += '<tr><th>' + '</th><th>'.join(row) + "</th></tr>\n"
54
html += "</thead><tfoot>\n"
55
for row in footerrows:
56
html += '<tr><th>' + '</th><th>'.join(row) + "</th></tr>\n"
57
html += "</tfoot><tbody>\n"
59
html += '<tr>' + ''.join(['<td class="%s">%s</td>' % x for x in row]) + "</tr>\n"
60
html += "</tbody></table></body>"
64
base = os.path.splitext(sys.argv[0])[0]
65
csvdata = csv.DictReader(open(base + ".csv", "rb"), dialect='excel-tab')
69
if row['Dosage'].split()[0] != '-':
70
for strip in row['Dosage'].split(','):
71
supported[strip] = row.copy()
72
supported[strip]['Dosage'] = strip
74
unsupported.append(row)
75
header = [x for x in csvdata.fieldnames if x not in ('URL', 'broken')]
78
for x in csvdata.fieldnames:
83
for moduleName in dosage.modules.items(dosage.modules.__path__[0]):
84
module = dosage.modules.get(moduleName)
85
extradata = supported.pop(moduleName, None)
88
url = module.latestUrl
90
print "WARNING: %s cannot get latest URL!" % (moduleName)
91
url = getattr(module, 'baseUrl', None)
92
rows.append(constructRow(header, extradata, counters, url))
94
notfound.append(moduleName)
95
print "The following Dosage modules are not in the CSV table: " + " ".join(notfound)
96
print "The following Dosage modules are in the CSV table but not in Dosage: " + " ".join(supported)
98
# At least add the rows with errors to the table
99
for module in supported:
100
supported[module]['Dosage'] = '- (was %s)' % (module)
101
rows.append(constructRow(header, supported[module], counters))
103
for module in unsupported:
104
rows.append(constructRow(header, module, counters))
106
footer = [str(len(counters[x])) for x in header]
107
footer[0] += ' (+ %i broken)' % (len(counters['broken']))
109
deltags = re.compile(r'<[^<>]+>')
110
rows.sort(cmp = lambda x,y: cmp(deltags.sub("", x[0][1].lower()), deltags.sub("", y[0][1].lower())))
112
f = open(base + '.html', 'w')
114
f.write(simpleTable(rows, [header], [footer]))
118
if __name__ == '__main__':