Mercurial > repos > bgruening > graphclust
annotate 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 |
rev | line source |
---|---|
0
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
2 import os |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
3 import sys |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
4 from xml.sax.saxutils import escape |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
5 |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
6 def make_table( directory ): |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
7 ret = ['<table class="fileList">\n'] |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
8 for root, dirs, files in os.walk( directory ): |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
9 root = root.rstrip('/') |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
10 ret.append(' <tr><td class="directory">%s</td></tr>\n' % escape( os.path.split(root)[-1] )) |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
11 for file in files: |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
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) )) |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
13 ret.append('</table>') |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
14 return ''.join(ret) |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
15 |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
16 def make_html( directory ): |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
17 return '\n'.join(['<html>' |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
18 '<head>', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
19 ' <title>Search results</title>', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
20 ' <style type="text/css">', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
21 ' table.fileList { text-align: left; }', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
22 ' td.directory { font-weight: bold; }', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
23 ' td.file { padding-left: 4em; }', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
24 ' </style>', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
25 '</head>', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
26 '<body>', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
27 '<h1>Search Results</h1>', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
28 make_table( directory ), |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
29 '</body>', |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
30 '</html>']) |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
31 |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
32 if __name__ == '__main__': |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
33 if len(sys.argv) == 2: |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
34 directory_path = sys.argv[1] |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
35 else: top = '.' |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
36 print make_html( directory_path ) |
a81b012ef352
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/graphclust commit 11e50007837b1efa01a3039c92df0ebf63f0f7e9
bgruening
parents:
diff
changeset
|
37 |