Skip to main content

Python library to parse config files that require indexing

Project description

A class to parse configuration files that require indexing.
This class returns a dictionary that you can call to retrieve items
from your config file.

To use this parser to its full potential create config files in the
following format for example:

(Example config file)

# Home server
server_1 = somename
ip_1 = 1.2.3.4
location_1 = san jose

# Remote server
server_2 = someothername
ip_2 = 4.3.2.1
location_2 = boston

# Universal configs
universal_key = something universal
my_username = kyle


You can keep raising the indexed number as much as you want.
The way to use this library is to pick a config definition
that you know will be different for each index. In this case I would
use "server" as the "defining key" and that would make each server name
into its own dictionary and the key/value pairs for it would be the config
key/values that are associated with the same index number.

There are 3 lists that are created on each parse:
keys = this is a list of the keys that are not indexed
(used for universal purposes)
index_keys = this is a list of all the keys that are indexed
(this is generated based on the defining key)
all_keys = this is a list of all the keys combined

Examples:

import IndexConfigParser

(The following code will print the dictionaries of each index key)
icp = IndexConfigParser.IndexConfigParser("/home/kyle/config.cfg", "server")
for key in icp.index_keys:
print "The dictionary for %s is: " %key
print icp[key]

(The following is how to call a specific key in the index key dict)
icp = IndexConfigParser.IndexConfigParser("/home/kyle/config.cfg", "server")
var = "somename"
icp[var]["ip"]
(Using the example config file above this would return "1.2.3.4")

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

IndexConfigParser-1.2.tar.gz (2.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page