annotate dir2html.py @ 5:beb902da6e5f draft

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