Project

pycf

0.0
No commit activity in last 3 years
No release in over 3 years
Configuration file parser for Python 2.7 basic configuration file.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 3.0.0
 Project Readme

Pycf

Configuration file parser for Python 2.7 basic configuration file.

see ConfigParser.py.

Gem Version Build Status Coverage Status

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"}}