#!/usr/bin/python
import os, sys
# Untar tarball, start writing index file
name=sys.argv[1]
if not os.access(name,0) or not os.access("%s-thumbs.tbz" % name,0):
print "can't find %s or %s-thumbs.tbz" % (name,name)
sys.exit(1)
os.system("tar xvjfC %s-thumbs.tbz sub" % name)
out=open("%s/outdex.html" % name,"w")
counter=0
out.write("\n
put name here\n\n\n\n\n")
# Get properly sorted directory list
def find(newlist,list,name,nicename):
for i in xrange(len(list)):
if list[i].split(".")[0].split("-")[0]==name:
newlist.append([list[i],nicename])
del list[i]
return
def prettypagename(a):
a=a[4:].split(".")[0]
if len(a.split("-"))==2: return "Pages %s" % a
return "Page %s" % a
def pagelist(list):
pages=filter(lambda a: a.startswith("page"),list)
sortlist=map(lambda a: [int(a[4:].split(".")[0].split("-")[0]),a],pages)
sortlist.sort()
return map(lambda a: [a[1],prettypagename(a[1])],sortlist)
namelist=os.listdir("sub")
newnamelist=[]
find(newnamelist,namelist,"cover","Front Cover")
find(newnamelist,namelist,"incover","Front Inside")
find(newnamelist,namelist,"contents","Contents")
newnamelist.extend(pagelist(namelist))
namelist=filter(lambda a: not a.startswith("page"),namelist)
namelist=filter(lambda a: not a=="index.html",namelist)
find(newnamelist,namelist,"inback","Back Inside")
find(newnamelist,namelist,"back","Back Cover")
find(newnamelist,namelist,"spine","Spine")
newnamelist.extend(map(lambda a: [a,a], namelist))
# Iterate through directory list moving thumbnails and writing index entries.
for i in newnamelist:
os.rename("sub/%s" % i[0],"%s/thumb.%s" % (name,i[0]))
if counter and not counter%8: out.write("
\n")
counter=counter+1
out.write(" %s
| \n" % (i[0],i[0],i[1]))
out.write("
\n\n\n")