def handle_purge(self, config): days = config.get('assets.purge.days') size_filter = config.get('assets.purge.size_filter') overall_limit = config.get('assets.purge.overall_limit') if self._count_filter_args(config) != 1: msg = ("You should choose --by-size-filter or --by-days. " "For help, run: avocado assets purge --help") LOG_UI.error(msg) return exit_codes.AVOCADO_FAIL cache_dirs = config.get('datadir.paths.cache_dirs') try: if days is not None: Asset.remove_assets_by_unused_for_days(days, cache_dirs) elif size_filter is not None: Asset.remove_assets_by_size(size_filter, cache_dirs) elif overall_limit is not None: try: size = DataSize(overall_limit).b Asset.remove_assets_by_overall_limit(size, cache_dirs) except InvalidDataSize: error_msg = "You are using an invalid suffix. " error_msg += "Use one of the following values: " error_msg += ",".join(DataSize.MULTIPLIERS.keys()) LOG_UI.error(error_msg) return exit_codes.AVOCADO_FAIL except (FileNotFoundError, OSError) as e: LOG_UI.error("Could not remove asset: %s", e) return exit_codes.AVOCADO_FAIL return exit_codes.AVOCADO_ALL_OK
def handle_purge(self, config): days = config.get('assets.purge.days') size_filter = config.get('assets.purge.size_filter') if (days is None and size_filter is None) \ or (days is not None and size_filter is not None): msg = ("You should choose --by-size-filter or --by-days. " "For help, run: avocado assets purge --help") LOG_UI.error(msg) return cache_dirs = data_dir.get_cache_dirs() try: if days is not None: Asset.remove_assets_by_unused_for_days(days, cache_dirs) elif size_filter is not None: Asset.remove_assets_by_size(size_filter, cache_dirs) except (FileNotFoundError, OSError) as e: LOG_UI.error("Could not remove asset: %s", e)