#!/usr/bin/python
import commands
import re
import os
import sys
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-d", "--dir", dest="rep", help ="Picture folder (ending with /)")
parser.add_option("-r", action="store_true", dest="recursive", help ="recursive mode")
(options, args) = parser.parse_args()
rep = options.rep
recursive= options.recursive
topahtml="""
"""
topbhtml="""
"""
middleahtml="""
"""
bottomhtml="""
"""
def main():
try:
global directorypath
directorypath=rep
if(recursive):
rec="";
else:
rec=" -maxdepth 0";
theindex=open(directorypath+"index.html","w")
print "index.html created in "+directorypath
theindex.write(topahtml)
theindex.write(directorypath)
theindex.write(topbhtml)
theindex.write("
Plots in "+directorypath+"
")
theindex.write(middleahtml)
myoutls=commands.getoutput("find "+directorypath+rec+" -type d -print").split("\n")
for i in sorted(myoutls):
#print i
#tmp=commands.getoutput("ls "+i+"/*.png "+i+"/*.[jJ][pP][gG] "+i+"/*.gif" ).split("\n")
tmp=commands.getoutput("ls "+i+"/*.png" ).split("\n")
tmpsize=len(tmp)
#print tmp
if((tmp[0].find("No such file or directory"))==-1):
for ii in range(0,tmpsize):
# theindex.write("
"
theindex.write(middlebhtml);
for i in sorted(myoutls):
tmp=commands.getoutput("ls "+i+"/*.png" ).split("\n")
tmpsize=len(tmp)
#print tmp
if((tmp[0].find("No such file or directory"))==-1):
for j in range(0,tmpsize):
hrefbase="./"
theindex.write("\n")
theindex.write(bottomhtml)
theindex.close()
except:
parser.print_help()
# if (len(sys.argv) < 2):
# print "Error"
# parser.error("vous devez donner 1 argument \n aide avec -h ou --help")
if __name__ == '__main__':
main()