On 10/9/12, Olemis Lang <ole...@gmail.com> wrote: > On 10/9/12, Carlos Zuniga <carlos....@gmail.com> wrote: >> 2012/10/9 Olemis Lang <ole...@gmail.com>: >>> Hola a tod@s ! >>> >>> Recientemente necesito convertir unos diagramas en formato .dot para >>> obtener la misma representación en formato .xdoc . Busqué una librería >>> q permitiera hacer esto sin ejecutar los comandos de Graphviz en un >>> proceso o hilo aparte . Finalmente encontré yapgvb [1]_ ... pero el >>> siguiente ejemplo no me funciona . >>> >>> {{{ >>> #!py >>> >>> >>> from yapgvb import Graph >>> >>> from cStringIO import StringIO >>> >>> gdot = StringIO("digraph G {Hello->World}") >>> >>> g = Graph.read(gdot) >>> Traceback (most recent call last): >>> File "<stdin>", line 1, in <module> >>> File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 253, >>> in read >>> newgraph = cls(input_stream_or_filename) >>> File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line >>> 551, in __init__ >>> GraphBase.__init__(self, arg) >>> File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line >>> 283, in __init__ >>> CGraph.__init__(self,*args,**keywords) >>> File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line >>> 187, in cgraph_init_wrapper >>> CGraph.__original_init__(self, *a,**b) >>> Boost.Python.ArgumentError: Python argument types in >>> CGraph.__init__(Graph, cStringIO.StringI) >>> did not match C++ signature: >>> __init__(_object*, _IO_FILE*) >>> __init__(_object*, boost::python::str, agraph_type) >>> __init__(_object*, boost::python::str) >>> __init__(_object*) >>> >>> }}} >>> >>> Preguntas >>> >>> - ¿Conocen alguna forma de hacer funcionar este ejemplo y >>> pasar el código .dot a graphviz utilizando un objeto StringIO o >>> equivalente (i.e. sin utilizar el sistema de archivos ;) ? >> >> Parece que su constructor también acepta cadenas de python, has >> intentado simplemente: >> >>>>> gdot = "digraph G {Hello->World}" >>>>> g = Graph.read(gdot) >> > > rats ! > [...]
A ver , rectifico todo lo q dije antes (y no repetí ...) pq está terriblemente mal . Probé esto con cierta prisa y está mal todo lo q dije ... a ver ... comentarios in-line en el código ... {{{ #!py # Imports >>> from yapgvb import Graph >>> from sys import stdout >>> import cStringIO >>> import StringIO # .dot graph >>> gdot = "digraph G {Hello->World}" # Passing .dot grap in to __init__ >>> g = Graph(gdot) >>> g.layout('dot') 0 # Same problem with cStringIO >>> gout = cStringIO.StringIO() >>> g.render(gout, 'xdot') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 341, in render result = rendering_context.render(self, format, outstream) Boost.Python.ArgumentError: Python argument types in RenderingContext.render(RenderingContext, Graph, str, cStringIO.StringO) did not match C++ signature: render(GVCWrapper {lvalue}, Graph*, boost::python::str, boost::python::str) render(GVCWrapper {lvalue}, Graph*, boost::python::str, _IO_FILE*) # Same problem with StringIO >>> gout = StringIO.StringIO() >>> g.render(gout, 'xdot') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 341, in render result = rendering_context.render(self, format, outstream) Boost.Python.ArgumentError: Python argument types in RenderingContext.render(RenderingContext, Graph, str, instance) did not match C++ signature: render(GVCWrapper {lvalue}, Graph*, boost::python::str, boost::python::str) render(GVCWrapper {lvalue}, Graph*, boost::python::str, _IO_FILE*) # Works with stdout but ... outputs empty graph :'( >>> g.render(stdout, 'xdot') graph "digraph G {Hello->World}" { graph [bb="0,0,0,0", _draw_="c 5 -white C 5 -white P 4 0 0 0 0 0 0 0 0 ", xdotversion="1.2"]; } 0 >>> g = Graph() # Reading from string ... rats ! >>> g.read(gdot) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 249, in read input_stream_or_filename = open(input_stream_or_filename,'r') IOError: [Errno 2] No such file or directory: 'digraph G {Hello->World}' # Same problem reading from cStringIO >>> gin = cStringIO.StringIO(gdot) >>> g.read(gin) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 253, in read newgraph = cls(input_stream_or_filename) File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 551, in __init__ GraphBase.__init__(self, arg) File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 283, in __init__ CGraph.__init__(self,*args,**keywords) File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 187, in cgraph_init_wrapper CGraph.__original_init__(self, *a,**b) Boost.Python.ArgumentError: Python argument types in CGraph.__init__(Graph, cStringIO.StringI) did not match C++ signature: __init__(_object*, _IO_FILE*) __init__(_object*, boost::python::str, agraph_type) __init__(_object*, boost::python::str) __init__(_object*) # Same problem from StringIO >>> gin = StringIO.StringIO(gdot) >>> g.read(gin) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 253, in read newgraph = cls(input_stream_or_filename) File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 551, in __init__ GraphBase.__init__(self, arg) File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 283, in __init__ CGraph.__init__(self,*args,**keywords) File "/usr/lib/python2.6/dist-packages/yapgvb/__init__.py", line 187, in cgraph_init_wrapper CGraph.__original_init__(self, *a,**b) Boost.Python.ArgumentError: Python argument types in CGraph.__init__(Graph, instance) did not match C++ signature: __init__(_object*, _IO_FILE*) __init__(_object*, boost::python::str, agraph_type) __init__(_object*, boost::python::str) __init__(_object*) }}} o sea ... q realmente no he avanzado nada . De todas formas gracias por su respuesta . -- Regards, Olemis. Blog ES: http://simelo-es.blogspot.com/ Blog EN: http://simelo-en.blogspot.com/ Featured article: _______________________________________________ Python-es mailing list Python-es@python.org http://mail.python.org/mailman/listinfo/python-es FAQ: http://python-es-faq.wikidot.com/