I introduce to you Cleaner Markup Language (also called CleanerML), BleachBit's new cleaner definition system based on XML. Originally all cleaners were written in Python code. For a new project, that was fine, but BleachBit has grown and matured. Most cleaners can be defined by labels, descriptions, and three types of actions, so they are best written as documents instead of as code. The new system allows easier contributions, uses better code design, and provides a platform for future enhancements.
Writing your own cleaner
To write your own cleaner, start by reviewing the existing CleanerML files, the example, and the XML Schema. They are all included in the source package starting with BleachBit 0.4.0 (coming soon). Until the release, you can check out the SVN trunk.
The markup language is simple and should be intuitive. Here's a graphic representation of the Bash history cleaner:
To validate your cleaner, copy it to the cleaners directory in the source tree, and then run:
make pretty make tests
Using your own cleaners
Simply name the cleaner with the extension .xml and place it in ~/.config/bleachbit/cleaners or /usr/share/cleaners. If you are running BleachBit from the source tree, you can also use the relative path ./cleaners/.
Submitting a cleaner
Want to share your cleaner with others? Follow this checklist:
- It cleans a significant amount of disk space or removes files that potentially contain private information
- It follows the guidelines in the example_cleaner.xml
- It passes XML Schema validation
Good? Then, submit it like a code contribution.
The whole CleanerML system may have taken more work than you think. Beyond the basics of simply parsing CleanerML, many other pieces were necessary:
- Defining CleanerML
- Writing an XML Schema to validate CleanerML
- Writing a generic system for performing actions (different ways of deleting files)
- Writing a system to extract text from CleanerML for translation
- Extending the translation extraction to suppress strings of proper nouns that should not be translated such as Bash and GIMP
- Conceived and implementing a security system to prevent tampering
- Adding makefile targets to reformat and to validate CleanerML
- Creating an example CleanerML with annotations
- Converting many of the existing cleaners to the new system
- Writing guidelines for cleaner labels and descriptions
- Updating descriptions to meet new guidelines
- Updating translations for those descriptions
- Writing this article :)
All this work has delayed the weekly release cycle.
Now that cleaners are documents, one of the next steps is creating a simple graphical interface for users to create their own cleaners.
With all the new cleaners, the BleachBit user interface feels cluttered. The likely next step is extending CleanerML to define categories and extending the UI to filter by those categories.