mirror of
https://github.com/powerline/powerline.git
synced 2025-07-24 22:36:01 +02:00
Handle removed and then added files
Note: if user configuration was removed, but global configuration was not it will start tracking global configuration file for changes.
This commit is contained in:
parent
4d1dc0658b
commit
b7c61f8bf6
@ -163,6 +163,8 @@ class Powerline(object):
|
|||||||
self.configs_lock = Lock()
|
self.configs_lock = Lock()
|
||||||
self.shutdown_event = Event()
|
self.shutdown_event = Event()
|
||||||
self.configs = defaultdict(set)
|
self.configs = defaultdict(set)
|
||||||
|
self.missing = defaultdict(set)
|
||||||
|
|
||||||
self.thread = None
|
self.thread = None
|
||||||
|
|
||||||
self.renderer_options = {}
|
self.renderer_options = {}
|
||||||
@ -171,6 +173,7 @@ class Powerline(object):
|
|||||||
|
|
||||||
self.prev_common_config = None
|
self.prev_common_config = None
|
||||||
self.prev_ext_config = None
|
self.prev_ext_config = None
|
||||||
|
self.pl = None
|
||||||
|
|
||||||
self.create_renderer(load_main=True, load_colors=True, load_colorscheme=True, load_theme=True)
|
self.create_renderer(load_main=True, load_colors=True, load_colorscheme=True, load_theme=True)
|
||||||
|
|
||||||
@ -218,7 +221,8 @@ class Powerline(object):
|
|||||||
self.logger.setLevel(level)
|
self.logger.setLevel(level)
|
||||||
self.logger.addHandler(handler)
|
self.logger.addHandler(handler)
|
||||||
|
|
||||||
self.pl = PowerlineState(self.use_daemon_threads, self.logger, self.ext)
|
if not self.pl:
|
||||||
|
self.pl = PowerlineState(self.use_daemon_threads, self.logger, self.ext)
|
||||||
|
|
||||||
self.renderer_options.update(
|
self.renderer_options.update(
|
||||||
pl=self.pl,
|
pl=self.pl,
|
||||||
@ -321,7 +325,12 @@ class Powerline(object):
|
|||||||
|
|
||||||
def _load_config(self, cfg_path, type):
|
def _load_config(self, cfg_path, type):
|
||||||
'''Load configuration and setup watcher.'''
|
'''Load configuration and setup watcher.'''
|
||||||
path = find_config_file(self.config_paths, cfg_path)
|
try:
|
||||||
|
path = find_config_file(self.config_paths, cfg_path)
|
||||||
|
except IOError:
|
||||||
|
with self.configs_lock:
|
||||||
|
self.missing[type].add(cfg_path)
|
||||||
|
raise
|
||||||
with self.configs_lock:
|
with self.configs_lock:
|
||||||
self.configs[type].add(path)
|
self.configs[type].add(path)
|
||||||
self.watcher.watch(path)
|
self.watcher.watch(path)
|
||||||
@ -418,6 +427,14 @@ class Powerline(object):
|
|||||||
for path in paths:
|
for path in paths:
|
||||||
if self.watcher(path):
|
if self.watcher(path):
|
||||||
kwargs['load_' + type] = True
|
kwargs['load_' + type] = True
|
||||||
|
for type, cfg_paths in self.missing.items():
|
||||||
|
for cfg_path in cfg_paths:
|
||||||
|
try:
|
||||||
|
find_config_file(self.config_paths, cfg_path)
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
kwargs['load_' + type] = True
|
||||||
if kwargs:
|
if kwargs:
|
||||||
try:
|
try:
|
||||||
self.create_renderer(**kwargs)
|
self.create_renderer(**kwargs)
|
||||||
|
@ -149,6 +149,8 @@ def load_json_config(config_file_path, *args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def find_config_file(search_paths, config_file):
|
def find_config_file(search_paths, config_file):
|
||||||
|
if config_file.endswith('raise') and config_file not in config:
|
||||||
|
raise IOError('fcf:' + config_file)
|
||||||
return config_file
|
return config_file
|
||||||
|
|
||||||
|
|
||||||
@ -280,6 +282,30 @@ class TestConfigReload(TestCase):
|
|||||||
self.assertEqual(p.logger._pop_msgs(), [])
|
self.assertEqual(p.logger._pop_msgs(), [])
|
||||||
self.assertEqual(p.renderer.local_themes, 'something')
|
self.assertEqual(p.renderer.local_themes, 'something')
|
||||||
|
|
||||||
|
def test_reload_unexistent(self):
|
||||||
|
with get_powerline(run_once=False) as p:
|
||||||
|
with replace_item(globals(), 'config', deepcopy(config)):
|
||||||
|
self.assertAccessEvents('config', 'colors', 'colorschemes/test/default', 'themes/test/default')
|
||||||
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
||||||
|
|
||||||
|
config['config']['ext']['test']['colorscheme'] = 'nonexistentraise'
|
||||||
|
add_watcher_events(p, 'config')
|
||||||
|
self.assertAccessEvents('config')
|
||||||
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
||||||
|
self.assertEqual(p.logger._pop_msgs(), ['test:Failed to create renderer: fcf:colorschemes/test/nonexistentraise'])
|
||||||
|
|
||||||
|
config['colorschemes/test/nonexistentraise'] = {
|
||||||
|
'groups': {
|
||||||
|
"str1": {"fg": "col1", "bg": "col3", "attr": ["bold"]},
|
||||||
|
"str2": {"fg": "col2", "bg": "col4", "attr": ["underline"]},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
while not p._created_renderer():
|
||||||
|
sleep(0.000001)
|
||||||
|
self.assertAccessEvents('colorschemes/test/nonexistentraise')
|
||||||
|
self.assertEqual(p.render(), '<1 3 1> s<3 4 False>>><2 4 4>g<4 False False>>><None None None>')
|
||||||
|
self.assertEqual(p.logger._pop_msgs(), [])
|
||||||
|
|
||||||
def test_reload_colors(self):
|
def test_reload_colors(self):
|
||||||
with get_powerline(run_once=False) as p:
|
with get_powerline(run_once=False) as p:
|
||||||
with replace_item(globals(), 'config', deepcopy(config)):
|
with replace_item(globals(), 'config', deepcopy(config)):
|
||||||
@ -290,6 +316,7 @@ class TestConfigReload(TestCase):
|
|||||||
add_watcher_events(p, 'colors')
|
add_watcher_events(p, 'colors')
|
||||||
self.assertAccessEvents('colors')
|
self.assertAccessEvents('colors')
|
||||||
self.assertEqual(p.render(), '<5 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
self.assertEqual(p.render(), '<5 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
||||||
|
self.assertEqual(p.logger._pop_msgs(), [])
|
||||||
|
|
||||||
def test_reload_colorscheme(self):
|
def test_reload_colorscheme(self):
|
||||||
with get_powerline(run_once=False) as p:
|
with get_powerline(run_once=False) as p:
|
||||||
@ -301,6 +328,7 @@ class TestConfigReload(TestCase):
|
|||||||
add_watcher_events(p, 'colorschemes/test/default')
|
add_watcher_events(p, 'colorschemes/test/default')
|
||||||
self.assertAccessEvents('colorschemes/test/default')
|
self.assertAccessEvents('colorschemes/test/default')
|
||||||
self.assertEqual(p.render(), '<1 3 1> s<3 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
self.assertEqual(p.render(), '<1 3 1> s<3 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
||||||
|
self.assertEqual(p.logger._pop_msgs(), [])
|
||||||
|
|
||||||
def test_reload_theme(self):
|
def test_reload_theme(self):
|
||||||
with get_powerline(run_once=False) as p:
|
with get_powerline(run_once=False) as p:
|
||||||
@ -312,6 +340,7 @@ class TestConfigReload(TestCase):
|
|||||||
add_watcher_events(p, 'themes/test/default')
|
add_watcher_events(p, 'themes/test/default')
|
||||||
self.assertAccessEvents('themes/test/default')
|
self.assertAccessEvents('themes/test/default')
|
||||||
self.assertEqual(p.render(), '<1 2 1> col3<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
self.assertEqual(p.render(), '<1 2 1> col3<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
||||||
|
self.assertEqual(p.logger._pop_msgs(), [])
|
||||||
|
|
||||||
|
|
||||||
replaces = {
|
replaces = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user