pixelb / crudini

A utility for manipulating ini files
GNU General Public License v2.0
443 stars 63 forks source link

crudini --get gets all strings in lower case #77

Closed palansher closed 3 years ago

palansher commented 3 years ago

Hello!

original section in text file:

[server__gigataxi_prod]
_type=server
ServerDomainName=gigataxi.gigataxi.ru
ServerHostName=gigataxi.ru
ServerIP4=x.x.x.x
ServerSyncGbin=1
SrvCfgSync_Dirs2Git=/etc,/usr/local/etc,/gbin,/root,/home/vladp,/home/admin/conf
SrvCfgSync_Enable=1
SrvCfgSync_RsyncFilters=rsync_filters_gigataxi.ru
SrvCfgSync_ShhRemote=root@gigataxi.gigataxi.ru
ServerSSHport=22

on some my servers it gets all lower case:

crudini --get /gbin/structure.ini server__gigataxi_prod
_type
serverdomainname
serverhostname
serverip4
serversyncgbin
srvcfgsync_dirs2git
srvcfgsync_enable
srvcfgsync_rsyncfilters
srvcfgsync_shhremote
serversshport

sometimes it shows correct (original) data:

root@marketing:~# crudini --get /gbin/structure.ini server__gigataxi_prod
_type
ServerDomainName
ServerHostName
ServerIP4
ServerSyncGbin
SrvCfgSync_Dirs2Git
SrvCfgSync_Enable
SrvCfgSync_RsyncFilters
SrvCfgSync_ShhRemote
ServerSSHport

I use Ubuntu 18.04/20.04

I cannot understand the reason. It seems when I use old crudini 0.7 from machine apt package, but I am not sure. Seems sometimes it happens on crudini 0.9.3 also.

Do you suppose the reason for such behavior?

thanks!

pixelb commented 3 years ago

We explicitly set "optionxform" to "str" to preserve case when using --get That seems to be working for me with python3-iniparse-0.4-40.fc32.noarch

What version of iniparse are you using?

palansher commented 3 years ago
apt-cache policy python-iniparse
python-iniparse:
  Installed: 0.4-2.2
  Candidate: 0.4-2.2
  Version table:
 *** 0.4-2.2 500
        500 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
        100 /var/lib/dpkg/status

And yes, I bag you to add to readme the micro installation instruction for Linux . I still don't know how to properly install the latest crudini version for Ubuntu. I use

apt install python-iniparse; curl https://raw.githubusercontent.com/pixelb/crudini/master/crudini > /usr/local/bin/crudini && chmod a+x /usr/local/bin/crudini

but it is sourced from rumors.

And I suppose people will interested how to use comments in .ini files:

/; ?

only in the beginning of the line or par=value; comment also supported

palansher commented 3 years ago

Also, how to understand which phyton version crudini use. In my ubuntu usually, phyton 2 and 3 are installed both.

pixelb commented 3 years ago

crudini supports either python variant

palansher commented 3 years ago

Hello!

Would be nice to hear your opinion about this issue. Thank you for such a useful solution!

apt-cache policy python-iniparse
python-iniparse:
  Installed: 0.4-2.2
  Candidate: 0.4-2.2
  Version table:
 *** 0.4-2.2 500
        500 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
        100 /var/lib/dpkg/status

And yes, I bag you to add to readme the micro installation instruction for Linux . I still don't know how to properly install the latest crudini version for Ubuntu. I use

apt install python-iniparse; curl https://raw.githubusercontent.com/pixelb/crudini/master/crudini > /usr/local/bin/crudini && chmod a+x /usr/local/bin/crudini

but it is sourced from rumors.

And I suppose people will interested how to use comments in .ini files:

/; ?

only in the beginning of the line or par=value; comment also supported

nganivet commented 3 years ago

A small patch can resolve this issue: sudo sed -i 's/self.parse_file(self.cfgfile)/self.parse_file(self.cfgfile, preserve_case=True)/' /usr/bin/crudini

The code already contains all logic, you just need to activate it ...

pixelb commented 3 years ago

Case preservation was released in crudini-0.9 (specifically commit e56e3a1). The sed above is a paraphrased version of that commit. Please update your Ubuntu system. I verified on packages.ubuntu.com that 0.9 is available.

nganivet commented 3 years ago

@pixelb bionic only seen to have crudini-0.7.1 available, so that's what we're working with! Thanks for creating such a useful utility!