[Checkins] SVN: stxutils/ Collect some tools for processing STX.
Tres Seaver
tseaver at palladion.com
Mon Feb 9 18:08:11 EST 2009
Log message for revision 96349:
Collect some tools for processing STX.
Changed:
A stxutils/
A stxutils/CHANGES.txt
A stxutils/README.txt
A stxutils/setup.py
A stxutils/stxutils/
A stxutils/stxutils/__init__.py
A stxutils/stxutils/tohtml.py
-=-
Added: stxutils/CHANGES.txt
===================================================================
--- stxutils/CHANGES.txt (rev 0)
+++ stxutils/CHANGES.txt 2009-02-09 23:08:10 UTC (rev 96349)
@@ -0,0 +1,7 @@
+stxutils Changelog
+==================
+
+Unreleased
+----------
+
+- Initial pass.
Added: stxutils/README.txt
===================================================================
--- stxutils/README.txt (rev 0)
+++ stxutils/README.txt 2009-02-09 23:08:10 UTC (rev 96349)
@@ -0,0 +1,8 @@
+stxutils Readme
+===============
+
+This package supplies a utilities for manipulating Zope's "structured text"
+format:
+
+- The ``stx2html`` command-line script converts structured text to HTML.
+
Added: stxutils/setup.py
===================================================================
--- stxutils/setup.py (rev 0)
+++ stxutils/setup.py 2009-02-09 23:08:10 UTC (rev 96349)
@@ -0,0 +1,20 @@
+from setuptools import setup
+
+
+setup(name='stxutils',
+ version='0.1dev',
+ description='StructuredText utilities',
+ long_description=(open('README.txt').read() + '\n\n' +
+ open('CHANGES.txt').read()
+ ),
+ packages=['stxutils'],
+ include_package_data=True,
+ zip_safe=False,
+ install_requires=[
+ 'zope.structuredtext',
+ ],
+ entry_points = """\
+ [console_scripts]
+ stx2html = stxutils.tohtml:main
+ """
+ )
Added: stxutils/stxutils/__init__.py
===================================================================
--- stxutils/stxutils/__init__.py (rev 0)
+++ stxutils/stxutils/__init__.py 2009-02-09 23:08:10 UTC (rev 96349)
@@ -0,0 +1 @@
+#package
Added: stxutils/stxutils/tohtml.py
===================================================================
--- stxutils/stxutils/tohtml.py (rev 0)
+++ stxutils/stxutils/tohtml.py 2009-02-09 23:08:10 UTC (rev 96349)
@@ -0,0 +1,67 @@
+""" stx2html -- convert structured text to html.
+
+Usage: stx2html [OPTIONS]
+
+Options include:
+
+o '--input' / '-i' Open the named file for input
+ if not passed, use stdin).
+
+o '--output' / '-o' Open the named file for output
+ if not passed, use stdout).
+"""
+import getopt
+import sys
+
+from zope.structuredtext.document import Document
+from zope.structuredtext.html import HTML
+from zope.structuredtext.stng import structurize
+
+def usage(msg='', rc=1):
+ print __doc__
+ if msg:
+ print
+ print msg
+ print
+ sys.exit(rc)
+
+def main(argv=None):
+
+ input = sys.stdin
+ output = sys.stdout
+
+ if argv is None:
+ argv = sys.argv[1:]
+
+ try:
+ opts, args = getopt.gnu_getopt(argv, 'i:o:h?',
+ ['--input=',
+ '--output=',
+ '--help',
+ ])
+ except getopt.GetoptError:
+ usage()
+
+ if args:
+ usage('No arguments allowed!')
+
+ for k, v in opts:
+ if k in ('-h', '-?', '--help'):
+ usage(rc=2)
+ elif k in ('-i', '--input'):
+ input = open(v, 'r')
+ elif k in ('-o', '--output'):
+ output = open(v, 'w')
+ else:
+ usage()
+
+ raw = input.read()
+ st = structurize(raw)
+ doc = Document()(st)
+ html = HTML()(doc)
+ output.write(html)
+
+
+if __name__ == '__main__':
+ import sys
+ main(sys.argv)
More information about the Checkins
mailing list