annotate dir2html.py @ 0:fe62ba547975 draft

Uploaded
author iuc
date Wed, 11 Feb 2015 10:18:02 -0500
parents
children 56e104999978
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fe62ba547975 Uploaded
iuc
parents:
diff changeset
1 #!/usr/bin/env python
fe62ba547975 Uploaded
iuc
parents:
diff changeset
2 import os
fe62ba547975 Uploaded
iuc
parents:
diff changeset
3 import sys
fe62ba547975 Uploaded
iuc
parents:
diff changeset
4 from xml.sax.saxutils import escape
fe62ba547975 Uploaded
iuc
parents:
diff changeset
5
fe62ba547975 Uploaded
iuc
parents:
diff changeset
6 def make_table( directory ):
fe62ba547975 Uploaded
iuc
parents:
diff changeset
7 ret = ['<table class="fileList">\n']
fe62ba547975 Uploaded
iuc
parents:
diff changeset
8 for file in os.listdir( directory ):
fe62ba547975 Uploaded
iuc
parents:
diff changeset
9 ret.append('<tr><td class="file"><a href="%s">%s</a></td></tr>\n' % ( file, escape(file).replace( 'MACS2_', '' ) ))
fe62ba547975 Uploaded
iuc
parents:
diff changeset
10 ret.append('</table>')
fe62ba547975 Uploaded
iuc
parents:
diff changeset
11 return ''.join(ret)
fe62ba547975 Uploaded
iuc
parents:
diff changeset
12
fe62ba547975 Uploaded
iuc
parents:
diff changeset
13 def make_html( directory, stderr ):
fe62ba547975 Uploaded
iuc
parents:
diff changeset
14 return '\n'.join(['<html>'
fe62ba547975 Uploaded
iuc
parents:
diff changeset
15 '<head>',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
16 ' <title>Additional output created by MACS2</title>',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
17 ' <style type="text/css">',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
18 ' table.fileList { text-align: left; }',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
19 ' td.directory { font-weight: bold; }',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
20 ' td.file { padding-left: 4em; }',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
21 ' </style>',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
22 '</head>',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
23 '<body>',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
24 '<h1>Additional Files:</h1>',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
25 make_table( directory ),
fe62ba547975 Uploaded
iuc
parents:
diff changeset
26 '<h3>Messages from MACS2:</h3>',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
27 stderr.read().replace('\n', '<br>'),
fe62ba547975 Uploaded
iuc
parents:
diff changeset
28 '</body>',
fe62ba547975 Uploaded
iuc
parents:
diff changeset
29 '</html>'])
fe62ba547975 Uploaded
iuc
parents:
diff changeset
30
fe62ba547975 Uploaded
iuc
parents:
diff changeset
31 if __name__ == '__main__':
fe62ba547975 Uploaded
iuc
parents:
diff changeset
32 if len(sys.argv) == 3:
fe62ba547975 Uploaded
iuc
parents:
diff changeset
33 directory_path = sys.argv[1]
fe62ba547975 Uploaded
iuc
parents:
diff changeset
34 stderr = open( sys.argv[2] )
fe62ba547975 Uploaded
iuc
parents:
diff changeset
35 print make_html( directory_path, stderr )
fe62ba547975 Uploaded
iuc
parents:
diff changeset
36 else:
fe62ba547975 Uploaded
iuc
parents:
diff changeset
37 sys.exit( 'Two parameter expected: directory path and stderr path' )
fe62ba547975 Uploaded
iuc
parents:
diff changeset
38