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
Opened by Fabian (Tids) - Sunday, 24 May 2020, 19:23 GMT
Last edited by Allan McRae (Allan) - Sunday, 04 December 2022, 10:01 GMT
|
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
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?
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?
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...