Author: gbrandl Date: 2007-05-22 17:33:45 +0200 (Tue, 22 May 2007) New Revision: 5091 Modified: trunk/sandbox/py-rest-doc/sphinx-web.py trunk/sandbox/py-rest-doc/sphinx/builder.py trunk/sandbox/py-rest-doc/sphinx/environment.py trunk/sandbox/py-rest-doc/sphinx/templates/layout.html trunk/sandbox/py-rest-doc/sphinx/templates/not_found.html trunk/sandbox/py-rest-doc/sphinx/web/application.py Log: Some adjustments. Modified: trunk/sandbox/py-rest-doc/sphinx/builder.py =================================================================== --- trunk/sandbox/py-rest-doc/sphinx/builder.py 2007-05-22 14:34:40 UTC (rev 5090) +++ trunk/sandbox/py-rest-doc/sphinx/builder.py 2007-05-22 15:33:45 UTC (rev 5091) @@ -137,9 +137,8 @@ """Build all source files.""" self.options.freshenv = True self.load_env() - self.msg('build summary:', nonl=1) - self.msg('Building all source files.', nobold=1) - self.build(self.all_source_files, self.all_source_files) + self.build(self.all_source_files, self.all_source_files, + summary='all source files') def build_specific(self, source_filenames): """Only rebuild as much as needed for changes in the source_filenames.""" @@ -153,10 +152,8 @@ to_read = self.all_source_files else: to_read = to_write - self.msg('build summary:', nonl=1) - self.msg('Building %d source files given on command line.' % - len(to_read), nobold=1) - self.build(to_read, to_write) + self.build(to_read, to_write, + summary='%d source files given on command line' % len(to_read)) def build_update(self): """Only rebuild files changed or added since last build.""" @@ -173,17 +170,19 @@ if mtime > self.env.mtimes[filename]: to_build.append(filename) if not to_build: - self.msg('no out of date files found, exiting.') + self.msg('no files are out of date, exiting.') return - self.msg('build summary:', nonl=1) - self.msg('Building %d source files that are out of date.' % - len(to_build), nobold=1) - self.build(to_build, to_build) + self.build(to_build, to_build, + summary='%d source files that are out of date' % len(to_build)) - def build(self, to_read, to_write): + def build(self, to_read, to_write, summary=None): assert self.env self.doctrees = {} + if summary: + self.msg('building [%s]:' % self.name, nonl=1) + self.msg(summary, nobold=1) + # read -- collect all warnings from docutils stream = StringIO.StringIO() self.env.set_warning_stream(stream) @@ -246,6 +245,7 @@ """ Builds standalone HTML docs. """ + name = 'html' option_spec = Builder.option_spec option_spec.update({ @@ -343,6 +343,7 @@ next = next, sourcename = sourcename, last_updated = self.last_updated, + builder = self.name, ) self.handle_file(filename, context) @@ -364,7 +365,7 @@ key=lambda x: x[0].lower())) # use pseudo name 'special.rst' because all of them are at top level - # XXX: wrong for index + # XXX: wrong for index? parents = [{'link': self.get_relative_uri('special.rst', 'index.rst'), 'title': 'Python Documentation'}] @@ -376,6 +377,7 @@ modindexentries = modules, parents = parents, len = len, + builder = self.name, ) self.handle_specials(specialcontext) @@ -455,6 +457,8 @@ """ Builds HTML docs usable with the web-based doc server. """ + name = 'web' + # doesn't use the standalone specific options option_spec = Builder.option_spec option_spec.update({ Modified: trunk/sandbox/py-rest-doc/sphinx/environment.py =================================================================== --- trunk/sandbox/py-rest-doc/sphinx/environment.py 2007-05-22 14:34:40 UTC (rev 5090) +++ trunk/sandbox/py-rest-doc/sphinx/environment.py 2007-05-22 15:33:45 UTC (rev 5091) @@ -468,7 +468,7 @@ for title, (fn, desc, _) in self.modules.iteritems(): yield ('module', fn, title, desc) for title, (fn, _) in self.descrefs.iteritems(): - yield ('ref', fn, title, '') + yield (_, fn, title, '') result = [] for type, filename, title, desc in possibilities(): Modified: trunk/sandbox/py-rest-doc/sphinx/templates/layout.html =================================================================== --- trunk/sandbox/py-rest-doc/sphinx/templates/layout.html 2007-05-22 14:34:40 UTC (rev 5090) +++ trunk/sandbox/py-rest-doc/sphinx/templates/layout.html 2007-05-22 15:33:45 UTC (rev 5091) @@ -66,13 +66,19 @@ XXX: Add links to old docs/essays/etc. here. </p> {% endif %} - {% if current_page_name != "search" %} - <h3 style="margin-top: 10px">Quicksearch</h3> + {% if builder == "html" and current_page_name != "search" %} + <h3 style="margin-top: 10px">Quick search</h3> <form class="search" action="{{ pathto('search.rst') }}" method="get"> <input type="text" name="q"> <input type="hidden" name="area" value="default"> </form> {% endif %} + {% if builder == 'web' %} + <h3 style="margin-top: 10px">Keyword search</h3> + <form class="search" action"{{ pathto('index.rst') }}" method="get"> + <input type="text" name="q"> + </form> + {% endif %} </div> </div> <div class="clearer"></div> Modified: trunk/sandbox/py-rest-doc/sphinx/templates/not_found.html =================================================================== --- trunk/sandbox/py-rest-doc/sphinx/templates/not_found.html 2007-05-22 14:34:40 UTC (rev 5090) +++ trunk/sandbox/py-rest-doc/sphinx/templates/not_found.html 2007-05-22 15:33:45 UTC (rev 5091) @@ -3,15 +3,14 @@ {% block body %} <h1 id="page-not-found">Keyword Not Found</h1> <p> - Sorry, but the keyword <strong>{{ keyword|e }}</strong> is - not associated with a page. {% if close_matches %}A similarity search - returned {{ close_matches|length }} items that are possible matches: - {% endif %} + The keyword <strong>{{ keyword|e }}</strong> is not directly associated with + a page. {% if close_matches %}A similarity search returned {{ + close_matches|length }} items that are possible matches: {% endif %} </p> {% if close_matches %} <ul> {% for item in close_matches %} - <li><a href="{{ item.href }}">{{ item.title|e }}</a>{% if item.description + <li><a href="{{ item.href }}">{{ item.title|e }}</a> ({{ item.type }}) {% if item.description %} — {{ item.description|e }}{% endif %}</li> {% endfor %} </ul> Modified: trunk/sandbox/py-rest-doc/sphinx/web/application.py =================================================================== --- trunk/sandbox/py-rest-doc/sphinx/web/application.py 2007-05-22 14:34:40 UTC (rev 5090) +++ trunk/sandbox/py-rest-doc/sphinx/web/application.py 2007-05-22 15:33:45 UTC (rev 5091) @@ -97,11 +97,21 @@ self.cache[url] = (filename, path.getmtime(filename), text) return Response(text) - def get_close_matches(self, req, url): + pretty_type = { + 'data': 'module data', + 'cfunction': 'C function', + 'cmember': 'C member', + 'cmacro': 'C macro', + 'ctype': 'C type', + 'cvar': 'C variable', + } + + def get_keyword_matches(self, req, url): """ - Find close matches. If there is an exact match (for example + Find keyword matches. If there is an exact match, just redirect: http://docs.python.org/os.path.exists would automatically redirect to http://docs.python.org/modules/os.path/#os.path.exists. + Else, show a page with close matches. Module references are processed first so that "os.path" is handled as a module and not as member of os. @@ -125,7 +135,7 @@ close_matches.append({ 'href': relative_uri(url + '/', link), 'title': title, - 'type': type, + 'type': self.pretty_type.get(type, type), 'description': desc }) return Response(render_template(req, 'not_found.html', { @@ -147,11 +157,13 @@ url = req.path.strip('/') or 'index' if url == 'search': resp = self.search(req) + elif url == 'index' and req.args.get('q', ''): + resp = self.get_keyword_matches(req, req.args['q']) else: try: resp = self.get_page(req, url) except NotFound: - resp = self.get_close_matches(req, url) + resp = self.get_keyword_matches(req, url) return resp(environ, start_response) Modified: trunk/sandbox/py-rest-doc/sphinx-web.py =================================================================== --- trunk/sandbox/py-rest-doc/sphinx-web.py 2007-05-22 14:34:40 UTC (rev 5090) +++ trunk/sandbox/py-rest-doc/sphinx-web.py 2007-05-22 15:33:45 UTC (rev 5091) @@ -7,22 +7,27 @@ :license: Python license. """ import sys +import getopt from wsgiref.simple_server import make_server + from sphinx.web.application import make_app -if __name__ == '__main__': - if len(sys.argv) != 2: - print 'usage: %s <doc_root>' % sys.argv[0] - sys.exit(-1) - app = make_app({'data_root_path': sys.argv[1]}) +def main(argv): + opts, args = getopt.getopt(argv[1:], "dh") + opts = dict(opts) + if len(args) != 1 or '-h' in opts: + print 'usage: %s [-d] <doc_root>' % argv[0] + print ' -d: use werkzeug debugger if installed' + return 2 + app = make_app({'data_root_path': args[0]}) - #XXX: make this configurable - try: - from werkzeug.debug import DebuggedApplication - except ImportError: - pass - else: - app = DebuggedApplication(app, True) + if '-d' in opts: + try: + from werkzeug.debug import DebuggedApplication + except ImportError: + pass + else: + app = DebuggedApplication(app, True) srv = make_server('localhost', 3000, app) try: @@ -30,3 +35,8 @@ srv.serve_forever() except KeyboardInterrupt: pass + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + |