# -*- tab-width: 4 -*- # Copyright (c) 2009 Tim Freeman # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # (This is the standard MIT License, copied from # http://www.opensource.org/licenses/mit-license.php on 24 Apr 2007.) #desc Script for generating index.html. from sys import argv from os import stat from glob import glob import htmlgen canonical_url = htmlgen.code_url + "/index.html" canonical_zip = htmlgen.code_url + "/respect_code.zip" admin_files = [x for x in argv[1:] if x.endswith(".py")] unit_tests = [x for x in glob("*_test.py") if x not in admin_files] source_files = [x for x in glob("*.py") if x not in admin_files + unit_tests] def entry(x): if type(x) == int or type(x) == long: align = "right" else: align = "left" return "" + str(x) + "" def header_entry(x): return "" + str(x) + "" def row(entries, format_entry=entry): return "" + "".join(map(format_entry,entries)) + "\n" def bytes(name): return stat(name).st_size def lines(name): f = file(name) try: return len(list(f)) finally: f.close() description_prefix = "#desc " def description(name): f = file(name) try: result = [] for line in f: if line.startswith(description_prefix): result.append(line[len(description_prefix):]) return "".join(result) finally: f.close() def list_files(documentFormatter, file_list): d = documentFormatter total_bytes = 0 total_lines = 0 result = [""] result.append("" + "") file_list = file_list[:] file_list.sort() for name in file_list: b = bytes(name) total_bytes += b l = lines(name) total_lines += l result.append(row([d.coderef(name), b, l, description(name)])) if len(file_list) > 1: result.append(row(["total", total_bytes, total_lines, ""])) result.append("
NameBytesLinesDescription
") return "".join(result) title = "Source Code for Compassion and Respect" def documentGenerator(documentFormatter): d = documentFormatter return d.start(title, canonical_url, "top") \ + d.contents(documentGenerator) \ + d.h2("introduction", "Introduction") + """ This directory contains the source code for the decision procedure described in """ + d.urlref(htmlgen.paper_url, htmlgen.paper_title) + """. Since this is just a decision procedure, even on toy problems it will not terminate in the forseeable future if run on physically realizable computers. However, parts of the code can be separately tested, and in aggregate all of the unit tests listed below touch all lines of the code.

This file describes how to """+d.nameref("run", "run the regression tests")+\ """, and it provides an overview that makes it easy to """+d.nameref("individual-source","browse individual source files")+""" either from the web or after downloading the sources. """+d.h2("run","Running Tests")+""" The code was tested on a 600 MhZ Pentium system running GNU/Linux. It is written in Python, and tested against Python 2.3.5. Using GNU/Linux for testing ought to be inessential, but you will need Python, which can be downloaded from """+d.urlref("http://www.python.org")+""". To run the tests, do the following:

If you have problems with this, or you have observed it to work with a different version of Python or a different operating system, send me email at """+d.my_email()+""". """+d.h2("individual-source", "Individual Source Files")+""" We have three categories of Python source here:

"""\ + d.h3("code", "The Decision Procedure") \ + list_files(d, source_files) \ + d.h3("tests", "Unit Tests") + """ A file with a name like foo_test.py is almost always a test for foo.py.

"""+list_files(d, unit_tests) \ + d.h3("admin", "Administrative Files") \ + list_files(d, admin_files) \ + d.h2("other", "Other Files") + """ If you want to regenerate this document from source, or you want to repackage a variation on the source code, read the Makefile.

coverage.py.patch includes some workarounds for Python variable naming bugs that the coverage analyzer aggravates. These bugs exist in Python 2.3.5 and may not exist in newer versions. """ + d.end() print documentGenerator(htmlgen.RealDocument(sourceDirectory=".", sourceURL=""))