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
Base.haskey
Base.haskey
Base.merge!
ConfParser.commit!
ConfParser.commit!
ConfParser.craft_content
ConfParser.erase!
ConfParser.erase!
ConfParser.guess_syntax
ConfParser.parse_conf!
ConfParser.parse_http
ConfParser.parse_ini
ConfParser.parse_keyonly
ConfParser.parse_line
ConfParser.parse_simple
ConfParser.retrieve
ConfParser.retrieve
ConfParser.retrieve
ConfParser.retrieve
ConfParser.save!
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.haskey
— Methodhaskey(s::ConfParse, block::String, key::String)
Check if a key exists inside an ini file block.
Base.haskey
— Methodhaskey(s::ConfParse, key::String)
Check if a key exists.
Base.merge!
— MethodBase.merge!(s::ConfParse, t::ConfParse)
Merge data of two configuration files.
ConfParser.commit!
— Methodcommit!(s::ConfParse, key::String, value::Any)
Insert data in a config file.
ConfParser.commit!
— Methodcommit!(s::ConfParse, block::String, key::String, values::String)
Insert data inside an ini file block.
ConfParser.erase!
— Methoderase!(s::ConfParse, block::String, key::String)
Remove entry from ini block.
ConfParser.erase!
— Methoderase!(s::ConfParse, key::String)
Remove entry from config (outside of block if ini).
ConfParser.parse_conf!
— Methodparse_conf!(s::ConfParse)
Tasks appropriate parser function based on configuration syntax.
ConfParser.retrieve
— Methodretrieve(s::ConfParse, block::String, key::String, t::Type)
Retrieve data from an ini config file block and converting to type.
ConfParser.retrieve
— Methodretrieve(s::ConfParse, block::String, key::String)
Retrieve data from an ini config file block.
ConfParser.retrieve
— Methodretrieve(s::ConfParse, key::String, t::Type)
Retrieve data outside of a block and converting to type.
ConfParser.retrieve
— Methodretrieve(s::ConfParse, key::String)
Retrieve data outside of a block.
ConfParser.save!
— Functionsave!(s::ConfParse, filename=nothing)
Write out new or modified configuration files.
Internals
ConfParser.craft_content
— Methodcraft_content(s::ConfParse)
Craft content strings from data array for saved config.
ConfParser.guess_syntax
— Methodguess_syntax(fh::IO)
Attempts to guess the configuration file syntax using regular expressions.
ConfParser.parse_http
— Methodparse_http(s::ConfParse)
Parses configuration files utilizing http sytnax. Populate the ConfParser.data dictionary.
ConfParser.parse_ini
— Methodparse_ini(s::ConfParse)
Parses configuration files utilizing ini sytnax. Populate the ConfParser.data dictionary.
ConfParser.parse_keyonly
— Methodparse_keyonly(s::ConfParse)
Parses configuration files utilizing keyonly syntax. Populates the ConfParser.data dictionary.
ConfParser.parse_line
— Methodparse_line(line::String)
Sperates by commas, removes newlines and such.
ConfParser.parse_simple
— Methodparse_simple(s::ConfParse)
Parses configuration files utilizing simple syntax. Populates the ConfParser.data dictionary.