Mercurial > repos > bgruening > graphclust
comparison dir2html.py @ 0:a81b012ef352 draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
| author | bgruening |
|---|---|
| date | Thu, 22 Dec 2016 08:40:17 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a81b012ef352 |
|---|---|
| 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 root, dirs, files in os.walk( directory ): | |
| 9 root = root.rstrip('/') | |
| 10 ret.append(' <tr><td class="directory">%s</td></tr>\n' % escape( os.path.split(root)[-1] )) | |
| 11 for file in files: | |
| 12 ret.append(' <tr><td class="file"><a href="%s">%s</a></td></tr>\n' % ( os.path.join( os.path.split(root)[-1], file), escape(file) )) | |
| 13 ret.append('</table>') | |
| 14 return ''.join(ret) | |
| 15 | |
| 16 def make_html( directory ): | |
| 17 return '\n'.join(['<html>' | |
| 18 '<head>', | |
| 19 ' <title>Search results</title>', | |
| 20 ' <style type="text/css">', | |
| 21 ' table.fileList { text-align: left; }', | |
| 22 ' td.directory { font-weight: bold; }', | |
| 23 ' td.file { padding-left: 4em; }', | |
| 24 ' </style>', | |
| 25 '</head>', | |
| 26 '<body>', | |
| 27 '<h1>Search Results</h1>', | |
| 28 make_table( directory ), | |
| 29 '</body>', | |
| 30 '</html>']) | |
| 31 | |
| 32 if __name__ == '__main__': | |
| 33 if len(sys.argv) == 2: | |
| 34 directory_path = sys.argv[1] | |
| 35 else: top = '.' | |
| 36 print make_html( directory_path ) | |
| 37 |
