From f48e5e1942c788f2506fc7741b1c3e9e637a38aa Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Mon, 14 Feb 2022 09:49:38 +0100 Subject: [PATCH] main: Add command line switch to clear all known settings/caches --- Orange/canvas/__main__.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Orange/canvas/__main__.py b/Orange/canvas/__main__.py index b84fdc55ddc..061b06512b5 100644 --- a/Orange/canvas/__main__.py +++ b/Orange/canvas/__main__.py @@ -361,12 +361,40 @@ def argument_parser(self) -> argparse.ArgumentParser: "--clear-widget-settings", action="store_true", help="Clear stored widget setting/defaults", ) + parser.add_argument( + "--clear-all", action="store_true", + help="Clear all settings and caches" + ) return parser def setup_logging(self): super().setup_logging() make_sql_logger(self.options.log_level) + def _rm_tree(self, path): + log.debug("rmtree '%s'", path) + shutil.rmtree(path, ignore_errors=True) + + def clear_widget_settings(self): + log.info("Clearing widget settings") + self._rm_tree(widget_settings_dir(versioned=True)) + self._rm_tree(widget_settings_dir(versioned=False)) + + def clear_caches(self): + from Orange.misc import environ + log.info("Clearing caches") + self._rm_tree(environ.cache_dir()) + log.info("Clearing data") + self._rm_tree(environ.data_dir(versioned=True)) + self._rm_tree(environ.data_dir(versioned=False)) + + def clear_application_settings(self): + s = QSettings() + log.info("Clearing application settings") + log.debug("clear '%s'", s.fileName()) + s.clear() + s.sync() + def setup_application(self): super().setup_application() clear_settings_flag = os.path.join(widget_settings_dir(), @@ -375,8 +403,12 @@ def setup_application(self): options = self.options if options.clear_widget_settings or \ os.path.isfile(clear_settings_flag): - log.info("Clearing widget settings") - shutil.rmtree(widget_settings_dir(), ignore_errors=True) + self.clear_widget_settings() + + if options.clear_all: + self.clear_widget_settings() + self.clear_caches() + self.clear_application_settings() notif_server = NotificationServer() canvas.notification_server_instance = notif_server