ConfParser.jl

ConfParser is a package for parsing, modifying, and writing to configuration files. ConfParser can handle configuration files utilizing multiple syntaxes to include INI, HTTP, and simple.

Index

Examples

INI Files

header=leheader

; this is a comment
[database]
user=dbuser
password=abc123
host=localhost

; this is another comment
[foobarness]
foo=bar,foo
foobar=barfoo
using ConfParser

conf = ConfParse("confs/config.ini")
parse_conf!(conf)

# get and store config parameters
user     = retrieve(conf, "database", "user")
password = retrieve(conf, "database", "password")
host     = retrieve(conf, "database", "host")

# replace config paramater
commit!(conf, "database", "user", "newuser")

# erase a config block
erase!(conf, "foobarness")

# save to another file
save!(conf, "testout.ini")

HTTP Files

# this is a comment
email:juliarocks@socks.com
password:qwerty

# this is another comment
url:julialang.org
foobars:foo,bar,snafu
using ConfParser

conf = ConfParse("confs/config.http")
parse_conf!(conf)

# get and store config parameters
email    = retrieve(conf, "email")
password = retrieve(conf, "password")
foobars  = retrieve(conf, "foobars")

# modify config parameter
commit!(conf, "email", "newemail@test.com")

# save changes
save!(conf)

Simple Files

# this is a comment
protocol kreberos
port 6643
user root

# this is another comment
foobar barfoo
using ConfParser

conf = ConfParse("confs/config.simple")
parse_conf!(conf)

# store config items in vars
protocol = retrieve(conf, "protocol")
port     = retrieve(conf, "port")
user     = retrieve(conf, "user")

# remove config parameter
erase!(conf, "protocol")

# generate new config from data
save!(conf, "outconf.simple")

Key-Only Files

e613ef71d63b84b721bdd345a5708ce5738028
using ConfParser

conf = ConfParse("confs/config.keyonly")
parse_conf!(conf)

# store config items in vars
key = retrieve(conf, "key") # the key is stored as "key"

# update config parameter
commit!(conf, "key","e714ef71d63b84b721bdd345a5708ce5738028b")

# generate new config from data
save!(conf, "outconf.keyonly")

Public Interface

Base.haskeyMethod
haskey(s::ConfParse, block::String, key::String)

Check if a key exists inside an ini file block.

Base.haskeyMethod
haskey(s::ConfParse, key::String)

Check if a key exists.

Base.merge!Method
Base.merge!(s::ConfParse, t::ConfParse)

Merge data of two configuration files.

ConfParser.commit!Method
commit!(s::ConfParse, key::String, value::Any)

Insert data in a config file.

ConfParser.commit!Method
commit!(s::ConfParse, block::String, key::String, values::String)

Insert data inside an ini file block.

ConfParser.erase!Method
erase!(s::ConfParse, block::String, key::String)

Remove entry from ini block.

ConfParser.erase!Method
erase!(s::ConfParse, key::String)

Remove entry from config (outside of block if ini).

ConfParser.parse_conf!Method
parse_conf!(s::ConfParse)

Tasks appropriate parser function based on configuration syntax.

ConfParser.retrieveMethod
retrieve(s::ConfParse, block::String, key::String, t::Type)

Retrieve data from an ini config file block and converting to type.

ConfParser.retrieveMethod
retrieve(s::ConfParse, block::String, key::String)

Retrieve data from an ini config file block.

ConfParser.retrieveMethod
retrieve(s::ConfParse, key::String, t::Type)

Retrieve data outside of a block and converting to type.

ConfParser.retrieveMethod
retrieve(s::ConfParse, key::String)

Retrieve data outside of a block.

ConfParser.save!Function
save!(s::ConfParse, filename=nothing)

Write out new or modified configuration files.

Internals

ConfParser.guess_syntaxMethod
guess_syntax(fh::IO)

Attempts to guess the configuration file syntax using regular expressions.

ConfParser.parse_httpMethod
parse_http(s::ConfParse)

Parses configuration files utilizing http sytnax. Populate the ConfParser.data dictionary.

ConfParser.parse_iniMethod
parse_ini(s::ConfParse)

Parses configuration files utilizing ini sytnax. Populate the ConfParser.data dictionary.

ConfParser.parse_keyonlyMethod
parse_keyonly(s::ConfParse)

Parses configuration files utilizing keyonly syntax. Populates the ConfParser.data dictionary.

ConfParser.parse_simpleMethod
parse_simple(s::ConfParse)

Parses configuration files utilizing simple syntax. Populates the ConfParser.data dictionary.