Skip to content
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

Issue with parsing apk list --installed #1027

Open
shomodj opened this issue Nov 6, 2023 · 0 comments
Open

Issue with parsing apk list --installed #1027

shomodj opened this issue Nov 6, 2023 · 0 comments
Labels
Bug Label for all kind of bugs. Facts Issues with facts.

Comments

@shomodj
Copy link

shomodj commented Nov 6, 2023

Describe the bug

When parsing installed alpine linux packages, the parser is skipping some packages due to the incomplete regex which results in pyinfra constantly trying to install a package that is already installed on the system

To Reproduce

Attached is the list of all the weird versions I quickly found on my system, note the openssh-server-9.3_p2-r0 x86_64 or syslinux-6.04_pre1-r13 x86_64 and less-633-r0

Expected behavior

Returned list of packages in the APK Fact class should return the same number of packages as apk list -I

Meta

Some weird examples

acct-6.6.4-r2 x86_64 {acct} (GPL-3.0-or-later) [installed]
alpine-keys-2.4-r1 x86_64 {alpine-keys} (MIT) [installed]
argon2-libs-20190702-r4 x86_64 {argon2} (Apache-2.0 OR CC0-1.0) [installed]
busybox-openrc-1.36.1-r5 x86_64 {busybox} (GPL-2.0-only) [installed]
ca-certificates-20230506-r0 x86_64 {ca-certificates} (MPL-2.0 AND MIT) [installed]
ca-certificates-bundle-20230506-r0 x86_64 {ca-certificates} (MPL-2.0 AND MIT) [installed]
chrony-4.3-r4 x86_64 {chrony} (GPL-2.0-or-later) [installed]
chrony-openrc-4.3-r4 x86_64 {chrony} (GPL-2.0-or-later) [installed]
coreutils-9.3-r1 x86_64 {coreutils} (GPL-3.0-or-later) [installed]
device-mapper-event-libs-2.03.21-r3 x86_64 {lvm2} (GPL-2.0-or-later AND LGPL-2.1-or-later AND BSD-2-Clause) [installed]
kmod-30-r3 x86_64 {kmod} (GPL-2.0-or-later) [installed]
kmod-libs-30-r3 x86_64 {kmod} (LGPL-2.1-or-later) [installed]
less-633-r0 x86_64 {less} (GPL-3.0-or-later OR BSD-2-Clause) [installed]
libedit-20221030.3.1-r1 x86_64 {libedit} (BSD-3-Clause) [installed]
libgcc-12.2.1_git20220924-r10 x86_64 {gcc} (GPL-2.0-or-later AND LGPL-2.1-or-later) [installed]
libncursesw-6.4_p20230506-r0 x86_64 {ncurses} (X11) [installed]
libpanelw-6.4_p20230506-r0 x86_64 {ncurses} (X11) [installed]
libstdc++-12.2.1_git20220924-r10 x86_64 {gcc} (GPL-2.0-or-later AND LGPL-2.1-or-later) [installed]
linux-firmware-none-20230515-r6 x86_64 {linux-firmware} (custom) [installed]
ncurses-terminfo-base-6.4_p20230506-r0 x86_64 {ncurses} (X11) [installed]
openssh-client-common-9.3_p2-r0 x86_64 {openssh} (BSD) [installed]
openssh-server-9.3_p2-r0 x86_64 {openssh} (BSD) [installed]
py3-certifi-2023.7.22-r0 x86_64 {py3-certifi} (MPL-2.0) [installed]
py3-certifi-pyc-2023.7.22-r0 x86_64 {py3-certifi} (MPL-2.0) [installed]
salt-3006.1-r0 x86_64 {salt} (Apache-2.0) [installed]
salt-minion-3006.1-r0 x86_64 {salt} (Apache-2.0) [installed]
syslinux-6.04_pre1-r13 x86_64 {syslinux} (GPL-2.0-or-later) [installed]
utmps-libs-0.1.2.1-r1 x86_64 {utmps} (ISC) [installed]

This is the best I could do, I don't think its even humanly possible to write a correct regex for this, that is why I split it into parts and searched for part which begins with a number in order to find where name and version were split

import re

with open("list.txt") as fh:
    lines = fh.readlines()

    packages = dict()

    for line in lines:
        line = line.strip()
        columns = line.split(" ")
        name_and_version = columns[0]
        parts = name_and_version.split("-")

        idx = 1
        while idx < len(parts):
            if re.match(r"^\d", parts[idx]):
                name = "-".join(parts[0:idx])
                version = "-".join(parts[idx:])
                packages[name] = version

            idx += 1

    print(packages)
@shomodj shomodj added the Bug Label for all kind of bugs. label Nov 6, 2023
@Fizzadar Fizzadar added the Facts Issues with facts. label Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Label for all kind of bugs. Facts Issues with facts.
Projects
None yet
Development

No branches or pull requests

2 participants