ivan-hc / AM

AppImage package manager to install, update and manage ALL of them, system-wide or locally, thanks to its ever-growing AUR-inspired database listing 2500+ portable apps and programs for GNU/Linux. The first, real centralized repository to manage your AppImages with the ease of APT and the power of PacMan.
https://portable-linux-apps.github.io
GNU General Public License v3.0
520 stars 41 forks source link

Provide JSON metadata of all packages #1166

Closed Azathothas closed 2 days ago

Azathothas commented 2 days ago

Hi, I noticed https://github.com/Portable-Linux-Apps/Portable-Linux-Apps.github.io/blob/main/apps.json, but this contains no source url i.e the SITE= or version= from your scripts Any interest in completing that list and also including the source_url ?

ivan-hc commented 2 days ago

Nope, it was asked by another developer that wanted to create an electron frontend for AM and tht is disappeared.

So I don't really need that file anymore. I also disabled its update in my workflow because useless at this point.

Azathothas commented 2 days ago

Hmm. I see. Seems like I have to parse shell scripts directly

Azathothas commented 2 days ago

Didn't get everything, sadly.

Is there a way to list pkg_name + description + version + url?

am -q --all

image

That only lists name and description

ivan-hc commented 2 days ago

Nope, this is a simple list with just appname and description. This is all the user needs to know.

In addition, -a gives a more complete description, with URL, and -d allows the download of the script, so the user can see exactly what the script will download and istal, and how the version can be obtained.

About apps version, it is always the latest one.

Azathothas commented 2 days ago

Hmm, seems like no way, without installing everything. No easy for machines to parse any data... For instance to just get the pkg name:

am -q --appimages | sed -n 's/.* ◆ \(.*\) :.*/\1/p'

As it's all formatted

ivan-hc commented 2 days ago

am -q --appimages | sed -n 's/.* ◆ \(.*\) :.*/\1/p'

you forgot the argument

ivan-hc commented 2 days ago

do you mean -l?

am -l --appimages | sed -n 's/.* ◆ \(.*\) :.*/\1/p'

Istantanea_2024-11-29_18-58-12

Azathothas commented 2 days ago

In my testing, I found -q to be faster than -l

$ time am -l --appimages | sed -n 's/.* ◆ \(.*\) :.*/\1/p' | wc -l
2121

real    0m1.726s
user    0m2.707s
sys     0m1.979s
$ time am -q --appimages | sed -n 's/.* ◆ \(.*\) :.*/\1/p' | wc -l
2121

real    0m1.717s
user    0m2.701s
sys     0m2.015s
Azathothas commented 2 days ago

I finally managed to generate one, but it's very slow process https://pub.ajam.dev/temp/AM.json

am -q --appimages | sed -n 's/.* ◆ \(.*\) :.*/\1/p' | xargs -I{} am -a "{}" | awk '
function escape_json(s) {
    gsub(/\\/, "\\\\", s)
    gsub(/"/, "\\\"", s)
    gsub(/\n/, "\\n", s)
    return s
}

function trim(s) {
    sub(/^[ \t]+/, "", s)
    sub(/[ \t]+$/, "", s)
    return s
}

/^ PACKAGE:/ { pkg = substr($0, index($0, $2)) }
/^ STATUS:/ { status = $NF }
/^ / && $1 !~ /^(PACKAGE:|STATUS:|DOCUMENTATION:|SOURCE:|SITE:)/ {
    desc = (desc == "" ? substr($0, 2) : desc " " substr($0, 2))
}
/^ SOURCE:/ { source = substr($0, index($0, $2)) }
/^ SITE:/ { site = substr($0, index($0, $2)) }
/^-+$/ {
    if (length($0) > 15 && pkg != "" && desc != "") {
        final_site = (source ~ /github\.com/ ? source : site)
        print "{ \"pkg\": \"" escape_json(pkg) "\", \"description\": \"" escape_json(trim(desc)) "\", \"site\": \"" escape_json(trim(final_site)) "\" }"
    }
    pkg = desc = site = source = ""
}' | sed 's/\\"//g' | sed 's/[[:space:]]\+/ /g' | tee "./AM.json.tmp"
jq -s 'map(select(.pkg != null and .description != null and .site != null))' "./AM.json.tmp" > "./AM.json"

The two missing entries probably got purged due to some of the filter

$ jq -r '.[].pkg' "./AM.json" | sort -u | wc -l
2119

This will likely break if AM changes the way it prints stuff to the screen. Hopefully one day there would be no need to parse shell scripts, and use something reliable like json. If nothing, this will increase speed by at least 2x-3x, when using am -q | -l