Pycf
Configuration file parser for Python 2.7 basic configuration file.
see ConfigParser.py.
Installation
Add this line to your application's Gemfile:
gem 'pycf'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pycf
Usage
load
require 'pycf'
python_config = <<EOS
[DEFAULT]
ServerAliveInterval = 45
Compression = yes
CompressionLevel = 9
ForwardX11 = yes
[bitbucket.org]
User = hg
[topsecret.server.com]
Port = 50022
ForwardX11 = no
EOS
p Pycf.load(python_config)
# => {"DEFAULT"=>
# {"serveraliveinterval"=>"45",
# "compression"=>"yes",
# "compressionlevel"=>"9",
# "forwardx11"=>"yes"},
# "bitbucket.org"=>{"user"=>"hg"},
# "topsecret.server.com"=>{"port"=>"50022", "forwardx11"=>"no"}}
dump
require 'pycf'
require 'pp'
hash = {"DEFAULT"=>
{"serveraliveinterval"=>"45",
"compression"=>"yes",
"compressionlevel"=>"9",
"forwardx11"=>"yes"},
"bitbucket.org"=>{"user"=>"hg"},
"topsecret.server.com"=>{"port"=>"50022", "forwardx11"=>"no"}}
puts Pycf.dump(hash)
# => [DEFAULT]
# serveraliveinterval = 45
# compression = yes
# compressionlevel = 9
# forwardx11 = yes
# [bitbucket.org]
# user = hg
# [topsecret.server.com]
# port = 50022
# forwardx11 = no
Interpolation
require 'pycf'
python_config = <<EOS
[My Section]
foodir: %(dir)s/whatever
dir=frob
long: this value continues
in the next line
EOS
p Pycf.load(python_config, interpolation: true)
# => {"My Section"=>
# {"foodir"=>"frob/whatever",
# "dir"=>"frob",
# "long"=>"this value continues\nin the next line"}}