Move useful function to packaging.util.

Original patch by Erik Bray as part of #11595, changed by me to improve
readability.
2 files changed