skip to navigation
skip to content

iniconfig.py 1.0.2

A more convenient and practical approach to manage .ini files

A more convenient and practical approach to manage .ini files. You can link a class property with an .ini file option and delegating your management.

Installation

Install it via pip

$ [sudo] pip install iniconfig.py

Or download zip and then install it by running

$ [sudo] python setup.py install

Example

from iniconfig import IniConfig

class Config(IniConfig):

    # file section
    useCsvWizard = IniConfig.iniproperty('file', 'useCsvWizard', True)
    owner = IniConfig.iniproperty('file', 'owner', {'name':'david', 'login':'yeap'})
    files = IniConfig.iniproperty('file', 'files', [])

    # tools section
    searches = IniConfig.iniproperty('tools', 'searches', ['primate', 'wolf', 'rabbit'])
    matchMode = IniConfig.iniproperty('tools', 'matchMode', 0)
    weight = IniConfig.iniproperty('tools', 'weight', False)

    # config section
    restore = IniConfig.iniproperty('config', 'restore', True)


config = Config('demo.ini')#, autocreate=True)

print '\nafter'
print 'file/useCsvWizard:', config.useCsvWizard
print 'file/owner:', config.owner
print 'file/files:', config.files
print 'tools/searches:', config.searches

config.useCsvWizard = False
config.files = ['myfile.py']
config.owner['name'] = 'joan'
config.owner['surname'] = 'miro'
del(config.owner['login'])
del config.searches[2]

print '\nbefore'
print 'file/useCsvWizard:', config.useCsvWizard
print 'file/owner:', config.owner
print 'file/files:', config.files
print 'tools/searches:', config.searches

Result

after
file/useCsvWizard: True
file/owner: {'login': 'yeap', 'name': 'david'}
file/files: []
tools/searches: ['primate', 'wolf', 'rabbit']

before
file/useCsvWizard: False
file/owner: {'surname': 'miro', 'name': 'joan'}
file/files: ['myfile.py']
tools/searches: ['primate', 'wolf']

Now the content .ini file is:

[file]
usecsvwizard = False
files = ['myfile.py']
owner = {'surname': 'miro', 'name': 'joan'}

[tools]
searches = ['primate', 'wolf']

How to contribute

Have an idea? Found a bug? add a new issue or fork and sendme a pull request. Don’t forget to add your name to the Contributors section of this document.

License

Licensed under the MIT, see LICENSE

Contributors

David Miro lite.3engine@gmail.com

 
File Type Py Version Uploaded on Size
iniconfig.py-1.0.2.zip (md5) Source 2016-05-11 10KB