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 !

Bue ... resulta ser q la definición creo q decía q si ese parámetro
era de tipo str entonces representaba el camino a un fichero en el
sistema de archivos . Sin embargo ...

{{{
#!py

>>> from yapgvb import Graph
>>> gdot = "digraph G {Hello->World}"
>>> g = Graph(gdot)
>>> g
<Graph "digraph G {Hello->World}">
>>> g.layout('dot')
0
>>> from StringIO import StringIO
>>> gout = 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*)
>>> from sys import stdout
>>> 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

}}}

... o sea q si bien no tengo ese problema para leer el dot (50% a mi
favor) continúo sufriendo las consecuencias para salvar el xdot en un
stream in-memory .

:-/

... pero ...

{{{
#!py

>>> from cStringIO import StringIO
>>> gout = StringIO()
>>> 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

}}}

al parecer como cStringIO está hecho en C resulta más amigable para
«conectarse» con los bindings de Boost.Python  ... y bue ... funciona
100%

:)

Gracias por su ayuda !

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:
Resolviendo el problema 1 de la IMO 2012 con inversión -
http://simelo-es.blogspot.com/2012/08/resolviendo-el-problema-1-de-la-imo.html
_______________________________________________
Python-es mailing list
Python-es@python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/

Responder a