comparison make_html.py @ 0:581d217c7337 draft

Planemo upload
author lgueguen
date Fri, 22 Jul 2016 05:39:13 -0400
parents
children 05c9b1a7f44e
comparison
equal deleted inserted replaced
-1:000000000000 0:581d217c7337
1 #Author: Loraine Gueguen
2
3 import sys
4 import os
5 import time
6 import argparse
7
8 def getfSize(fpath,outpath):
9 """
10 format a nice file size string
11 """
12 size = ''
13 fp = os.path.join(outpath,fpath)
14 if os.path.isfile(fp):
15 size = '0 B'
16 n = float(os.path.getsize(fp))
17 if n > 2**20:
18 size = '%1.1f MB' % (n/2**20)
19 elif n > 2**10:
20 size = '%1.1f KB' % (n/2**10)
21 elif n > 0:
22 size = '%d B' % (int(n))
23 return size
24
25 # Define option
26 parser = argparse.ArgumentParser(description='Create an html page for downloading files from a directory')
27 parser.add_argument('--tool', help='Galaxy tool', required=True)
28 parser.add_argument('--output_type', help='figures or tables', required=True)
29 parser.add_argument('--output_dir', help='Output directory', required=True)
30 parser.add_argument('--output_html', help='Output HTML file name', default='', required=True)
31
32 #Parse the command line
33 args = parser.parse_args()
34 tool=args.tool
35 output_type=args.output_type
36 output_dir=args.output_dir
37 output_html=args.output_html
38
39
40 debut_html="""<!DOCTYPE html>
41 <html>
42 <head>
43 <meta charset="utf-8" />
44 <title></title>
45 </head>
46 <body>
47 <h1>Galaxy Tool %s</h1>
48 """ %(tool)
49
50 fin_html="</body></html>"
51
52 html=debut_html
53 run_date=time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
54 html+='<div>Run at %s</div><br/>\n'%run_date
55 html+='<div><strong>%s</strong> available for downloading</div><br/>\n'%output_type
56
57
58 flist = os.listdir(output_dir)
59 flist.sort()
60
61
62 html+='<div><table cellpadding="3" cellspacing="3"><tr><th>Output File Name (click to view)</th><th>Size</th></tr>\n'
63
64 for f in flist :
65 size=getfSize(f,output_dir)
66 html+='<tr><td><a href="%s">%s</a></td><td>%s</td></tr>\n'%(f,f,size)
67 html+='</table></div><br/>\n'
68
69 html+=fin_html
70
71 htmlf = file(output_html,'w')
72 htmlf.write(html)
73 htmlf.close()