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