From 6a4b8bc49cf46fe1ac57c32ad2cc3d402cc610e5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 20 Nov 2013 23:51:26 +0400 Subject: [PATCH] Pass run_once to ConfigLoader, make it respect run_once It only respects run_once by using DummyWatcher instead of a watcher doing something potentially useful Ref #711 --- powerline/__init__.py | 2 +- powerline/lib/config.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/powerline/__init__.py b/powerline/__init__.py index 1689f1da..4e148f05 100644 --- a/powerline/__init__.py +++ b/powerline/__init__.py @@ -121,7 +121,7 @@ class Powerline(object): 'load_theme': True, } self.shutdown_event = shutdown_event or Event() - self.config_loader = config_loader or ConfigLoader(shutdown_event=self.shutdown_event) + self.config_loader = config_loader or ConfigLoader(shutdown_event=self.shutdown_event, run_once=run_once) self.run_loader_update = False self.renderer_options = {} diff --git a/powerline/lib/config.py b/powerline/lib/config.py index 9cf6ee4a..e826e3bf 100644 --- a/powerline/lib/config.py +++ b/powerline/lib/config.py @@ -20,11 +20,22 @@ def load_json_config(config_file_path, load=json.load, open_file=open_file): return load(config_file_fp) +class DummyWatcher(object): + def __call__(self, *args, **kwargs): + return False + + def watch(self, *args, **kwargs): + pass + + class ConfigLoader(MultiRunnedThread): - def __init__(self, shutdown_event=None, watcher=None, load=load_json_config): + def __init__(self, shutdown_event=None, watcher=None, load=load_json_config, run_once=False): super(ConfigLoader, self).__init__() self.shutdown_event = shutdown_event or Event() - self.watcher = watcher or create_file_watcher() + if run_once: + self.watcher = DummyWatcher() + else: + self.watcher = watcher or create_file_watcher() self._load = load self.pl = None