Thursday, September 21, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  1] [ 0]  / answers: 1 / hits: 2171  / 1 Year ago, fri, august 26, 2022, 10:22:46

The Ubuntu software center is able to display a detailed history of packages installed /updated/removed according to date.

  1. Where does it get this info from? (/var/log/dpkg.log is maintained only for 12 months; I don't know of any apt-* or dpkg commands to get the date when a package was first installed.)

  2. How can I copy this data in the form of a table / text to be processed by another program?

More From » apt


Thought the specifics are fairly useless, Unless you want to find out exactly what changes were made to the system on a specific day and time, I felt the steps I went through to discover this information were worth documenting:

I ran strace -e trace=open -f -o usc software-center to get a list of all the files opened by the software center. Then I filtered it like this.

cat usc| grep -oP '(?<=open(").*(?=",)' |egrep -v '.(so.([0-9]|cache)|so|pyc|mo|py|png|svg)$'|egrep -v '/usr/lib/(python2.7|x86|girepo)'| egrep -v '/usr/share/(icons|themes)' |egrep -v '/etc/fonts'|egrep -v '(screenshots|reviews)' |egrep -v fontconfig |sort -u

to eliminate all the files didn't contain data files.

Among these I found the interesting looking looking file: ~/.cache/software-center/apthistory.p It looked like a python pickle file when I opened it. trying to load the file I got the error that softwarecenter.db.history_impl.apthistory was not imported. I ran the following command to look for python files that ere opened and had "softwarecenter" in their path

$cat usc| grep -oP '(?<=open(").*(?=",)' |grep softwarecenter

and got a whole bunch of filenames including /usr/share/software-center/softwarecenter/db/history_impl/ I wrote the following script to read and process file:

import sys
import os
import pickle

import softwarecenter.db.history_impl.apthistory

with open(os.path.expanduser('~/.cache/software-center/apthistory.p')) as IFile:

print type(hist[0])
print "earliest apt transaction started on:",hist[-1].start_date
print "installed:"
for PackageStr in hist[-1].install:
print PackageStr
print "upgraded:"
for PackageStr in hist[-1].upgrade:
print PackageStr

I found the necessary attributes by looking up the class of which hist[0] was an instance of: help(softwarecenter.db.history_impl.apthistory.AptTransaction). This lead me to the parent class help( softwarecenter.db.history.Transaction) from where I figured out how to use it.

Btw even sudo apt-get installed stuff appears here.

[#29296] Sunday, August 28, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 52
Total Questions: 112
Total Answers: 113

Location: Marshall Islands
Member since Tue, Sep 21, 2021
2 Years ago