Sunday, March 13, 2022

[SOLVED] python-apt package, obtain time pkg was installed and build time?

Issue

Is it possible to obtain the time a package was installed as well as the build time for that particular package?

For example:

import apt

def get_pkg_details():
    apt_cache = apt.Cache()
    selected_pkg = apt_cache["git"] #Example package

    time_installed = selected_pkg.installedTime() #?????

I know this is possible with RPM but I haven't found any documentation on anything similar to this on APT.

In RPM the install time of a package and build time can be accessed with the following enumerators:

RPMTAG_INSTALLTIME 
RPMTAG_BUILDTIME

python-apt Docs: http://stuff.mit.edu/afs/athena/system/i386_deb50/os/usr/share/doc/python-apt/html/apt/package.html#examples

RPM Tag API: http://rpm.org/api/4.6.0/group__rpmtag.html


Solution

I maintain part of a code that is distributed through an apt-server, so i have had to deal with this issue as well, for a basic idea of the time of build of a package I get the mtime os.path.getmtime() of the package... /var/lib/dpkg/info/PACKAGE

the line of my code also turns it into a datetime object.

datetime.datetime.fromtimestamp(os.path.getmtime("PATH"))


Answered By - Inbar Rose
Answer Checked By - Cary Denson (WPSolving Admin)