Issue
I'm using the Python APT wrapper library to write an interactive APT interface. I want to handle the case when APT prompts if to overwrite or keep a config file during apt-upgrade.
This corresponds to the following user interaction in command-line APT:
Configuration file '/var/usr/myconf.cfg'
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** myconf.cfg (Y/I/N/O/D/Z) [default=N] ? Y
Installing new version of config file var/usr/myconf.cfg ...
Status change
I've found that apt.progress.base.InstallProgress has a callback function conffile which is called when APT prompts if to overwrite.
It has the following signature:
def conffile(self, current, new):
"""(Abstract) Called when a conffile question from dpkg is detected."""
Parameters current and new are the two filepaths involved. How can I use Python APT to mark the conffile for overwrite or keep programmatically?
Solution
The Python APT library does not seem to offer any way of resolving this. I ended up writing Dpkg::Options { "–force-confnew"; }
to /etc/apt/apt.conf.d/local
which always overwrites old conf files with new ones; I couldn't spend time extending the library.
One possible solution to get more user interaction would be to execute a manual dry run with the apt-command and parse all the conffile conflicts from the console output. Then one could prompt the user for a solution for all conf files and write
/etc/apt/apt.conf.d/local
appropriately + call upgrade from the Python APT library.
Update: answerSeeker figured out a way to set these options programatically - see this post.
Answered By - Simon Lischka