-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New parser: update-alternatives --query #230
Comments
Thank you for the parser suggestion. Sweet script! I’ll definitely take a look at this. |
Is this fairly representative of the output? Are there any fields you see missing?
Looks pretty simple to parse - I can probably get this into the next release. The schema could look something like this:
Also, I wonder if there would be any value to creating a parser for |
Yes to all the above! I've had a quick scan through the output of this: for alt in $(update-alternatives --get-selections | awk '{ print $1 }'); do update-alternatives --query ${alt}; done | less And I didn't see anything that didn't match the pattern above. I agree that it would be good to also generate JSON from I'm currently working on a Ansible role for which I picked a slightly different format, a dictionary rather than a list: alternatives_update:
'php':
state: present
link: /usr/bin/php
alternatives:
- path: /usr/bin/php7.4
state: present
priority: 50
- path: /usr/bin/php8.0
state: present
priority: 80
- path: /usr/bin/php8.1
state: present
priority: 81
'php-fpm.sock':
link: /run/php/php-fpm.sock
state: present
alternatives:
- path: /run/php/php7.4-fpm.sock
state: present
priority: 74
- path: /run/php/php8.0-fpm.sock
state: present
priority: 80
- path: /run/php/php8.1-fpm.sock
state: present
priority: 81 But your format probably makes more sense so I'll look at updating it, your version in YAML is this: name: string
link: string
slaves:
- name: string
path: string
status: string
best: string
value: string
alternatives:
- name: string
priority: integer
slaves:
- name: string
path: string |
I notice you have a |
Sorry I should have omitted that above, |
I have a working version in https://github.com/kellyjonbrazil/jc/blob/dev/jc/parsers/update_alt_q.py You can copy this file to your plugin folder and it should work like |
A working version of the https://github.com/kellyjonbrazil/jc/blob/dev/jc/parsers/update_alt_gs.py Usage is similar: |
Thanks, I've done this: pip install jc
mkdir -p "${HOME}/.local/share/jc/jcparsers"
cd "${HOME}/.local/share/jc/jcparsers"
wget https://raw.githubusercontent.com/kellyjonbrazil/jc/dev/jc/parsers/update_alt_q.py
cd
update-alternatives --get-selections | jc --update-alt-q And the output is:
Have I missed something? I also tried:
And that has the same result. |
Sorry, I half read the first of your comments above via email and then the second via the web and got them mixed up... trying again...
Am I doing something wrong? |
I tried the above on an ubuntu VM and it seemed to work. What happens if you do
|
Weird, yes the plugins are there: jc -h 2>&1 | grep update
--update_alt_gs `update-alternatives --get-selections` command parser
--update_alt_q `update-alternatives --query` command parser And |
Funny because this feels like you have an older version of |
I was just wondering if this was the issue also, I appear to be running the Debian Buster version: cat $(which jc) | head
#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'jc==1.14.3','console_scripts','jc'
import re
import sys
# for compatibility with easy_install; see #2198
__requires__ = 'jc==1.14.3'
try:
from importlib.metadata import distribution |
In that case I think it will work if you remove the underscores in the filenames. I haven't tested on a version that old, though. |
This did the trick... wget "https://github.com/kellyjonbrazil/jc/releases/download/v1.18.6/jc_1.18.6-1_amd64.deb"
gdebi jc_1.18.6-1_amd64.deb Now both these work:
That's fantastic! I'll stop writing Bash to parse the output and write an Ansible role to install the latest version of |
Right on! I still need to write some tests and then I'll add these into v1.18.7. I'll probably release it by next week some time. Thanks for your contributions! |
Thanks again for your work on this @kellyjonbrazil, I've written an Ansible role to install jc using debs from GitHub and I'll now work on a role that uses the parsers you have written to update alternatives. |
One thought, the
Is described like this in the man page:
Since it is a absolute path it might make more sense to use |
Yeah, that makes sense. There are a lot of ‘name’s there that can get confusing. I can change that no problem. |
Thinking about this some more I think the best approach would be to stick closely to what is in the |
Sounds good - yeah I was thinking the same thing, too. |
I'm going to release this now in the v1.18.7 release on PIP-only. If things test ok, then I'll bump the github release as well. Thanks! |
There seems to be a problem here: update-alternatives --query php-fpm.sock
Name: php-fpm.sock
Link: /run/php/php-fpm.sock
Status: auto
Best: /run/php/php8.1-fpm.sock
Value: /run/php/php8.1-fpm.sock
Alternative: /run/php/php7.4-fpm.sock
Priority: 74
Alternative: /run/php/php8.0-fpm.sock
Priority: 80
Alternative: /run/php/php8.1-fpm.sock
Priority: 81 jc -p update-alternatives --query php-fpm.sock
{
"name": "php-fpm.sock",
"link": "/run/php/php-fpm.sock",
"status": "auto",
"best": "/run/php/php8.1-fpm.sock",
"value": "/run/php/php8.1-fpm.sock",
"alternatives": [
{
"alternative": "/run/php/php8.1-fpm.sock",
"priority": 81
}
]
} Why are the alternatives missing from the JSON version? Any suggestions regarding how I might help debug this? |
let me take a look - it probably has to do with certain expected values missing (e.g. slaves) |
Yep, was a little bug in the logic. Cleaned that up and the fix will go into v1.18.8. You can test it here: https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/update_alt_q.py |
Great, thanks, I've tested it and it is working as expected, {
"name": "php-fpm.sock",
"link": "/run/php/php-fpm.sock",
"status": "auto",
"best": "/run/php/php8.1-fpm.sock",
"value": "/run/php/php8.1-fpm.sock",
"alternatives": [
{
"alternative": "/run/php/php7.4-fpm.sock",
"priority": 74
},
{
"alternative": "/run/php/php8.0-fpm.sock",
"priority": 80
},
{
"alternative": "/run/php/php8.1-fpm.sock",
"priority": 81
}
]
} I'm going to try to find time this evening to test a lot of other alternatives but first I want to write a Ansible |
Nice! Let me know if you run into any other issues. I'm packaging v1.18.8 now. It's already on PIP and the binaries should be in github Releases soon. It would be possible to output YAML in addition to JSON. I might think about that for v1.19.0. Maybe open a feature request issue so we can track it. |
Cheers, have done #237 |
The Ansible role I was planning to use to test the |
The Debian alternatives system has a
update-alternatives
command which has a--query
option which will:For example for the
editor
(omitting the Slaves output):Perhaps this might be a useful new parser for
jc
, the Ansible alternatives module is only able to set alternatives, not read them, so I've written some Bash to use as a Ansiblefacts.d
script for converting the output into JSON:Running this script with an argument, for example
editor
results in:The text was updated successfully, but these errors were encountered: