Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to silence the commit function from the python apt library?

Tags:

python

apt

I use python apt library and I would like that the commit() function doesn't produce any output.

I've searched on the web and saw that the fork function can do the trick but I don't know how to do that or if there exists another way. I don't use any GUI, I work via the terminal.

like image 835
NicoFromFrance Avatar asked Jan 16 '26 20:01

NicoFromFrance


1 Answers

The easiest solution is probably to use something like:

class LogInstallProgress(apt.progress.base.InstallProgress):
    def fork(self):
        pid = os.fork()
        if pid == 0:
            logfd = os.open("dpkg.log", os.O_RDWR | os.O_APPEND | os.O_CREAT, 0o644)
            os.dup2(logfd, 1)
            os.dup2(logfd, 2)
        return pid

and then in commit():

 cache.commit(install_progress=LogInstallProgress())

But be careful, note that deb packages may do conffile prompts and similar things, so you will want to override conffile() (and error too).

like image 114
Michael Vogt Avatar answered Jan 19 '26 18:01

Michael Vogt