FS#66769 - python configparser is unable to parse pacman.conf because of the nonstandard format of it.

Attached to Project: Pacman
Opened by Fabian (Tids) - Sunday, 24 May 2020, 19:23 GMT
Last edited by Allan McRae (Allan) - Sunday, 04 December 2022, 10:01 GMT
Task Type Bug Report
Category General
Status Closed
Assigned To No-one
Architecture All
Severity Low
Priority Normal
Reported Version 5.2.1
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Hi. I'm trying to parse the pacman.conf in python. Sadly this wont work, because it's only in part an INI file.
ERROR is
configparser.ParsingError: Source contains parsing errors: '/etc/pacman.conf'
[line 33]: 'Color\n'
[line 34]: 'TotalDownload\n'
[line 35]: 'CheckSpace\n'
[line 36]: 'VerbosePkgLists\n'
[line 37]: 'ILoveCandy\n'

COMMAND pythonshell
import configparser
pacman_config = configparser.RawConfigParser()
pacman_config.read("/etc/pacman.conf")
print(pacman_config.get('options', 'HoldPKG'))

I read it now in as normal text file, so no big deal. However, I'd like to ask if it could become a proper INI config file in a future release? Misc options could be a list
Misc = Color TotalDownload Checkspace etc

The other part is the "Include = " line at the end. If uncommented it would be part of the [community] section and so a duplicate (that results in an error). So this general Include would need to be changed in some way to make it part of an own section or the options section. Other than that it's pretty OK already.

This would be a great help.
Thanks in advance. :)
This task depends upon

Closed by  Allan McRae (Allan)
Sunday, 04 December 2022, 10:01 GMT
Reason for closing:  No response
Comment by Eli Schwartz (eschwartz) - Sunday, 24 May 2020, 19:35 GMT
Use pacman-conf to query values, or the thirdparty pyalpm bindings with pycman.config

ini is hardly a standard format, there are dialects in which an "implicit key" is automatically assumed boolean true. I see nothing wrong with that.

I see no rationale to break the Include syntax just because someone wishes to use python's configparser to parse it. Why should duplicate sections be considered an error? What do you propose to do with "Server =" directives, which must support multiple servers as fallbacks?
Comment by Fabian (Tids) - Sunday, 24 May 2020, 20:48 GMT
> What do you propose to do with "Server =" directives, which must support multiple servers as fallbacks?
Thats true. I've completely forget about that. You're right with it.

Also omitted values are actually supported and just fine.
DOCS: Values can be omitted, in which case the key/value delimiter may also be left out.

So for both of them, sorry!

The last Include still feels like it's wrong where it is right now. It isnt a part of the repo, isnt it? yet it would be set as part of a repo, if straight commented out. Is this intentional?
Comment by Andrew Gregory (andrewgregory) - Sunday, 24 May 2020, 20:57 GMT
What Include are you referring to?
Comment by Eli Schwartz (eschwartz) - Sunday, 24 May 2020, 21:06 GMT
What include are you even talking about? There's one per section, normally, which is used to inline-include the contents of the mirrorlist file.

At the bottom of the stock pacman.conf there is a commented-out 3-line block:

#[custom]
#SigLevel = Optional TrustAll
#Server = file:///home/custompkgs

If you uncomment all 3 lines, it forms a custom repo. But it's not an Include line.

An Include line is certainly *valid*, regardless of where it appears or why or how many times. But I don't know which one you happen to be talking about...

Loading...