tidy-rpm-cache - a Script to Tidy a Cache of RPM Files
This page provides documentation and other information on a Python script to tidy a cache of RPM package files by deleting those that have become obsolete. This script may be useful if you wish to minimise the disk space usage of locally stored update packages.
Contents
Description
The tidy-rpm-cache.py script deletes obsolete package files by comparing the version information of all RPM files which provide the same software package. You can specify any number of paths of directories to search and you can also exclude specific packages from being tested for obsolescence.
To run this script, simply specify the path of a directory containing RPM package files using the --dir option. For example, to tidy the directory /tmp/packages, execute the following command:
$ tidy-rpm-cache.py --dir=/tmp/packages
The script will display a list of RPM packages it has deemed as obsolete and ask for confirmation before deleting them from the filesystem. To disable the confirmation message, add the --force option.
Download
The latest release of the script can be downloaded here.
About this Release
- Version #:
- 1232 (latest changes)
- Package Size:
- 20Kb
- License:
- GPLv3
- Platforms:
- Linux (RPM-based)
- Requirements:
- python and rpm-python
Installation
The script does not require any special installation procedure and can be run from any location. You may however need to execute it as root in order to be able to actually delete files. The following example shows how to copy the script to a location that is accessible by all users:
$ cd /tmp $ tar xzf tidy-rpm-cache-rev*.tar.gz $ cp tidy-rpm-cache/tidy-rpm-cache.py /usr/local/bin/
Screenshot
Click on the image below for a screenshot of the output of the script.
Getting Help
The package includes a file called README.txt which contains documentation for the script.
The command-line options for this script are summarised below and also at the top of the source file tidy-rpm-cache.py. You may wish to use the Python tool pydoc to view the documentation in the source file in a man-style format or to generate a HTML version of the documentation.
Configuration
Excluding Packages
To prevent the deletion of specific packages you can supply a regular expression which will be tested against all RPM package filenames. If the expression matches, then that RPM will be excluded from the obsolescence test. For example, to exclude all kernel packages, execute the following command:
$ tidy-rpm-cache.py --dir=/tmp/packages --exclude='^kernel.*'
Note: always enclose the regular expressions in single quotes to prevent them being interpreted as a glob expression.
Keeping Some Old Versions of Packages
You can also configure the script to keep any number of versions of a package. For example, if you wish to keep one old version of each package in, you can achieve this using the --num-obsolete option. For example:
$ tidy-rpm-cache.py --dir=/tmp/packages --num-obsolete=1
Note that the --num-obsolete option specifies the number of versions to keep excluding the newest version of the package. In the example given above, all but the recent and the second most-recent versions would be deleted.
To see more information about what the script is doing and what packages it is examining, add the --verbose option. To disable all output except warning and error messages, add the --quiet option.
For more information on these and other options, please read the help information provided with the script. You can access this by adding the --help option. For example:
$ tidy-rpm-cache.py --help
Usage Synopsis
tidy-rpm-cache.py {-d|--dir=dir}
{-n|--num-obsolete=number}
{-x|--exclude=reg-ex}
{-f|--force}
{--ignore-arch}
{--ignore-file-errors}
{--log-prefix=text}
{-s|--srpm}
{-u|--usage} {-h|--help} {--version}
{-v|--verbose} {-q|--quiet}
License
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
For a copy of the GNU General Public License, see http://www.gnu.org/licenses/.
Minimising the Size of a YUM Cache
This script was written to provide functionality which is missing in the current implementation of YUM, the RPM-based software management system popular on many distributions of Linux. YUM provides an option to keep downloaded package files in a cache directory for later use but it does not automatically delete older package files when a newer version is downloaded to the cache.
The following command is shown as an example of how this script could be used to keep the size of the cache directory at a minimum. Note that the script is called twice: once to delete all obsolete packages but exclude all kernel packages; and a second time to delete all but the two most-recent versions of kernel packages. The --force should be used if running from a Cron script.
$ tidy-rpm-cache.py --dir=/var/cache/yum --exclude='kernel.*' --force $ tidy-rpm-cache.py --dir=/var/cache/yum --num-obsolete=1 --force
The functionality of this script has also been integrated into a plugin for YUM. You can read more about it on this page.
Compatibility
The code has been tested on the following system configurations:
| System # | Linux | Python | rpm-python | Result |
|---|---|---|---|---|
| 1 | Fedora 11 | 2.6 | 4.7.1 | Pass |
| 2 | Fedora 10 | 2.5.2 | 4.6.1 | Pass |
| 3 | Fedora 9 | 2.5.1 | 4.4.2.3 | Pass |
Code Updates
09/12/2009 - Revision: 1232
This revision fixes a bug where the script would exit if an incorrectly-formatted regular expression was supplied in the exclude option. The compilation of the expressions has also been improved. This revision also fixes a bug where packages with the '.' symbol in the filename were not identified as seperate packages (e.g. openoffice.org-core and openoffice.org-writer). This revision contains no other functionality changes.
09/11/2009 - Revision: 1216
Fixed a bug in the results table formatting code which could cause the program to exit unexpectedly.
26/10/2009 - Revision: 1195
The script now only compares RPM package files with the same package name and architecture. If you want to disregard the architecture attribute (i.e. go back to the old behaviour), then use the command-line option --ignore-arch.
16/10/2009: Revision 1160
Renamed the script to tidy-rpm-cache.py to clarify its purpose and to distinguish from the functionality in RPM relating to obsolete package files.
28/09/2009: Revision 1140
All warnings related to RPM headers are now printed after scanning is complete. Printing of warnings can also now be disabled.
23/06/2009: Revision 1009
Fixed a bug where obsolete versions would not be processed if only one package existed.
02/07/2008: Revision 861
This update adds the option --num-obsolete (see documentation above) to allow a specific number of obsolete versions of a package. The script output is now more informative and there have also been improvements in the memory usage and overall performance.
Links
- The freshmeat.net project page for this script. You can subscribe to a feed with information on new releases of this script here.
- The RPM project website
- The RPM Guide by on Fedora Project.