[Python-checkins] r62283 - sandbox/trunk/seealso/make-seealso.py sandbox/trunk/seealso/parse-seealso.py sandbox/trunk/seealso/pyspecific.py
andrew.kuchling
python-checkins at python.org
Fri Apr 11 01:56:34 CEST 2008
Author: andrew.kuchling
Date: Fri Apr 11 01:56:33 2008
New Revision: 62283
Added:
sandbox/trunk/seealso/pyspecific.py
Removed:
sandbox/trunk/seealso/make-seealso.py
Modified:
sandbox/trunk/seealso/parse-seealso.py
Log:
Remove make-seealso script (no need to write TeX files any more).
parse-seealso: record info in a more obvious order.
Add draft of :seealsolinks: directive.
Deleted: /sandbox/trunk/seealso/make-seealso.py
==============================================================================
--- /sandbox/trunk/seealso/make-seealso.py Fri Apr 11 01:56:33 2008
+++ (empty file)
@@ -1,73 +0,0 @@
-#!/usr/bin/env python
-
-# Read a pickled dictionary, and output a bunch of *.tex files
-# into the specified directory.
-
-import os, sys
-import pickle
-
-def main ():
- if len(sys.argv) < 3:
- print 'Usage: %s database-filename example-dir' % sys.argv[0]
- sys.exit(1)
-
- db_file = sys.argv[1]
- example_dir = sys.argv[2]
-
- # Delete all *.tex files
- for fn in os.listdir(example_dir):
- if fn.endswith('.tex'):
- p = os.path.join(example_dir, fn)
- os.remove(p)
-
- # Read dictionary
- input = open(db_file, 'rb')
- db = pickle.load(input)
- input.close()
-
- # Output files
- for module in db:
- examples = db[module]
-
- # XXX sort examples in some way?
-
- def tex_escape (t):
- t = t.replace('%', '\%')
- t = t.replace('$', '\$')
- return t
-
- # Write file containing examples for this module
- p = os.path.join(example_dir, module + '.tex')
- output = open(p, 'w')
- for (url, document_title, document_url,
- author, title, excerpt) in examples:
-
- attribution = ""
- if document_title:
- attribution += ' from "%s"' % tex_escape(document_title)
- if document_url:
- attribution += ' (\url{%s})' % (tex_escape(document_url))
- if author:
- attribution += " by %s" % (tex_escape(author))
-
- if attribution:
- attribution = ',' + attribution
-
- if excerpt is None:
- output.write("\seeurl{%s}{%s%s.}\n" % (tex_escape(url),
- tex_escape(title),
- attribution,
- ))
- else:
- output.write("\seeurl{%s}{%s%s.\n\n%s}\n" % (tex_escape(url),
- tex_escape(title),
- attribution,
- tex_escape(excerpt)))
-
-
- output.close()
-
-
-if __name__ == '__main__':
- main()
-
Modified: sandbox/trunk/seealso/parse-seealso.py
==============================================================================
--- sandbox/trunk/seealso/parse-seealso.py (original)
+++ sandbox/trunk/seealso/parse-seealso.py Fri Apr 11 01:56:33 2008
@@ -72,10 +72,8 @@
target_nodes = item.getElementsByTagNameNS(None, 'target')
for t in target_nodes:
target = get_text(t)
- L.append((target, href, document_title, document_url, author,
- title, excerpt))
-
-
+ L.append((target, href, title, document_url, document_title,
+ author, excerpt))
# update database
@@ -87,6 +85,7 @@
input = open(db_file, 'rb')
db = pickle.load(input)
input.close()
+
for entry in L:
# Check if URL is already listed; if yes, delete the old entry
module = entry[0]
Added: sandbox/trunk/seealso/pyspecific.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/seealso/pyspecific.py Fri Apr 11 01:56:33 2008
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+"""
+ pyspecific.py
+ ~~~~~~~~~~~~~
+
+ Sphinx extension with Python doc-specific markup.
+
+ :copyright: 2008 by Georg Brandl.
+ :license: Python license.
+"""
+
+ISSUE_URI = 'http://bugs.python.org/issue%s'
+
+from docutils import nodes, utils
+
+def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
+ issue = utils.unescape(text)
+ text = 'issue ' + issue
+ refnode = nodes.reference(text, text, refuri=ISSUE_URI % issue)
+ return [refnode], []
+
+import pickle
+seealso_dict = None
+
+def seealsolinks_role(typ, rawtext, text, lineno, inliner,
+ options={}, content=[]):
+ global seealso_dict
+
+ if seealso_dict is None:
+ f = open('/tmp/db', 'rb')
+ seealso_dict = pickle.load(f)
+ f.close()
+
+ module_name = utils.unescape(text)
+
+ # Nothing to add
+ if module_name not in seealso_dict:
+ return [], []
+
+ links = []
+ for (url, title, document_url, document_title,
+ author, excerpt) in seealso_dict[module_name] + seealso_dict['exceptions']:
+ page_link = nodes.reference(title, title, refuri=url)
+ node = nodes.paragraph()
+ node += page_link
+ if document_url:
+ msg = ' in '
+ node += nodes.Text(msg, msg)
+ document_link = nodes.reference(document_title,
+ document_title,
+ refuri=document_url)
+ node += document_link
+
+ if author:
+ msg = ' by ' + author
+ node += nodes.Text(msg, msg)
+
+ node += nodes.Text('.', '.')
+ links.append(node)
+
+ return links, []
+
+def setup(app):
+ app.add_role('issue', issue_role)
+ app.add_role('seealsolinks', seealsolinks_role)
More information about the Python-checkins
mailing list