Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-config style configuration system

What system does git-config use to manage configuration? Is it something that's publicly available as a stand-alone library/tool? or is it tightly interwined into git?

I'd like to have something like it for my project.

Is there a library that I can use which provides similar functionality? Or should I just write my own tool/library?

like image 915
hasen Avatar asked Dec 08 '22 05:12

hasen


2 Answers

For Python, seems ConfigParser cannot be used directly due to the leading spaces in git config file. But it could be used in this way

from ConfigParser import ConfigParser
from StringIO import StringIO

with open('.gitconfig') as f:
    c = f.readlines()
cp = ConfigParser()
cp.readfp(StringIO(''.join([l.lstrip() for l in c])))
like image 147
Congbin Guo Avatar answered Dec 09 '22 19:12

Congbin Guo


The code is custom. Have a look for yourself (see builtin-config.c, config.c).

See the license (GPL v2) for details on reuse.

It is not a generic library, nor is it a generic tool (though you might be able to use it as one if you alway pass --file and are OK with the way it does subsections), so it will take some work to adapt the code.

like image 41
Chris Johnsen Avatar answered Dec 09 '22 18:12

Chris Johnsen