Skip to main content

read configuration files, conf.d style

Project description

read configuration files, conf.d style

Requirements

  • Python 2.6+

Installation

Using PIP:

From Github:

pip install git+git://github.com/josegonzalez/conf_d.git#egg=conf_d

From PyPI:

pip install conf_d==0.0.2

Usage

usage:

# in your /etc/derp/conf file
[derp]
no: sleep
til: brooklyn

[herp]
sleep: 1
wait: 5.0
timeout: seventy

# From your fictional derp module
from conf_d import Configuration

def digitize(config):
    for key in config:
        if not config[key].isdigit():
            try:
                config[key] = float(config[key])
            except ValueError:
                pass
        else:
            try:
                config[key] = int(config[key])
            except ValueError:
                pass

        return config

# All defaults must be strings
conf = Configuration(
    name="derp",
    path="/etc/derp/conf",
    main_defaults={
        "no": "one",
        "expected": "the spanish inquisition",
        "cats": "1",
    },
    section_parser=digitize
)

what_not_to_do = conf.get(section='derp', key='no', default="jumping")
# "sleep"

until_when = conf.get(section='derp', key='til')
# "brooklyn"

cats = conf.get(section='derp', key='cats')
# "1"

dogs = conf.get(section='derp', key='dogs')
# None

sleep = conf.get(section='herp', key='sleep')
# 1

wait = conf.get(section='herp', key='wait')
# 5.0

timeout = conf.get(section='herp', key='timeout')
# "seventy"

section_exists = conf.has(section='derp')
# True

section_exists = conf.has(section='derp', key='no')
# True

raw_data = conf.raw()
# {
#    'sections': {
#       'herp': {
#          'sleep': 1,
#          'wait': 5.0,
#          'timeout': 'seventy'
#       }
#    },
#    'derp': {
#       'expected': 'the spanish inquisition',
#       'til': 'brooklyn',
#       'cats': '1',
#       'no': 'sleep'
#    }
# }

Changelog

0.0.1 (2013-04-13)

  • Initial commit

Project details


Download files

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

Source Distribution

conf_d-0.0.2.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file conf_d-0.0.2.tar.gz.

File metadata

  • Download URL: conf_d-0.0.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for conf_d-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f361f86ac382f9c1c47115aeb5fc484adf42f6e0505c003bc5129af6d2305332
MD5 96908c83cb9d9ad2c9cd3381801df98d
BLAKE2b-256 588d5b30823d182606d651013ed14854cb980b1c0dc8b9bad63b42430ba58860

See more details on using hashes here.

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