Skip to content

Commit

Permalink
main: Add command line switch to clear all known settings/caches
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Feb 14, 2022
1 parent 5f098bf commit f48e5e1
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions Orange/canvas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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
Expand Down

0 comments on commit f48e5e1

Please sign in to comment.