python_etf
python_etf copied to clipboard
Looking for python package to read and write erlang config file
Hi @twonds, I need to be able to parse and update rabbitmq.config file using python on Travis and AppVeyor builds of the pika open-source RabbitMQ client library. I haven't been able to find one on the web, so wondering if you know of one. Many thanks.
Do you have an example config?
This is a tiny example: https://gist.github.com/celldee/4241084 and this is a large template of all the possibilities with everything commented out: https://github.com/rabbitmq/rabbitmq-server/blob/master/docs/rabbitmq.config.example.
Thank you.
Tiny example works except comments with "#" because they are non-valid for erlang, for example:
>>> erl_terms_core.decode("""
... [
... {rabbit, [
... {tcp_listeners,[{"127.0.0.1",5672}]},
... {ssl_listeners, [{"127.0.1.1",5671}]},
... {ssl_options, [{cacertfile,"/usr/local/etc/rabbitmq/ssl/testca/cacert.pem"},
... {certfile,"/usr/local/etc/rabbitmq/ssl/server/cert.pem"},
... {keyfile,"/usr/local/etc/rabbitmq/ssl/server/key.pem"},
... {verify,verify_none},
... {fail_if_no_peer_cert,false}]}
... ]}
... ].
... """)
[[('rabbit', [('tcp_listeners', [('127.0.0.1', 5672)]), ('ssl_listeners', [('127.0.1.1', 5671)]), ('ssl_options', [('cacertfile', '/usr/local/etc/rabbitmq/ssl/testca/cacert.pem'), ('certfile', '/usr/local/etc/rabbitmq/ssl/server/cert.pem'), ('keyfile', '/usr/local/etc/rabbitmq/ssl/server/key.pem'), ('verify', 'verify_none'), ('fail_if_no_peer_cert', False)])])]]
and longer example works entirely,
let us know if you have any further quesions
actually, even Erlang itself does not accept tiny example with "#" comments:
1> file:consult("example.txt"). {error,{1,erl_parse,["syntax error before: ","'/'"]}}
Hi @parsifal-47, thank you for following up on my question and demonstrating erl_terms_core's decoding capability. When I first looked at the package, I also noticed that. However, I am looking for a package that provides the ability to encode as well. The pika test code needs to open/parase rabbitmq.config, make some changes in the configuration, and then save it back out. I was hoping to avoid having to do it in Erlang (no time for the learning curve at the moment), so python would be more desirable. Thank you for sharing. Please post if you know of a package that supports decode/modify/encode on that format.
Also, sorry about the unfortunate choice of example with the # character in it. That was my mistake.