From c94d1ca48ae07c71606bf1dc48917a3128ee0440 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Mon, 14 Nov 2005 09:43:27 +0000 Subject: [PATCH] function to update the config file from version to version I currently update some var names, add new themes and remove cyan theme, add new proxies, add new emoticons If things are missing add them there --- src/common/optparser.py | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/common/optparser.py b/src/common/optparser.py index c73abc947..4bb7d331a 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -26,6 +26,8 @@ _ = i18n._ class OptionsParser: def __init__(self, filename): self.__filename = filename + self.old_values = {} # values that are saved in the file and maybe + # no longer valid def read_line(self, line): index = line.find(' = ') @@ -36,6 +38,7 @@ class OptionsParser: i_end = var_str.rfind('.') if i_start == -1: + self.old_values[var_str] = value_str gajim.config.set(var_str, value_str) else: optname = var_str[0:i_start] @@ -53,12 +56,17 @@ class OptionsParser: print _('error: cannot open %s for reading') % self.__filename return + new_version = gajim.config.get('version') for line in fd.readlines(): try: line = line.decode('utf-8') except UnicodeDecodeError: line = line.decode(locale.getpreferredencoding()) self.read_line(line) + old_version = gajim.config.get('version') + + self.update_config(old_version, new_version) + self.old_values = {} # clean mem fd.close() @@ -116,3 +124,53 @@ class OptionsParser: except IOError, e: return e.errno os.chmod(self.__filename, 0600) + + def update_config(self, old_version, new_version): + if old_version < '0.9' and new_version == '0.9': + self.update_config_x_to_09() + + def update_config_x_to_09(self): + # Var name that changed: + # avatar_width /height -> chat_avatar_width / height + if self.old_values.has_key('avatar_width'): + gajim.config.set('chat_avatar_width', self.old_values['avatar_width']) + if self.old_values.has_key('avatar_height'): + gajim.config.set('chat_avatar_height', self.old_values['avatar_height']) + # always_compact_view -> always_compact_view_chat / _gc + if self.old_values.has_key('always_compact_view'): + gajim.config.set('always_compact_view_chat', + self.old_values['always_compact_view']) + gajim.config.set('always_compact_view_gc', + self.old_values['always_compact_view']) + # new theme: grocery, plain + d = ['accounttextcolor', 'accountbgcolor', 'accountfont', + 'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont', + 'groupfontattrs', 'contacttextcolor', 'contactbgcolor', 'contactfont', + 'contactfontattrs', 'bannertextcolor', 'bannerbgcolor'] + for theme_name in ['grocery', 'plain']: + if theme_name not in gajim.config.get_per('themes'): + gajim.config.add_per('themes', theme_name) + theme = gajim.config.themes_default[theme_name] + for o in d: + gajim.config.set_per('themes', theme_name, o, theme[d.index(o)]) + # Remove cyan theme if it's not the default theme + if gajim.config.get('roster_theme') != 'cyan' and \ + 'cyan' in gajim.config.get_per('themes'): + gajim.config.del_per('themes', 'cyan') + # new proxies in accounts.name.file_transfer_proxies + for account in gajim.config.get_per('accounts'): + proxies = gajim.config.get_per('accounts', account, + 'file_transfer_proxies') + for new in ['proxy.netlab.cz', 'proxy65.jabber.ccc.de', + 'proxy65.unstable.nl']: + if proxies.find(new) < 0: + proxies += ', ' + new + gajim.config.set_per('accounts', account,'file_transfer_proxies', + proxies) + # Add some emots :-* :* >:) >:-) <3 + for emot in [':-*', ':*', '>:)', '>:-)', '<3']: + if emot not in gajim.config.get_per('emoticons'): + gajim.config.add_per('emoticons', emot) + gajim.config.set_per('emoticons', emot, 'path', + gajim.config.emoticons_default[emot]) + gajim.config.set('version', '0.9')