[Checkins] SVN: grok/trunk/doc/ remove old documentation tools.

Jan-Wijbrand Kolman janwijbrand at gmail.com
Thu May 1 06:23:28 EDT 2008


Log message for revision 85972:
  remove old documentation tools.

Changed:
  D   grok/trunk/doc/grok2html.py
  D   grok/trunk/doc/grok2pdf.sh
  D   grok/trunk/doc/pygments_code_block_directive.py
  D   grok/trunk/doc/setup.py

-=-
Deleted: grok/trunk/doc/grok2html.py
===================================================================
--- grok/trunk/doc/grok2html.py	2008-05-01 10:22:57 UTC (rev 85971)
+++ grok/trunk/doc/grok2html.py	2008-05-01 10:23:27 UTC (rev 85972)
@@ -1,198 +0,0 @@
-import os
-import codecs
-import sys
-import urllib
-
-import docutils.core
-from docutils.writers.html4css1 import Writer
-
-from zope.app.renderer.rest import ZopeTranslator
-from zope.pagetemplate.pagetemplate import PageTemplate
-from zope.pagetemplate.pagetemplatefile import PageTemplateFile
-
-# registers code-block directive using pygments.
-import pygments_code_block_directive
-
-class ReStructuredTextToHTMLRenderer:
-    """Convert from Restructured Text to HTML."""
-
-    def __init__(self,content):
-        self.content = content
-
-    def render(self):
-        settings_overrides = {
-            'halt_level': 6,
-            'input_encoding': 'utf8',
-            'output_encoding': 'utf8',
-            'initial_header_level': 2,
-            # don't try to include the stylesheet (docutils gets hiccups)
-            'stylesheet_path': '',
-        }
-
-        writer = Writer()
-        writer.translator_class = ZopeTranslator
-        html = docutils.core.publish_string(
-                        self.content,
-                        writer=writer,
-                        settings_overrides=settings_overrides,)
-        html = codecs.decode(html, 'utf_8')
-        return html
-
-class RestFile(object):
-
-    source = ''
-    target = ''
-    url = ''
-    title = ''
-    active = True
-
-    def __init__(self, url, source, target):
-        self.url = url
-        self.target = target
-        if os.path.isfile(target) and os.path.isfile(source):
-            if os.path.getmtime(source) < os.path.getmtime(target):
-                self.active = False
-        if os.path.isfile(source):
-            self.source = codecs.open(source,"r",'utf8').read()
-        elif source.startswith("http"):
-            print "Downloading %s" % source
-            try:
-                response = urllib.urlopen(source)
-                self.source = response.read()
-            except IOError, e:
-                if hasattr(e, 'reason'):
-                    print 'We failed to reach a server.'
-                    print 'Reason: ', e.reason
-                elif hasattr(e, 'code'):
-                    print 'The server couldn\'t fulfill the request.'
-                    print 'Error code:', e.code
-                self.source = u''
-        else:
-            self.source = source
-        srctxt = self.source.split('\n')
-        title = ''
-        count = 0
-        while title == '':
-            title = srctxt[count]
-            count += 1
-            if title.startswith("=====") or title.startswith(".."):
-                title = srctxt[count]
-        self.title = title
-
-    def set_rest_content(self):
-        renderer = ReStructuredTextToHTMLRenderer(self.source)
-        self.content = renderer.render().strip()
-
-    def create_html(self, page, settings):
-        if not self.active:
-            pass
-        print 'Processing ', self.url
-        self.set_rest_content()
-
-        settings["context"] = Context(self.url, self.title, self.content)
-        content = page.pt_render(namespace=settings)
-        #fp = open(self.target, 'w')
-        targetdir = os.path.dirname(self.target)
-        if not os.path.isdir(targetdir):
-            print 'Creating dir: ', targetdir
-            os.mkdir(targetdir)
-        fp = codecs.open(self.target,"w",'utf8')
-        fp.write(content)
-        fp.close()
-
-class Context:
-    """Set up the context for rendering the rest as html through zpt"""
-
-    def __init__(self, url, title=u'', content=u''):
-        self.url = url
-        self.title = title
-        self.content = content
-
-    @property
-    def menu(self):
-        for item in Menu:
-            if item.get('href') == self.url:
-                item['klass'] = u'selected'
-            else:
-                item['klass'] = u''
-            # just for tutorial files
-            if len(self.url.split('/')) > 2:
-                if item.get('href').split('/')[:-1] == self.url.split('/')[:-1]:
-                    item['klass'] = u'selected'
-            if not item.get('description', None):
-                item['description'] = item['title']
-        return Menu
-
-def create_html(rest_files, template):
-    settings = {}
-    settings["here"] = { "layout": template }
-    page = PageTemplate()
-    page.write("""<metal:block use-macro="here/layout/macros/pagelayout" />""")
-
-    for restfile in rest_files:
-        restfile.create_html(page, settings)
-
-# Menu should later be generated if site becomes more complex
-Menu = [
-        {'href':'/index.html','title':u'Home','klass':''},
-        {'href':'/about.html','title':u'About','klass':''},
-        {'href':'/tutorial.html','title':u'Tutorial','klass':''},
-        {'href':'/minitutorials/index.html','title':u'How Tos','klass':''},
-        ]
-
-def main(argv=None):
-    if argv is None:
-        argv = sys.argv[1:]
-
-    if not len(argv) == 1:
-        print "Usage: grok2html OUTDIR"
-        sys.exit(1)
-
-    source_dir = os.path.dirname(__file__)
-    www_dir = os.path.abspath(argv[0])
-
-    if not os.path.isdir(www_dir):
-        print "OUTDIR '%s' does not exist." % (www_dir,)
-        sys.exit(1)
-
-    os.chdir(source_dir)
-
-    rest_files = []
-    # Toplevel pages:
-    for name in [
-        'about',
-        'index',
-        'tutorial',
-        'upgrade'
-        ]:
-        rest_files.append(
-            RestFile(
-                name, os.path.join(source_dir, name+'.txt'),
-            os.path.join(www_dir, name+'.html')))
-    # The minitutorials:
-    for name in [
-        'index',
-        'macros',
-        'permissions',
-        'rest',
-        'searching',
-        'template-languages',
-        'transient-objects',
-        'xmlprc',
-        ]:
-        rest_files.append(
-            RestFile(
-                name, os.path.join(source_dir, 'minitutorials', name+'.txt'),
-            os.path.join(www_dir, 'minitutorials', name+'.html')))
-    # External sources:
-    rest_files.append(
-        RestFile(
-            'zc.buildout',
-            'http://svn.zope.org/*checkout*/zc.buildout/trunk/doc/tutorial.txt',
-            os.path.join(www_dir, 'minitutorials', 'buildout.html')))
-
-    template = PageTemplateFile(os.path.join(source_dir, 'template.pt'))
-    create_html(rest_files, template)
-
-if __name__ == '__main__':
-    main()

Deleted: grok/trunk/doc/grok2pdf.sh
===================================================================
--- grok/trunk/doc/grok2pdf.sh	2008-05-01 10:22:57 UTC (rev 85971)
+++ grok/trunk/doc/grok2pdf.sh	2008-05-01 10:23:27 UTC (rev 85972)
@@ -1,5 +0,0 @@
-#!/bin/sh
-rst2latex.py --use-latex-toc --stylesheet=style.tex tutorial.txt > tutorial.tex
-pdflatex tutorial.tex
-# run pdflatex a second time for contents
-pdflatex tutorial.tex

Deleted: grok/trunk/doc/pygments_code_block_directive.py
===================================================================
--- grok/trunk/doc/pygments_code_block_directive.py	2008-05-01 10:22:57 UTC (rev 85971)
+++ grok/trunk/doc/pygments_code_block_directive.py	2008-05-01 10:23:27 UTC (rev 85972)
@@ -1,177 +0,0 @@
-#!/usr/bin/python
-
-# :Author: a Pygments author|contributor; Felix Wiemann; Guenter Milde
-# :Date: $Date: 2007-06-13 22:20:42 +1200 (Wed, 13 Jun 2007) $
-# :Copyright: This module has been placed in the public domain.
-# 
-# This is a merge of `Using Pygments in ReST documents`_ from the pygments_
-# documentation, and a `proof of concept`_ by Felix Wiemann.
-# 
-# ========== ===========================================================
-# 2007-06-01 Removed redundancy from class values.
-# 2007-06-04 Merge of successive tokens of same type
-#            (code taken from pygments.formatters.others).
-# 2007-06-05 Separate docutils formatter script
-#            Use pygments' CSS class names (like the html formatter)
-#            allowing the use of pygments-produced style sheets.
-# 2007-06-07 Merge in the formatting of the parsed tokens
-#            (misnamed as docutils_formatter) as class DocutilsInterface
-# 2007-06-08 Failsave implementation (fallback to a standard literal block 
-#            if pygments not found)
-# ========== ===========================================================
-# 
-# ::
-
-"""Define and register a code-block directive using pygments
-"""
-
-# Requirements
-# ------------
-# ::
-
-from docutils import nodes
-from docutils.parsers.rst import directives
-try:
-    import pygments
-    from pygments.lexers import get_lexer_by_name
-    from pygments.formatters.html import _get_ttype_class
-except ImportError:
-    pass
-
-
-# Customisation
-# -------------
-# 
-# Do not insert inline nodes for the following tokens.
-# (You could add e.g. Token.Punctuation like ``['', 'p']``.) ::
-
-unstyled_tokens = ['']
-
-# DocutilsInterface
-# -----------------
-# 
-# This interface class combines code from
-# pygments.formatters.html and pygments.formatters.others.
-# 
-# It does not require anything of docutils and could also become a part of
-# pygments::
-
-class DocutilsInterface(object):
-    """Parse `code` string and yield "classified" tokens.
-    
-    Arguments
-    
-      code     -- string of source code to parse
-      language -- formal language the code is written in.
-    
-    Merge subsequent tokens of the same token-type. 
-    
-    Yields the tokens as ``(ttype_class, value)`` tuples, 
-    where ttype_class is taken from pygments.token.STANDARD_TYPES and 
-    corresponds to the class argument used in pygments html output.
-
-    """
-
-    def __init__(self, code, language):
-        self.code = code
-        self.language = language
-        
-    def lex(self):
-        # Get lexer for language (use text as fallback)
-        try:
-            lexer = get_lexer_by_name(self.language)
-        except ValueError:
-            # info: "no pygments lexer for %s, using 'text'"%self.language
-            lexer = get_lexer_by_name('text')
-        return pygments.lex(self.code, lexer)
-        
-            
-    def join(self, tokens):
-        """join subsequent tokens of same token-type
-        """
-        tokens = iter(tokens)
-        (lasttype, lastval) = tokens.next()
-        for ttype, value in tokens:
-            if ttype is lasttype:
-                lastval += value
-            else:
-                yield(lasttype, lastval)
-                (lasttype, lastval) = (ttype, value)
-        yield(lasttype, lastval)
-
-    def __iter__(self):
-        """parse code string and yield "clasified" tokens
-        """
-        try:
-            tokens = self.lex()
-        except IOError:
-            print "INFO: Pygments lexer not found, using fallback"
-            # TODO: write message to INFO 
-            yield ('', self.code)
-            return
-
-        for ttype, value in self.join(tokens):
-            yield (_get_ttype_class(ttype), value)
-
-
-
-# code_block_directive
-# --------------------
-# ::
-
-def code_block_directive(name, arguments, options, content, lineno,
-                       content_offset, block_text, state, state_machine):
-    """parse and classify content of a code_block
-    """
-    language = arguments[0]
-    # create a literal block element and set class argument
-    code_block = nodes.literal_block(classes=["code-block", language])
-    
-    # parse content with pygments and add to code_block element
-    for cls, value in DocutilsInterface(u'\n'.join(content), language):
-        if cls in unstyled_tokens:
-            # insert as Text to decrease the verbosity of the output.
-            code_block += nodes.Text(value, value)
-        else:
-            code_block += nodes.inline(value, value, classes=[cls])
-
-    return [code_block]
-
-
-# Register Directive
-# ------------------
-# ::
-
-code_block_directive.arguments = (1, 0, 1)
-code_block_directive.content = 1
-directives.register_directive('code-block', code_block_directive)
-
-# .. _doctutils: http://docutils.sf.net/
-# .. _pygments: http://pygments.org/
-# .. _Using Pygments in ReST documents: http://pygments.org/docs/rstdirective/
-# .. _proof of concept:
-#      http://article.gmane.org/gmane.text.docutils.user/3689
-# 
-# Test output
-# -----------
-# 
-# If called from the command line, call the docutils publisher to render the
-# input::
-
-if __name__ == '__main__':
-    from docutils.core import publish_cmdline, default_description
-    description = "code-block directive test output" + default_description
-    try:
-        import locale
-        locale.setlocale(locale.LC_ALL, '')
-    except:
-        pass
-    # Uncomment the desired output format:
-    publish_cmdline(writer_name='pseudoxml', description=description)
-    # publish_cmdline(writer_name='xml', description=description)
-    # publish_cmdline(writer_name='html', description=description)
-    # publish_cmdline(writer_name='latex', description=description)
-    # publish_cmdline(writer_name='newlatex2e', description=description)
-    
-
-

Deleted: grok/trunk/doc/setup.py
===================================================================
--- grok/trunk/doc/setup.py	2008-05-01 10:22:57 UTC (rev 85971)
+++ grok/trunk/doc/setup.py	2008-05-01 10:23:27 UTC (rev 85972)
@@ -1,15 +0,0 @@
-from setuptools import setup, find_packages
-
-setup(
-    name='grokdocs',
-    install_requires=['docutils',
-                      'zope.pagetemplate',
-                      'zope.app.renderer',
-                      'Pygments'
-                      ],
-    py_modules = ['grok2html'],
-    entry_points="""
-    [console_scripts]
-    grok2html = grok2html:main
-    """
-    )



More information about the Checkins mailing list