[docs]classCleanupHandler(GenericHandler):""" Base class and default implementation for the "cleanup" handler, responsible for removing old unwanted files etc. """
[docs]defcleanup_everything(self,session,dry_run=False,progress=None,**kwargs):""" Invoke cleanup logic for all enabled cleaners. """cleaners=self.get_all_cleaners()forkeyinsorted(cleaners):cleaner=cleaners[key]log.debug("running cleanup for: %s",key)cleaner.cleanup(session,dry_run=dry_run,progress=progress)
[docs]defget_all_cleaners(self,**kwargs):""" Return a dictionary containing all registered cleaner objects. """cleaners=load_entry_points('rattail.cleaners')forkeyinlist(cleaners):cleaner=cleaners[key](self.config)cleaner.key=keycleaners[key]=cleanerreturncleaners
[docs]defget_cleaner(self,key):""" Retrieve a specific cleaner object. """cleaners=self.get_all_cleaners()returncleaners.get(key)
[docs]classCleaner(object):""" Base class for cleaners. """def__init__(self,config,**kwargs):self.config=configself.app=config.get_app()self.model=self.app.model
[docs]defcleanup(self,session,dry_run=False,progress=None,**kwargs):""" Perform actual cleanup steps as needed. """