I have the following problem: I wrote a script, that extracts information about the installed packages of my system (Ubuntu 16.04 LTS). I am particularly interested in the source of the package. This means, that the data of APT-Sources from apt show <packagename> is crucial for me.
As of now, my script has to call apt show for every single installed package which creates an almost unacceptable workload in comparison to how small of a task this should be [the CPU load reaches almost 100%].
I was hoping, that there was some file on the system, that has all the information stored, that is output by apt show. Reading and parsing that file should be faster than calling apt show thousands of times. Is there such a file?
Please note, that I already tried to use dpkgand apt-cache, but both do not provide the APT-Sources information.
edit: Maybe some elaboration might be useful. My Python script calls apt list --installed to get the list of installed packages and parses this output into a list, containing only the package names as strings.
Then it calls apt show for every element in this list.
I would have liked, to only have a single file, read once, that contains information about the installed packages. I then would have my script parse this file, add the information to the list element and be done in one iteration. My hope was, that reading a large file once and parsing it, is faster than calling a CLI command many hundreds of times.
As such, I assume, that greping over multiple files multiple times would not really decrease the workload.
apt show git | grep Sourcesthat's not in the output ofapt-cache policy git. – muru Jul 20 '17 at 07:16/var/cache/apt/I can't find anything I could directly parse in my script. For example runninggrep -r "Sources" *inside/var/cache/apt/gives me nothing. Is there a non-binary file, that would provide the info? – KyuMirthu Jul 20 '17 at 07:45APT-Sources(and inapt-cache policy) is essentially the name of a file/var/lib/apt/lists: Compare output ofgrep 'Package: git' /var/lib/apt/lists/*_Packages -l | awk -F'[/_]' '{printf "http://%s/%s %s/%s %s %s\n", $6, $7, $9, $10, $11, $12}'– muru Jul 20 '17 at 07:54apt list, you're already doing it wrong. APT has a Python API: https://apt.alioth.debian.org/python-apt-doc/ What do you need it for, anyway? – muru Jul 20 '17 at 07:59rpmandzypperwhere enough to get all the information we could wish for). – KyuMirthu Jul 20 '17 at 08:02