josch

python3 support

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
#
# Copyright (C) 2013 Johannes Schauer <j.schauer at email.de>
#
......@@ -13,7 +12,7 @@ import json
from datetime import datetime
if len(sys.argv) != 4:
print "usage: %s date mainarchs portarchs"
print("usage: %s date mainarchs portarchs")
exit(1)
newestdate = datetime.strptime(sys.argv[1], "%Y%m%dT%H%M%SZ")
......@@ -62,6 +61,9 @@ apt_pkg.init()
sources = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: {arch:False for arch in archs if data[arch]})))
def cmp(a,b):
return (a > b) - (a < b)
# sort first by binary/source, then by name, then by version
def binpkgcmp(a, b):
n1, a1, v1 = a
......@@ -116,7 +118,7 @@ def vertcmp(a, b):
try:
return srcpkgcmp(data1,data2)
except:
print("FIXME: duplicate SrcPkg vertex %s"%data1[0])
print(("FIXME: duplicate SrcPkg vertex %s"%data1[0]))
return 0
else:
raise Exception("invalid vertex type: %s"%t2)
......@@ -183,11 +185,11 @@ binary_ratios.sort(reverse=True)
if not source_ratios:
source_ratio_cutoff = 0
else:
source_ratio_cutoff = source_ratios[len(source_ratios)/10]
source_ratio_cutoff = source_ratios[len(source_ratios)//10]
if not binary_ratios:
binary_ratio_cutoff = 0
else:
binary_ratio_cutoff = binary_ratios[len(binary_ratios)/10]
binary_ratio_cutoff = binary_ratios[len(binary_ratios)//10]
sources_in_scc = {arch:defaultdict(set) for arch in archs if data[arch]}
......@@ -252,7 +254,7 @@ sources_in_scc_d = defaultdict(set)
for arch in archs:
if not data[arch]:
continue
for k,v in sources_in_scc[arch].items():
for k,v in list(sources_in_scc[arch].items()):
sources_in_scc_d[k].update(v)
# string of package
......@@ -296,10 +298,10 @@ def soc(c):
t,data = v
if t == 'SrcPkg':
# the previous edge was a "buildsfrom" edge
res += u" <span title=\"builds from\" class=\"arrowouter\"><span class=\"arrowinner\">→</span></span> "
res += " <span title=\"builds from\" class=\"arrowouter\"><span class=\"arrowinner\">→</span></span> "
elif t == 'InstSet':
# the previous edge was a "builddepends" edge
res += u" <span title=\"build depends\" class=\"arrowouter\"><span class=\"arrowinner\">⇢</span></span> "
res += " <span title=\"build depends\" class=\"arrowouter\"><span class=\"arrowinner\">⇢</span></span> "
else:
raise Exception("invalid vertex type: %s"%t)
res += sov(v)
......@@ -419,8 +421,8 @@ def render_table(name,src,ver):
if data[arch]:
f.write('<th>%s</th>'%arch)
f.write('</tr></thead><tbody>')
for k,v in sources[src,ver][name].items():
f.write(('<tr><td>'+'</td><td>'.join(tables[name]['printer'](*k))+'</td>').encode("utf8"))
for k,v in list(sources[src,ver][name].items()):
f.write('<tr><td>'+'</td><td>'.join(tables[name]['printer'](*k))+'</td>')
for arch in archs:
if not data[arch]:
continue
......@@ -430,7 +432,7 @@ def render_table(name,src,ver):
f.write('</tbody></table>')
for src, ver in sources:
f=open("bootstrap.debian.net/source/%s_%s.html"%(src,ver), "w")
f=open("bootstrap.debian.net/source/%s_%s.html"%(src,ver), "w", encoding="utf8")
f.write("""<!DOCTYPE html>
<html>
<head>
......@@ -460,7 +462,7 @@ table {font-size: 1em !important}
$.each($("table.tablesorter"), function(index, val) {
var id = $(val).attr('id');
$(val).tablesorter({widthFixed:true}).tablesorterPager({container: $('#' + id + '_pager'), positionFixed: false});"""%(src,newestdate.isoformat()))
for name,val in tables.items():
for name,val in list(tables.items()):
f.write(" $('#%s').trigger(\"sorton\",[[[0,%d]]]);"%(name,val['order']))
f.write(""" });
});
......@@ -483,8 +485,8 @@ last updated: %s
</html>""")
f.close()
for srcname,versions in sources_in_scc_d.items():
f=open("bootstrap.debian.net/source/%s.html"%srcname, "w")
for srcname,versions in list(sources_in_scc_d.items()):
f=open("bootstrap.debian.net/source/%s.html"%srcname, "w", encoding="utf8")
f.write("""<!DOCTYPE html>
<html>
<head>
......@@ -532,8 +534,7 @@ source package in the respective architecture.
now = datetime.now().isoformat()
import codecs
f=codecs.open("bootstrap.debian.net/index.html", "w", "utf-8")
f=open("bootstrap.debian.net/index.html", "w", encoding="utf8")
f.write("""<!DOCTYPE html>
<html>
<head>
......@@ -687,7 +688,7 @@ for i,srcname in enumerate(sorted(sources_in_scc_d)):
fullname = "src:%s&nbsp;(=&nbsp;%s)"%(srcname,v)
shortver = v
if len(shortver) > 10:
shortver = shortver[:10]+u"…"
shortver = shortver[:10]+"…"
f.write("""<a href="/source/%s_%s.html" class=\"pkg\" title=\"%s\">%s</a>"""%(srcname,v,fullname,shortver))
f.write("""</td>\n""")
else:
......@@ -700,13 +701,13 @@ f.write("""</table>\n"""+footer+"""
# json can't handle tuples as dictionary keys
# turn those dictionaries into key/value tuple lists
dumpable_sources = [(k1,{k2:[(k3,v3) for k3,v3 in v2.items()] for k2,v2 in v1.items()}) for k1,v1 in sources.items()]
dumpable_sources = [(k1,{k2:[(k3,v3) for k3,v3 in list(v2.items())] for k2,v2 in list(v1.items())}) for k1,v1 in list(sources.items())]
with open("bootstrap.debian.net/source/stats.json", "w") as f:
with open("bootstrap.debian.net/source/stats.json", "w", encoding="utf8") as f:
json.dump(dumpable_sources, f, sort_keys=True, indent=2)
with open("bootstrap.debian.net/source/stats_min.json", "w") as f:
json.dump(sources.keys(), f, sort_keys=True, indent=2)
with open("bootstrap.debian.net/source/stats_min.json", "w", encoding="utf8") as f:
json.dump(list(sources.keys()), f, sort_keys=True, indent=2)
f.close()
......
......@@ -58,7 +58,7 @@ for arch in $portarchs; do
continue
fi
# add snapshot timestamp to json output:
python -c "import json,sys; f=open('./out/stats.json');d=json.load(f);f.close();d['timestamp']='$now';f=open('./out/stats.json','w');json.dump(d,f,sort_keys=True,indent=2);f.close();"
python3 -c "import json,sys; f=open('./out/stats.json');d=json.load(f);f.close();d['timestamp']='$now';f=open('./out/stats.json','w');json.dump(d,f,sort_keys=True,indent=2);f.close();"
# native.sh was successful, replace old directory with new content
rm -rf ./bootstrap.debian.net/$arch
mv ./out ./bootstrap.debian.net/$arch
......@@ -83,7 +83,7 @@ for arch in $mainarchs; do
continue
fi
# add snapshot timestamp to json output:
python -c "import json,sys; f=open('./out/stats.json');d=json.load(f);f.close();d['timestamp']='$now';f=open('./out/stats.json','w');json.dump(d,f,sort_keys=True,indent=2);f.close();"
python3 -c "import json,sys; f=open('./out/stats.json');d=json.load(f);f.close();d['timestamp']='$now';f=open('./out/stats.json','w');json.dump(d,f,sort_keys=True,indent=2);f.close();"
# native.sh was successful, replace old directory with new content
rm -rf ./bootstrap.debian.net/$arch
mv ./out ./bootstrap.debian.net/$arch
......@@ -94,7 +94,7 @@ done
rm -rf ./bootstrap.debian.net/source
mkdir -p ./bootstrap.debian.net/source
python generate_html.py "$now" "$mainarchs" "$portarchs"
python3 generate_html.py "$now" "$mainarchs" "$portarchs"
#######################################################
# Generate history.html #
......
......@@ -9,12 +9,12 @@ dist=sid
arch="i386" # because amd64 doesnt exist in the 2005 snapshots
hostarch="mipsel" # because mipsel survived from 2005 to now
# but this choice is largely irrelevant because not the real mipsel packages are used
dates=`cat << END | python -c "import sys; exec sys.stdin.read()"
dates=`cat << END | python3 -c "import sys; exec(sys.stdin.read())"
from datetime import date, timedelta as t
last = date.today()
i = date(2005, 3, 12)
while (i <= last):
print i.strftime("%Y%m%d")
print(i.strftime("%Y%m%d"))
i += t(5)
END`
......
......@@ -4,12 +4,12 @@ dist=sid
arch="i386" # because amd64 doesnt exist in the 2005 snapshots
hostarch="mipsel" # because mipsel survived from 2005 to now
# but this choice is largely irrelevant because not the real mipsel packages are used
dates=`cat << END | python -c "import sys; exec sys.stdin.read()"
dates=`cat << END | python3 -c "import sys; exec(sys.stdin.read())"
from datetime import date, timedelta as t
last = date.today()
i = date(2005, 3, 12)
while (i <= last):
print i.strftime("%Y%m%d")
print(i.strftime("%Y%m%d"))
i += t(5)
END`
......