Skip to main content

A simple Apache Config Parser

Project description

Simple Apache Config Parser

Welcome to the Simple Apache Config Parser! This package is intended to ease the parsing/analysis of apache config files. This parser uses the Apache Config Lexer provided by the pygments project.

This project is still very much in its infancy, but my focus is on providing easy to use/understand object interfaces to analyze and modify apache config files while attempting to minimize the deltas between the original configs and the modified content. If this software is not quite meeting your needs, drop in an Issue and I'll do my best to address/help, but even if that's failing checkout this other neat parser apacheconfig.

Example usage

Here are some example usages. Note that these examples assume your current working directory properly set to match Include patterns. In the examples below this is for a CentOS installation where the root apache directory tends to be /etc/httpd/.

Parsing

Parsing a config file is easy!

from sacp import *
cf = ConfigFile(file="conf/httpd.conf")

This will automatically parse the httpd.conf from the current directory. Any dependent configs (e.g. those that are listed in an Include or IncludeOptional directive) will also be loaded.

Walking the nodes

Visiting all the nodes is also easy!

from sacp import *

def visit(node):
    print("{}{}".format(node.depth * " ", type(node)))

cf = ConfigFile(file="conf/httpd.conf")
NodeVisitor(cf.children).visit(visitor=visit)

This visits all of the nodes in the config file, including it's children, and prints each node type with it's relative depth represented as well.

Contribute

Want to contribute? Awesome! Fork, code, and request a PR.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sacp, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size sacp-0.2-py3-none-any.whl (7.0 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size sacp-0.2.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page