Added script and related configuration to browse all of CryptoNAS' Python code in one browser

window
This commit is contained in:
frisco 2011-07-05 07:35:31 +00:00
parent a75f40eac2
commit a26dca8068
4 changed files with 130 additions and 0 deletions

7
.htaccess Normal file
View File

@ -0,0 +1,7 @@
# Override server default MIME types so .py files get opened
# in developer's web browser.
# This is intended for use with the index in doc/browse-py,
# but you can disable it if it causes problems.
# See also: AddEncoding, ForceType
AddType text/plain .py

95
bin/gen_pyindex.py Executable file
View File

@ -0,0 +1,95 @@
#!/usr/bin/env python
#
# index_gen.py
# Laszlo Szathmary, 2011 (jabba.laci@gmail.com)
#
# Project's home page:
# https://pythonadventures.wordpress.com/2011/03/26/static-html-filelist-generator/
#
# Version: 0.1
# Date: 2011-03-26 (yyyy-mm-dd)
#
# This free software is copyleft licensed under the same terms as Python, or,
# at your option, under version 2 of the GPL license.
#
# James Crofts July 2011:
# Now under the GNU General Public License, version 2
#
# Modified to exclude hidden directories such as .svn, .git, etc.
# Added support for multiple directories as arguments
# Other modifications for use in CryptoNAS development
import os
import os.path
import sys
import re
ofile = None
class SimpleHtmlFilelistGenerator:
# start from this directory
base_dirs = None
exclude_re = None
def __init__(self, dirs):
self.base_dirs = dirs
# Ignore "hidden" filenames, .pyc files, and help and documentation locations
self.exclude_re = re.compile("(\..*)|(.*\.pyc)|(.*~)|(intl)|(help)")
def print_html_header(self):
ofile.write("""<html>
<body>
""",)
def print_html_footer(self):
ofile.write('<code>' + '\n')
home = 'https://pythonadventures.wordpress.com/2011/03/26/static-html-filelist-generator/'
name = 'Static HTML Filelist Generator'
ofile.write('</code>' + '\n')
href = "<a href=\"%s\">%s</a>" % (home, name)
ofile.write("<!--<p><i><sub>This page was generated with Jabba Laci's %s.</sub></p>" % href)
ofile.write("""-->
</body>
</html>
""",)
def processDirectory ( self, args, dirname, filenames):
#For each name in filenames, if it matches exclude_re, delete it from the list in-place
ofile.write('<strong>' + dirname + '/' + '</strong>' + '<br>' + '\n')
for filename in sorted(filenames):
if self.exclude_re.match(filename):
del filenames[filenames.index(filename)]
continue
rel_path = os.path.join(dirname, filename)
if rel_path in [sys.argv[0], './index.html']:
continue # exclude this generator script and the generated index.html
if os.path.isfile(rel_path):
href = "<a href=\"%s\" target=main>%s</a>" % (rel_path, filename)
ofile.write('&nbsp;' * 4 + href + '<br>' + '\n')
def start(self):
self.print_html_header()
for base_dir in self.base_dirs:
ofile.write('<code>' + '\n')
os.path.walk(base_dir, self.processDirectory, None )
ofile.write('</code>' + '\n')
ofile.write('<hr>' + '\n')
self.print_html_footer()
# class SimpleHtmlFilelistGenerator
if __name__ == "__main__":
#base_dirs = ['']
# Hard-coded directory names
base_dirs = ['src/cryptobox/', 'plugins']
# Support giving multiple directories as arguments
# if len(sys.argv) > 1:
# base_dirs = sys.argv[1:]
ofile = open('doc/browse-py/pyindex.html', 'w')
gen = SimpleHtmlFilelistGenerator(base_dirs)
gen.start()
print "If there were no errors, doc/browse-py/pyindex.html should now exist"
ofile.close()

7
doc/browse-py/index.html Normal file
View File

@ -0,0 +1,7 @@
<html>
<title>Browse CryptoNAS Python Source</title>
<frameset cols="20%,80%">
<frame src="../../pyindex.html" name=index />
<frame src="intro.html" name=main />
</frameset>
</html>

21
doc/browse-py/intro.html Normal file
View File

@ -0,0 +1,21 @@
<html>
<head>
<title>Browse all Python Source</title>
</head>
<body>
<p>If you're reading this for the first time, you probably need to generate pyindex.html
before this web page is useful. To do this, run
<code>bin/gen_pyindex.py</code> with no arguments.
<p>Use the index on the left to browse all the Python source files in CryptoNAS, including the
Unit
Tests. This offers convenient access to some files that pydoc does not.
<p>If you wish, run a webserver such that <code>trunk</code> is accessible. The included
<code>trunk/.htaccess</code>
file should cause the Python files to open in the same browser window when used with some web
servers; with others, you may have to reconfigure their MIME types manually. You may
have to reload your browser's cache before such MIME type reassignments take effect.
</body>
</html>