kuuko pushed a commit to branch master. http://git.enlightenment.org/apps/econnman.git/commit/?id=240c1a38b5d7888bc2331f705d53070494760e03
commit 240c1a38b5d7888bc2331f705d53070494760e03 Author: Matthias Wauer <matthiaswa...@googlemail.com> Date: Fri Dec 13 17:27:00 2013 +0000 Only try to load config file for 802.1x when used. Econnman will only try to read/write the config file, when necessary. It also displays an error message, when the file couldn't be read/written. --- econnman-bin.in | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/econnman-bin.in b/econnman-bin.in index 1e14dbd..e2d5956 100755 --- a/econnman-bin.in +++ b/econnman-bin.in @@ -254,11 +254,25 @@ class ObjectView(object): ####################################################################### # Config Files Helper: +def config_file_setup(): + configs = configparser.RawConfigParser() + configs.optionxform = str + try: + fd = open(CONFIG_FILE, 'r', encoding='utf8') + configs.readfp(fd) + close(fd) + except IOError: + popup_error(win, "Cannot read configuration file", "Econnman cannot read the coniguration file \"" + CONF_FILE + "\", used by connman to configure your ieee802.1x networks. Make sure the user running connman is able to read/write it.") + configs = None + pass + def config_del(name): secname = 'service_' + name if configs == None: - log.error("Config file was not parsed!") - return + try: + config_file_setup() + except IOError: + return if not configs.has_section(secname): configs.remove_section(secname) config_write(name) @@ -266,8 +280,10 @@ def config_del(name): def config_set(name, key, value): secname = 'service_' + name if configs == None: - log.error("Config file was not parsed!") - return + try: + config_file_setup() + except IOError: + return if not configs.has_section(secname): configs.add_section(secname) configs.set(secname, 'Type', 'wifi') @@ -280,8 +296,10 @@ def config_set(name, key, value): def config_get(name): if configs == None: - log.error("Config file was not parsed!") - return None + try: + config_file_setup() + except IOError: + return None for sec in configs.sections(): if configs.has_option(sec, 'Name') and configs.get(sec, 'Name') == name: return sec @@ -295,8 +313,11 @@ def config_exists(name): return False def config_write(name): - with open(CONF_FILE, 'w', encoding='utf8') as configfile: - configs.write(configfile) + try: + with open(CONF_FILE, 'w', encoding='utf8') as configfile: + configs.write(configfile) + except IOError: + popup_error(win, "Cannot write configuration file", "Econnman cannot write the coniguration file \"" + CONF_FILE + "\", used by connman to configure your ieee802.1x networks. Make sure the user running connman is able to read/write it.") ######################################################################## # Views: @@ -1610,10 +1631,6 @@ if __name__ == "__main__": level -= 10 * args.verbose log.setLevel(level) - configs = configparser.RawConfigParser() - configs.optionxform = str - configs.read(CONF_FILE) - elm.init() elm.policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED) --