From 8b944da383a130b16de9e0ebd657f1e74fc39f39 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Fri, 7 Aug 2015 14:35:36 +0200 Subject: fix i3status config file generation thx to @hlmtre some i3status modules have no default configuration and i3status ignores them if they are requested by the user but not configured py3status was always generating an empty config for all i3status modules and this crashed i3status with a message "glob() failed" --- py3status/__init__.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/py3status/__init__.py b/py3status/__init__.py index 460a338..d3095cb 100755 --- a/py3status/__init__.py +++ b/py3status/__init__.py @@ -148,11 +148,18 @@ class I3status(Thread): # self.config = self.i3status_config_reader(i3status_config_path) - def valid_config_param(self, param_name): + def valid_config_param(self, param_name, cleanup=False): """ Check if a given section name is a valid parameter for i3status. """ - valid_config_params = self.i3status_module_names + ['general', 'order'] + if cleanup: + valid_config_params = [ _ for _ in self.i3status_module_names if _ not in [ + 'cpu_usage', 'ddate', 'load', 'time' + ]] + else: + valid_config_params = self.i3status_module_names + [ + 'general', 'order' + ] return param_name.split(' ')[0] in valid_config_params @staticmethod @@ -318,6 +325,14 @@ class I3status(Thread): ) ) + # cleanup unconfigured i3status modules that have no default + for module_name in deepcopy(config['order']): + if (self.valid_config_param(module_name, cleanup=True) and + not config.get(module_name)): + config.pop(module_name) + config['i3s_modules'].remove(module_name) + config['order'].remove(module_name) + return config def set_responses(self, json_list): @@ -484,7 +499,7 @@ class I3status(Thread): tmpfile ) self.write_in_tmpfile('\n', tmpfile) - elif self.valid_config_param(section_name): + elif self.valid_config_param(section_name) and conf: self.write_in_tmpfile('%s {\n' % section_name, tmpfile) for key, value in conf.items(): self.write_in_tmpfile( -- cgit v1.3