gajim

view src/common/optparser.py @ 10773:1076fc9700f5

merge elghinn's branch (roster versioning) to trunk. Fixes #4661, #3190
author Yann Leboulanger <asterix@lagaule.org>
date Fri, 10 Jul 2009 15:05:01 +0200
parents d079ffe7bb5a 4e609a89ac14
children b765732974a5 d07ff24ba073
line source
1 # -*- coding:utf-8 -*-
2 ## src/common/optparser.py
3 ##
4 ## Copyright (C) 2003-2005 Vincent Hanquez <tab AT snarc.org>
5 ## Copyright (C) 2003-2008 Yann Leboulanger <asterix AT lagaule.org>
6 ## Copyright (C) 2005-2006 Dimitur Kirov <dkirov AT gmail.com>
7 ## Nikos Kouremenos <kourem AT gmail.com>
8 ## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
9 ## Copyright (C) 2007 James Newton <redshodan AT gmail.com>
10 ## Brendan Taylor <whateley AT gmail.com>
11 ## Tomasz Melcer <liori AT exroot.org>
12 ## Stephan Erb <steve-e AT h3c.de>
13 ##
14 ## This file is part of Gajim.
15 ##
16 ## Gajim is free software; you can redistribute it and/or modify
17 ## it under the terms of the GNU General Public License as published
18 ## by the Free Software Foundation; version 3 only.
19 ##
20 ## Gajim is distributed in the hope that it will be useful,
21 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ## GNU General Public License for more details.
24 ##
25 ## You should have received a copy of the GNU General Public License
26 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
27 ##
29 import os
30 import locale
31 import re
32 from common import gajim
33 from common import helpers
35 import exceptions
36 try:
37 import sqlite3 as sqlite # python 2.5
38 except ImportError:
39 try:
40 from pysqlite2 import dbapi2 as sqlite
41 except ImportError:
42 raise exceptions.PysqliteNotAvailable
43 import logger
45 class OptionsParser:
46 def __init__(self, filename):
47 self.__filename = filename
48 self.old_values = {} # values that are saved in the file and maybe
49 # no longer valid
51 def read(self):
52 try:
53 fd = open(self.__filename)
54 except Exception:
55 if os.path.exists(self.__filename):
56 #we talk about a file
57 print _('error: cannot open %s for reading') % self.__filename
58 return False
60 new_version = gajim.config.get('version')
61 new_version = new_version.split('-', 1)[0]
62 seen = set()
63 regex = re.compile(r"(?P<optname>[^.]+)(?:(?:\.(?P<key>.+))?\.(?P<subname>[^.]+))?\s=\s(?P<value>.*)")
65 for line in fd:
66 try:
67 line = line.decode('utf-8')
68 except UnicodeDecodeError:
69 line = line.decode(locale.getpreferredencoding())
70 optname, key, subname, value = regex.match(line).groups()
71 if key is None:
72 self.old_values[optname] = value
73 gajim.config.set(optname, value)
74 else:
75 if (optname, key) not in seen:
76 gajim.config.add_per(optname, key)
77 seen.add((optname, key))
78 gajim.config.set_per(optname, key, subname, value)
80 old_version = gajim.config.get('version')
81 old_version = old_version.split('-', 1)[0]
83 self.update_config(old_version, new_version)
84 self.old_values = {} # clean mem
86 fd.close()
87 return True
89 def write_line(self, fd, opt, parents, value):
90 if value is None:
91 return
92 value = value[1]
93 # convert to utf8 before writing to file if needed
94 if isinstance(value, unicode):
95 value = value.encode('utf-8')
96 else:
97 value = str(value)
98 if isinstance(opt, unicode):
99 opt = opt.encode('utf-8')
100 s = ''
101 if parents:
102 if len(parents) == 1:
103 return
104 for p in parents:
105 if isinstance(p, unicode):
106 p = p.encode('utf-8')
107 s += p + '.'
108 s += opt
109 fd.write(s + ' = ' + value + '\n')
111 def write(self):
112 (base_dir, filename) = os.path.split(self.__filename)
113 self.__tempfile = os.path.join(base_dir, '.' + filename)
114 try:
115 f = open(self.__tempfile, 'w')
116 except IOError, e:
117 return str(e)
118 try:
119 gajim.config.foreach(self.write_line, f)
120 except IOError, e:
121 return str(e)
122 f.close()
123 if os.path.exists(self.__filename):
124 # win32 needs this
125 try:
126 os.remove(self.__filename)
127 except Exception:
128 pass
129 try:
130 os.rename(self.__tempfile, self.__filename)
131 except IOError, e:
132 return str(e)
133 os.chmod(self.__filename, 0600)
135 def update_config(self, old_version, new_version):
136 old_version_list = old_version.split('.') # convert '0.x.y' to (0, x, y)
137 old = []
138 while len(old_version_list):
139 old.append(int(old_version_list.pop(0)))
140 new_version_list = new_version.split('.')
141 new = []
142 while len(new_version_list):
143 new.append(int(new_version_list.pop(0)))
145 if old < [0, 9] and new >= [0, 9]:
146 self.update_config_x_to_09()
147 if old < [0, 10] and new >= [0, 10]:
148 self.update_config_09_to_010()
149 if old < [0, 10, 1, 1] and new >= [0, 10, 1, 1]:
150 self.update_config_to_01011()
151 if old < [0, 10, 1, 2] and new >= [0, 10, 1, 2]:
152 self.update_config_to_01012()
153 if old < [0, 10, 1, 3] and new >= [0, 10, 1, 3]:
154 self.update_config_to_01013()
155 if old < [0, 10, 1, 4] and new >= [0, 10, 1, 4]:
156 self.update_config_to_01014()
157 if old < [0, 10, 1, 5] and new >= [0, 10, 1, 5]:
158 self.update_config_to_01015()
159 if old < [0, 10, 1, 6] and new >= [0, 10, 1, 6]:
160 self.update_config_to_01016()
161 if old < [0, 10, 1, 7] and new >= [0, 10, 1, 7]:
162 self.update_config_to_01017()
163 if old < [0, 10, 1, 8] and new >= [0, 10, 1, 8]:
164 self.update_config_to_01018()
165 if old < [0, 11, 0, 1] and new >= [0, 11, 0, 1]:
166 self.update_config_to_01101()
167 if old < [0, 11, 0, 2] and new >= [0, 11, 0, 2]:
168 self.update_config_to_01102()
169 if old < [0, 11, 1, 1] and new >= [0, 11, 1, 1]:
170 self.update_config_to_01111()
171 if old < [0, 11, 1, 2] and new >= [0, 11, 1, 2]:
172 self.update_config_to_01112()
173 if old < [0, 11, 1, 3] and new >= [0, 11, 1, 3]:
174 self.update_config_to_01113()
175 if old < [0, 11, 1, 4] and new >= [0, 11, 1, 4]:
176 self.update_config_to_01114()
177 if old < [0, 11, 1, 5] and new >= [0, 11, 1, 5]:
178 self.update_config_to_01115()
179 if old < [0, 11, 2, 1] and new >= [0, 11, 2, 1]:
180 self.update_config_to_01121()
181 if old < [0, 11, 4, 1] and new >= [0, 11, 4, 1]:
182 self.update_config_to_01141()
183 if old < [0, 11, 4, 2] and new >= [0, 11, 4, 2]:
184 self.update_config_to_01142()
185 if old < [0, 11, 4, 3] and new >= [0, 11, 4, 3]:
186 self.update_config_to_01143()
187 if old < [0, 11, 4, 4] and new >= [0, 11, 4, 4]:
188 self.update_config_to_01144()
189 if old < [0, 12, 0, 1] and new >= [0, 12, 0, 1]:
190 self.update_config_to_01201()
191 if old < [0, 12, 1, 1] and new >= [0, 12, 1, 1]:
192 self.update_config_to_01211()
193 if old < [0, 12, 1, 2] and new >= [0, 12, 1, 2]:
194 self.update_config_to_01212()
195 if old < [0, 12, 1, 3] and new >= [0, 12, 1, 3]:
196 self.update_config_to_01213()
197 if old < [0, 12, 1, 4] and new >= [0, 12, 1, 4]:
198 self.update_config_to_01214()
199 if old < [0, 12, 1, 5] and new >= [0, 12, 1, 5]:
200 self.update_config_to_01215()
201 if old < [0, 12, 3, 1] and new >= [0, 12, 3, 1]:
202 self.update_config_to_01231()
204 gajim.logger.init_vars()
205 gajim.config.set('version', new_version)
207 gajim.capscache.load_from_db()
209 def update_config_x_to_09(self):
210 # Var name that changed:
211 # avatar_width /height -> chat_avatar_width / height
212 if 'avatar_width' in self.old_values:
213 gajim.config.set('chat_avatar_width', self.old_values['avatar_width'])
214 if 'avatar_height' in self.old_values:
215 gajim.config.set('chat_avatar_height', self.old_values['avatar_height'])
216 if 'use_dbus' in self.old_values:
217 gajim.config.set('remote_control', self.old_values['use_dbus'])
218 # always_compact_view -> always_compact_view_chat / _gc
219 if 'always_compact_view' in self.old_values:
220 gajim.config.set('always_compact_view_chat',
221 self.old_values['always_compact_view'])
222 gajim.config.set('always_compact_view_gc',
223 self.old_values['always_compact_view'])
224 # new theme: grocery, plain
225 d = ['accounttextcolor', 'accountbgcolor', 'accountfont',
226 'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont',
227 'groupfontattrs', 'contacttextcolor', 'contactbgcolor', 'contactfont',
228 'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont',
229 'bannerfontattrs']
230 for theme_name in (_('grocery'), _('default')):
231 if theme_name not in gajim.config.get_per('themes'):
232 gajim.config.add_per('themes', theme_name)
233 theme = gajim.config.themes_default[theme_name]
234 for o in d:
235 gajim.config.set_per('themes', theme_name, o, theme[d.index(o)])
236 # Remove cyan theme if it's not the current theme
237 if 'cyan' in gajim.config.get_per('themes'):
238 gajim.config.del_per('themes', 'cyan')
239 if _('cyan') in gajim.config.get_per('themes'):
240 gajim.config.del_per('themes', _('cyan'))
241 # If we removed our roster_theme, choose the default green one or another
242 # one if doesn't exists in config
243 if gajim.config.get('roster_theme') not in gajim.config.get_per('themes'):
244 theme = _('green')
245 if theme not in gajim.config.get_per('themes'):
246 theme = gajim.config.get_per('themes')[0]
247 gajim.config.set('roster_theme', theme)
248 # new proxies in accounts.name.file_transfer_proxies
249 for account in gajim.config.get_per('accounts'):
250 proxies = gajim.config.get_per('accounts', account,
251 'file_transfer_proxies')
252 if proxies.find('proxy.netlab.cz') < 0:
253 proxies += ', ' + 'proxy.netlab.cz'
254 gajim.config.set_per('accounts', account, 'file_transfer_proxies',
255 proxies)
257 gajim.config.set('version', '0.9')
259 def assert_unread_msgs_table_exists(self):
260 '''create table unread_messages if there is no such table'''
261 back = os.getcwd()
262 os.chdir(logger.LOG_DB_FOLDER)
263 con = sqlite.connect(logger.LOG_DB_FILE)
264 os.chdir(back)
265 cur = con.cursor()
266 try:
267 cur.executescript(
268 '''
269 CREATE TABLE unread_messages (
270 message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
271 jid_id INTEGER
272 );
273 '''
274 )
275 con.commit()
276 gajim.logger.init_vars()
277 except sqlite.OperationalError:
278 pass
279 con.close()
281 def update_config_09_to_010(self):
282 if 'usetabbedchat' in self.old_values and not \
283 self.old_values['usetabbedchat']:
284 gajim.config.set('one_message_window', 'never')
285 if 'autodetect_browser_mailer' in self.old_values and \
286 self.old_values['autodetect_browser_mailer'] is True:
287 gajim.config.set('autodetect_browser_mailer', False)
288 if 'useemoticons' in self.old_values and \
289 not self.old_values['useemoticons']:
290 gajim.config.set('emoticons_theme', '')
291 if 'always_compact_view_chat' in self.old_values and \
292 self.old_values['always_compact_view_chat'] != 'False':
293 gajim.config.set('always_hide_chat_buttons', True)
294 if 'always_compact_view_gc' in self.old_values and \
295 self.old_values['always_compact_view_gc'] != 'False':
296 gajim.config.set('always_hide_groupchat_buttons', True)
298 for account in gajim.config.get_per('accounts'):
299 proxies_str = gajim.config.get_per('accounts', account,
300 'file_transfer_proxies')
301 proxies = proxies_str.split(',')
302 for i in range(0, len(proxies)):
303 proxies[i] = proxies[i].strip()
304 for wrong_proxy in ('proxy65.jabber.autocom.pl',
305 'proxy65.jabber.ccc.de'):
306 if wrong_proxy in proxies:
307 proxies.remove(wrong_proxy)
308 if not 'transfer.jabber.freenet.de' in proxies:
309 proxies.append('transfer.jabber.freenet.de')
310 proxies_str = ', '.join(proxies)
311 gajim.config.set_per('accounts', account, 'file_transfer_proxies',
312 proxies_str)
313 # create unread_messages table if needed
314 self.assert_unread_msgs_table_exists()
316 gajim.config.set('version', '0.10')
318 def update_config_to_01011(self):
319 if 'print_status_in_muc' in self.old_values and \
320 self.old_values['print_status_in_muc'] in (True, False):
321 gajim.config.set('print_status_in_muc', 'in_and_out')
322 gajim.config.set('version', '0.10.1.1')
324 def update_config_to_01012(self):
325 # See [6456]
326 if 'emoticons_theme' in self.old_values and \
327 self.old_values['emoticons_theme'] == 'Disabled':
328 gajim.config.set('emoticons_theme', '')
329 gajim.config.set('version', '0.10.1.2')
331 def update_config_to_01013(self):
332 '''create table transports_cache if there is no such table'''
333 #FIXME see #2812
334 back = os.getcwd()
335 os.chdir(logger.LOG_DB_FOLDER)
336 con = sqlite.connect(logger.LOG_DB_FILE)
337 os.chdir(back)
338 cur = con.cursor()
339 try:
340 cur.executescript(
341 '''
342 CREATE TABLE transports_cache (
343 transport TEXT UNIQUE,
344 type INTEGER
345 );
346 '''
347 )
348 con.commit()
349 except sqlite.OperationalError:
350 pass
351 con.close()
352 gajim.config.set('version', '0.10.1.3')
354 def update_config_to_01014(self):
355 '''apply indeces to the logs database'''
356 print _('migrating logs database to indices')
357 #FIXME see #2812
358 back = os.getcwd()
359 os.chdir(logger.LOG_DB_FOLDER)
360 con = sqlite.connect(logger.LOG_DB_FILE)
361 os.chdir(back)
362 cur = con.cursor()
363 # apply indeces
364 try:
365 cur.executescript(
366 '''
367 CREATE INDEX idx_logs_jid_id_kind ON logs (jid_id, kind);
368 CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id);
369 '''
370 )
372 con.commit()
373 except Exception:
374 pass
375 con.close()
376 gajim.config.set('version', '0.10.1.4')
378 def update_config_to_01015(self):
379 '''clean show values in logs database'''
380 #FIXME see #2812
381 back = os.getcwd()
382 os.chdir(logger.LOG_DB_FOLDER)
383 con = sqlite.connect(logger.LOG_DB_FILE)
384 os.chdir(back)
385 cur = con.cursor()
386 status = dict((i[5:].lower(), logger.constants.__dict__[i]) for i in \
387 logger.constants.__dict__.keys() if i.startswith('SHOW_'))
388 for show in status:
389 cur.execute('update logs set show = ? where show = ?;', (status[show],
390 show))
391 cur.execute('update logs set show = NULL where show not in (0, 1, 2, 3, 4, 5);')
392 con.commit()
393 cur.close() # remove this in 2007 [pysqlite old versions need this]
394 con.close()
395 gajim.config.set('version', '0.10.1.5')
397 def update_config_to_01016(self):
398 '''#2494 : Now we play gc_received_message sound even if
399 notify_on_all_muc_messages is false. Keep precedent behaviour.'''
400 if 'notify_on_all_muc_messages' in self.old_values and \
401 self.old_values['notify_on_all_muc_messages'] == 'False' and \
402 gajim.config.get_per('soundevents', 'muc_message_received', 'enabled'):
403 gajim.config.set_per('soundevents',\
404 'muc_message_received', 'enabled', False)
405 gajim.config.set('version', '0.10.1.6')
407 def update_config_to_01017(self):
408 '''trayicon_notification_on_new_messages ->
409 trayicon_notification_on_events '''
410 if 'trayicon_notification_on_new_messages' in self.old_values:
411 gajim.config.set('trayicon_notification_on_events',
412 self.old_values['trayicon_notification_on_new_messages'])
413 gajim.config.set('version', '0.10.1.7')
415 def update_config_to_01018(self):
416 '''chat_state_notifications -> outgoing_chat_state_notifications'''
417 if 'chat_state_notifications' in self.old_values:
418 gajim.config.set('outgoing_chat_state_notifications',
419 self.old_values['chat_state_notifications'])
420 gajim.config.set('version', '0.10.1.8')
422 def update_config_to_01101(self):
423 '''fill time_stamp from before_time and after_time'''
424 if 'before_time' in self.old_values:
425 gajim.config.set('time_stamp', '%s%%X%s ' % (
426 self.old_values['before_time'], self.old_values['after_time']))
427 gajim.config.set('version', '0.11.0.1')
429 def update_config_to_01102(self):
430 '''fill time_stamp from before_time and after_time'''
431 if 'ft_override_host_to_send' in self.old_values:
432 gajim.config.set('ft_add_hosts_to_send',
433 self.old_values['ft_override_host_to_send'])
434 gajim.config.set('version', '0.11.0.2')
436 def update_config_to_01111(self):
437 '''always_hide_chatbuttons -> compact_view'''
438 if 'always_hide_groupchat_buttons' in self.old_values and \
439 'always_hide_chat_buttons' in self.old_values:
440 gajim.config.set('compact_view', self.old_values['always_hide_groupchat_buttons'] and \
441 self.old_values['always_hide_chat_buttons'])
442 gajim.config.set('version', '0.11.1.1')
444 def update_config_to_01112(self):
445 '''gtk+ theme is renamed to default'''
446 if 'roster_theme' in self.old_values and \
447 self.old_values['roster_theme'] == 'gtk+':
448 gajim.config.set('roster_theme', _('default'))
449 gajim.config.set('version', '0.11.1.2')
451 def update_config_to_01113(self):
452 # copy&pasted from update_config_to_01013, possibly 'FIXME see #2812' applies too
453 back = os.getcwd()
454 os.chdir(logger.LOG_DB_FOLDER)
455 con = sqlite.connect(logger.LOG_DB_FILE)
456 os.chdir(back)
457 cur = con.cursor()
458 try:
459 cur.executescript(
460 '''
461 CREATE TABLE caps_cache (
462 node TEXT,
463 ver TEXT,
464 ext TEXT,
465 data BLOB
466 );
467 '''
468 )
469 con.commit()
470 except sqlite.OperationalError:
471 pass
472 con.close()
473 gajim.config.set('version', '0.11.1.3')
475 def update_config_to_01114(self):
476 # add default theme if it doesn't exist
477 d = ['accounttextcolor', 'accountbgcolor', 'accountfont',
478 'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont',
479 'groupfontattrs', 'contacttextcolor', 'contactbgcolor', 'contactfont',
480 'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont',
481 'bannerfontattrs']
482 theme_name = _('default')
483 if theme_name not in gajim.config.get_per('themes'):
484 gajim.config.add_per('themes', theme_name)
485 if gajim.config.get_per('themes', 'gtk+'):
486 # copy from old gtk+ theme
487 for o in d:
488 val = gajim.config.get_per('themes', 'gtk+', o)
489 gajim.config.set_per('themes', theme_name, o, val)
490 gajim.config.del_per('themes', 'gtk+')
491 else:
492 # copy from default theme
493 theme = gajim.config.themes_default[theme_name]
494 for o in d:
495 gajim.config.set_per('themes', theme_name, o, theme[d.index(o)])
496 gajim.config.set('version', '0.11.1.4')
498 def update_config_to_01115(self):
499 # copy&pasted from update_config_to_01013, possibly 'FIXME see #2812' applies too
500 back = os.getcwd()
501 os.chdir(logger.LOG_DB_FOLDER)
502 con = sqlite.connect(logger.LOG_DB_FILE)
503 os.chdir(back)
504 cur = con.cursor()
505 try:
506 cur.executescript(
507 '''
508 DELETE FROM caps_cache;
509 '''
510 )
511 con.commit()
512 except sqlite.OperationalError:
513 pass
514 con.close()
515 gajim.config.set('version', '0.11.1.5')
517 def update_config_to_01121(self):
518 # remove old unencrypted secrets file
519 from common.configpaths import gajimpaths
521 new_file = gajimpaths['SECRETS_FILE']
523 old_file = os.path.dirname(new_file) + '/secrets'
525 if os.path.exists(old_file):
526 os.remove(old_file)
528 gajim.config.set('version', '0.11.2.1')
530 def update_config_to_01141(self):
531 back = os.getcwd()
532 os.chdir(logger.LOG_DB_FOLDER)
533 con = sqlite.connect(logger.LOG_DB_FILE)
534 os.chdir(back)
535 cur = con.cursor()
536 try:
537 cur.executescript(
538 '''
539 CREATE TABLE IF NOT EXISTS caps_cache (
540 node TEXT,
541 ver TEXT,
542 ext TEXT,
543 data BLOB
544 );
545 '''
546 )
547 con.commit()
548 except sqlite.OperationalError:
549 pass
550 con.close()
551 gajim.config.set('version', '0.11.4.1')
553 def update_config_to_01142(self):
554 '''next_message_received sound event is splittedin 2 events'''
555 gajim.config.add_per('soundevents', 'next_message_received_focused')
556 gajim.config.add_per('soundevents', 'next_message_received_unfocused')
557 if gajim.config.get_per('soundevents', 'next_message_received'):
558 enabled = gajim.config.get_per('soundevents', 'next_message_received',
559 'enabled')
560 path = gajim.config.get_per('soundevents', 'next_message_received',
561 'path')
562 gajim.config.del_per('soundevents', 'next_message_received')
563 gajim.config.set_per('soundevents', 'next_message_received_focused',
564 'enabled', enabled)
565 gajim.config.set_per('soundevents', 'next_message_received_focused',
566 'path', path)
567 gajim.config.set('version', '0.11.1.2')
569 def update_config_to_01143(self):
570 back = os.getcwd()
571 os.chdir(logger.LOG_DB_FOLDER)
572 con = sqlite.connect(logger.LOG_DB_FILE)
573 os.chdir(back)
574 cur = con.cursor()
575 try:
576 cur.executescript(
577 '''
578 CREATE TABLE IF NOT EXISTS rooms_last_message_time(
579 jid_id INTEGER PRIMARY KEY UNIQUE,
580 time INTEGER
581 );
582 '''
583 )
584 con.commit()
585 except sqlite.OperationalError:
586 pass
587 con.close()
588 gajim.config.set('version', '0.11.4.3')
590 def update_config_to_01144(self):
591 back = os.getcwd()
592 os.chdir(logger.LOG_DB_FOLDER)
593 con = sqlite.connect(logger.LOG_DB_FILE)
594 os.chdir(back)
595 cur = con.cursor()
596 try:
597 cur.executescript('DROP TABLE caps_cache;')
598 con.commit()
599 except sqlite.OperationalError:
600 pass
601 try:
602 cur.executescript(
603 '''
604 CREATE TABLE caps_cache (
605 hash_method TEXT,
606 hash TEXT,
607 data BLOB
608 );
609 '''
610 )
611 con.commit()
612 except sqlite.OperationalError, e:
613 pass
614 con.close()
615 gajim.config.set('version', '0.11.4.4')
617 def update_config_to_01201(self):
618 if 'uri_schemes' in self.old_values:
619 new_values = self.old_values['uri_schemes'].replace(' mailto', '').\
620 replace(' xmpp', '')
621 gajim.config.set('uri_schemes', new_values)
622 gajim.config.set('version', '0.12.0.1')
624 def update_config_to_01211(self):
625 if 'trayicon' in self.old_values:
626 if self.old_values['trayicon'] == 'False':
627 gajim.config.set('trayicon', 'never')
628 else:
629 gajim.config.set('trayicon', 'always')
630 gajim.config.set('version', '0.12.1.1')
632 def update_config_to_01212(self):
633 for opt in ('ignore_unknown_contacts', 'send_os_info',
634 'log_encrypted_sessions'):
635 if opt in self.old_values:
636 val = self.old_values[opt]
637 for account in gajim.config.get_per('accounts'):
638 gajim.config.set_per('accounts', account, opt, val)
639 gajim.config.set('version', '0.12.1.2')
641 def update_config_to_01213(self):
642 msgs = gajim.config.statusmsg_default
643 for msg_name in gajim.config.get_per('statusmsg'):
644 if msg_name in msgs:
645 gajim.config.set_per('statusmsg', msg_name, 'activity',
646 msgs[msg_name][1])
647 gajim.config.set_per('statusmsg', msg_name, 'subactivity',
648 msgs[msg_name][2])
649 gajim.config.set_per('statusmsg', msg_name, 'activity_text',
650 msgs[msg_name][3])
651 gajim.config.set_per('statusmsg', msg_name, 'mood',
652 msgs[msg_name][4])
653 gajim.config.set_per('statusmsg', msg_name, 'mood_text',
654 msgs[msg_name][5])
655 gajim.config.set('version', '0.12.1.3')
657 def update_config_to_01214(self):
658 for status in ['online', 'chat', 'away', 'xa', 'dnd', 'invisible',
659 'offline']:
660 gajim.config.add_per('statusmsg', '_last_' + status)
661 gajim.config.set_per('statusmsg', '_last_' + status, 'message',
662 self.old_values['last_status_msg_' + status])
663 gajim.config.set('version', '0.12.1.4')
665 def update_config_to_01215(self):
666 '''Remove hardcoded ../data/sounds from config'''
667 dirs = ('../data', gajim.gajimpaths.root, gajim.DATA_DIR)
668 for evt in gajim.config.get_per('soundevents'):
669 path = gajim.config.get_per('soundevents', evt ,'path')
670 # absolute and relative passes are necessary
671 path = helpers.strip_soundfile_path(path, dirs, abs=False)
672 path = helpers.strip_soundfile_path(path, dirs, abs=True)
673 gajim.config.set_per('soundevents', evt, 'path', path)
674 gajim.config.set('version', '0.12.1.5')
676 def update_config_to_01231(self):
677 back = os.getcwd()
678 os.chdir(logger.LOG_DB_FOLDER)
679 con = sqlite.connect(logger.LOG_DB_FILE)
680 os.chdir(back)
681 cur = con.cursor()
682 try:
683 cur.executescript(
684 '''
685 CREATE TABLE IF NOT EXISTS roster_entry(
686 account_jid_id INTEGER,
687 jid_id INTEGER,
688 name TEXT,
689 subscription INTEGER,
690 ask BOOLEAN,
691 PRIMARY KEY (account_jid_id, jid_id)
692 );
694 CREATE TABLE IF NOT EXISTS roster_group(
695 account_jid_id INTEGER,
696 jid_id INTEGER,
697 group_name TEXT,
698 PRIMARY KEY (account_jid_id, jid_id, group_name)
699 );
700 '''
701 )
702 con.commit()
703 except sqlite.OperationalError:
704 pass
705 con.close()
706 gajim.config.set('version', '0.12.3.1')
711 # vim: se ts=3: