Any python libs for parsing apache config files?

扶醉桌前 提交于 2019-11-29 03:31:20

问题


Any python libs for parsing apache config files or if not python anyone aware of such thing in other languages (perl, php, java, c#)? As i'll be able to rewrite them in python.


回答1:


I did find an interesting Apache Config parser for python here: http://www.poldylicious.de/node/25

The Apache Config Parser mentioned is not documented, but it does work.




回答2:


Red Hat's Emerging Technologies group has Augeas (written in C, but with Python bindings available), a generic system configuration tool with "lenses" for reading and writing several different configuration file formats. I would consider investigating the availability of a lens for Apache.




回答3:


There is a new library as of 2016 written using pyparsing:

https://pypi.python.org/pypi/parse_apache_configs/

Has a few rough edges, but allowed me to add in directives and save to a new file.

Source at https://github.com/alextricity25/parse_apache_configs




回答4:


No Python libraries exist that I know of, but here's a perl one: http://packages.debian.org/sid/libapache-configfile-perl

Package: libapache-configfile-perl
Priority: optional
Section: interpreters
Installed-Size: 124
Maintainer: Michael Alan Dorman
Version: 1.18-1
Depends: perl (>= 5.6.0-16)
Description: Parse an Apache style httpd.conf configuration file

This module parses the Apache httpd.conf, or any
compatible config file, and provides methods for
you to access the values from the config file.

If you do rewrite it in Python, please update your post to mention the name of your package on PyPI! :)




回答5:


There is also one new parser released.

  • http://pypi.python.org/pypi/apache_conf_parser/

It still lacks documentation, however is quite straightforward for understanding.


Example

import apache_conf_parser
import pprint

DEFAULT_VHOST = '/etc/apache2/sites-available/000-default.conf'

vhost_default = apache_conf_parser.ApacheConfParser(DEFAULT_VHOST)

print vhost_default.nodes
print vhost_default.nodes[0].body.nodes

pprint.pprint( 
    {
        i.name: [i.arguments for i in vhost_default.nodes[0].body.nodes]
    }
)



回答6:


ZConfig, I think, used to ship with a schema for parsing Apache configuration files; it doesn't seem to anymore, but it's oriented around parsing those types of files and turning the config into a Python object. A quick glance at the documentation suggests it wouldn't be too hard to set up a ZConfig schema corresponding to whatever Apache options you'd like to parse and validate.

http://pypi.python.org/pypi/ZConfig/2.6.0



来源:https://stackoverflow.com/questions/237209/any-python-libs-for-parsing-apache-config-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!