ocarina/html/library2.py

46 lines
1.2 KiB
Python

# Bryan Schumaker (12 / 26 / 2010)
import libsaria
library = libsaria.sources.library
walk = library.walk
get_attrs = library.get_attrs
cols = [("Title", 400), ("Length", 60), ("Artist", 200), ("Album", 200), ("Year", 50)]
def header(wfile):
wfile.write("<html><body>")
def footer(wfile):
wfile.write("</body></html>")
def content_header(wfile):
wfile.write("<table><tr>")
for col, width in cols:
wfile.write("<td style=\"width:%spx;\">%s</td>" % (width, col))
wfile.write("</tr></table>")
wfile.write("<hr>")
def body(wfile):
wfile.write("header stuff goes here")
content_header(wfile)
wfile.write("<div style=\"height:80%;width:100%;overflow:auto;\">")
wfile.write("<table>")
colors = ["white", "aliceblue"]
i = 0
for id in walk():
wfile.write("<tr>")
for index, attr in enumerate(get_attrs(id, "title", "lenstr", "artist", "album", "year")):
wfile.write("<td style=\"width:%spx;background:%s;\">%s</td>" % (cols[index][1], colors[i], attr))
wfile.write("</tr>")
if i == 0:
i = 1
else:
i = 0
wfile.write("</table></div>")
wfile.write("footer stuff goes here")
def to_html(wfile, args):
header(wfile)
body(wfile)
footer(wfile)