Analysis of apt-get install output for progress bar

I am working on a simple GUI Python script to perform some simple tasks on the system. Some of these works include apt-get install to install some packages.

While this is happening, I want to display a progress bar, which should be updated with the download progress using the small percentage shown in the apt-get interface in the terminal.

BUT! I cannot find a way to get progress information. Piping or redirecting the output of apt-get simply gives static lines that show the message “completed download” for each package, as well as for reading through subprocess.Popen() in my script.

How can I read from the apt-get output to get the percentages of the downloaded file?

+6
python subprocess popen progress-bar apt-get
source share
2 answers

As I said, use pexpect , not a subprocess, etc. when you need to get a continuous exit. pexpect tricks the subprocess into believing that it works on the terminal, so the subprocess will only provide the kind of output it will give on the real terminal ... and you can catch it and turn it into any kind of fantasy you want! )

+3
source share

Instead of parsing the output of apt-get, you can use python-apt to install packages. AFAIK also has modules for reporting progress.

+5
source share

All Articles