changeset 3:1a267297f779

graphviz now works, giving real version
author k0s <k0scist@gmail.com>
date Thu, 14 Jan 2010 00:16:34 -0500
parents 1e2c475015d8
children 5258325a496a
files contenttransformer/transformers.py example.ini example/process.gv.txt setup.py
diffstat 4 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/contenttransformer/transformers.py
+++ b/contenttransformer/transformers.py
@@ -1,20 +1,23 @@
 import docutils.core
 import subprocess
 from webob import Response
 
 class Graphviz(object):
     def __init__(self, content):
         """create a Graphviz object"""
-        raise NotImplementedError # TODO
+        process = subprocess.Popen(['dot', '-Tpng'],
+                                   stdin=subprocess.PIPE,
+                                   stdout=subprocess.PIPE)
+        self.image, _ = process.communicate(content)
 
     def __call__(self, environ, start_response):
         """return a WSGI response"""
-   
+        return Response(content_type='image/png', body=self.image)(environ, start_response)   
 
 class RestructuredText(object):
     settings = { 'report_level': 5 }
 
     def __init__(self, content):
         """template: genshi(?) template to use (???)"""
         self.html = docutils.core.publish_string(content,
                                                  writer_name='html',
--- a/example.ini
+++ b/example.ini
@@ -15,9 +15,9 @@ port = 6666
 use = egg:Paste#urlmap
 / = contenttransformer
 
 set debug = false
 
 [app:contenttransformer]
 paste.app_factory = contenttransformer.factory:factory
 transformer.directory = %(here)s/example
-transformer.transforms = *.txt=ReST
\ No newline at end of file
+transformer.transforms = *.gv.txt=Graphviz,*.txt=ReST
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/example/process.gv.txt
@@ -0,0 +1,13 @@
+digraph g {
+start -> types;
+start [label="new project"];
+types [label="pastescript template"];
+types -> templates [dir=none];
+templates [
+          label="webob_view|genshi_view|console_script"
+          shape="record"];
+types -> development;
+development -> types;
+development -> integration;
+integration [label="integration with website + middleware"];
+};
--- a/setup.py
+++ b/setup.py
@@ -1,12 +1,12 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = "0.0"
+version = "0.1"
 
 setup(name='contentransformer',
       version=version,
       description="transform e.g. file data based on type to be served TTW",
       long_description="""
 """,
       classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
       author='Jeff Hammel',