Add autoremove function to aptpkg.py

Resolves #18369.