Created
July 16, 2015 15:35
-
-
Save jimallman/fa79cddd3a0a0fa4733f to your computer and use it in GitHub Desktop.
Quick test of local config file (for web-app configuration, etc)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A quick validator for web-app config files | |
import os | |
from ConfigParser import SafeConfigParser | |
conf = SafeConfigParser({}) | |
if not os.path.isfile("./config"): | |
print("Expecting a file 'config' in the current directory") | |
exit() | |
conf.read("./config") | |
try: | |
conf.read("./config") | |
except: | |
print("Found a local 'config' file, but I can't read it!") | |
exit() | |
print("\n\nSections in this config file:") | |
for sec in conf.sections(): | |
print(" {}".format(sec)) | |
print("\n\nOptions within each section:") | |
for sec in conf.sections(): | |
print(" [{}]".format(sec)) | |
for opt in conf.options(sec): | |
print(" {o} = {v}".format(o=opt, v=conf.get(sec,opt))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment