Comparing text strings

Mats Wichmann mats at wichmann.us
Tue Apr 13 12:05:30 EDT 2021


On 4/12/21 5:11 PM, Rich Shepard wrote:
> I'm running Slackware64-14.2 and keep a list of installed packages. When a
> package is upgraded I want to remove the earlier version, and I've not
> before written a script like this. Could there be a module or tool that
> already exists to do this? If not, which string function would be best
> suited to the task?
> 
> Here's an example:
> atftp-0.7.2-x86_64-2_SBo.tgz
> atftp-0.7.4-x86_64-1_SBo.tgz
> 
> and there are others like this. I want the python3 script to remove the
> first one. Tools like like 'find' or 'sort -u' won't work because while the
> file name is the same the version or build numbers differ.

Yes, you've identified why this is hard: package versioning takes many 
forms.  As suggested elsewhere, for Linux distribution packages, the 
only reliable approach is to lean on the distro's packaging 
infrastructure in some way, because those version strings (plus package 
metadata which may have "replaces" or "obsoletes" or some similar 
information) all have a defined meaning to *it* - it's the intended 
audience.

Don't know if Slack exposes this information in some way, it may be hard 
to make a reliable script if not. I know Debian actually does what 
you're looking for as a feature of the packaging system (apt-get 
autoclean), and the Fedora/RedHat universe does not, so I've also looked 
for what you're looking for :)



More information about the Python-list mailing list