Package common :: Module optparser
[hide private]
[frames] | no frames]

Source Code for Module common.optparser

  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-2010 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  ## 
 28   
 29  import os 
 30  import sys 
 31  import locale 
 32  import re 
 33  from time import time 
 34  from common import gajim 
 35  from common import helpers 
 36  from common import caps_cache 
 37   
 38  import sqlite3 as sqlite 
 39  import logger 
 40   
41 -class OptionsParser:
42 - def __init__(self, filename):
43 self.__filename = filename 44 self.old_values = {} # values that are saved in the file and maybe
45 # no longer valid 46
47 - def read(self):
48 try: 49 fd = open(self.__filename) 50 except Exception: 51 if os.path.exists(self.__filename): 52 #we talk about a file 53 print _('error: cannot open %s for reading') % self.__filename 54 return False 55 56 new_version = gajim.config.get('version') 57 new_version = new_version.split('-', 1)[0] 58 seen = set() 59 regex = re.compile(r"(?P<optname>[^.]+)(?:(?:\.(?P<key>.+))?\.(?P<subname>[^.]+))?\s=\s(?P<value>.*)") 60 61 for line in fd: 62 try: 63 line = line.decode('utf-8') 64 except UnicodeDecodeError: 65 line = line.decode(locale.getpreferredencoding()) 66 optname, key, subname, value = regex.match(line).groups() 67 if key is None: 68 self.old_values[optname] = value 69 gajim.config.set(optname, value) 70 else: 71 if (optname, key) not in seen: 72 gajim.config.add_per(optname, key) 73 seen.add((optname, key)) 74 gajim.config.set_per(optname, key, subname, value) 75 76 old_version = gajim.config.get('version') 77 old_version = old_version.split('-', 1)[0] 78 79 self.update_config(old_version, new_version) 80 self.old_values = {} # clean mem 81 82 fd.close() 83 return True
84
85 - def write_line(self, fd, opt, parents, value):
86 if value is None: 87 return 88 value = value[1] 89 # convert to utf8 before writing to file if needed 90 if isinstance(value, unicode): 91 value = value.encode('utf-8') 92 else: 93 value = str(value) 94 if isinstance(opt, unicode): 95 opt = opt.encode('utf-8') 96 s = '' 97 if parents: 98 if len(parents) == 1: 99 return 100 for p in parents: 101 if isinstance(p, unicode): 102 p = p.encode('utf-8') 103 s += p + '.' 104 s += opt 105 fd.write(s + ' = ' + value + '\n')
106
107 - def write(self):
108 (base_dir, filename) = os.path.split(self.__filename) 109 self.__tempfile = os.path.join(base_dir, '.' + filename) 110 try: 111 f = open(self.__tempfile, 'w') 112 except IOError, e: 113 return str(e) 114 try: 115 gajim.config.foreach(self.write_line, f) 116 except IOError, e: 117 return str(e) 118 f.flush() 119 os.fsync(f.fileno()) 120 f.close() 121 if os.path.exists(self.__filename): 122 if os.name == 'nt': 123 # win32 needs this 124 try: 125 os.remove(self.__filename) 126 except Exception: 127 pass 128 try: 129 os.rename(self.__tempfile, self.__filename) 130 except IOError, e: 131 return str(e) 132 os.chmod(self.__filename, 0600)
133
134 - def update_config(self, old_version, new_version):
135 old_version_list = old_version.split('.') # convert '0.x.y' to (0, x, y) 136 old = [] 137 while len(old_version_list): 138 old.append(int(old_version_list.pop(0))) 139 new_version_list = new_version.split('.') 140 new = [] 141 while len(new_version_list): 142 new.append(int(new_version_list.pop(0))) 143 144 if old < [0, 9] and new >= [0, 9]: 145 self.update_config_x_to_09() 146 if old < [0, 10] and new >= [0, 10]: 147 self.update_config_09_to_010() 148 if old < [0, 10, 1, 1] and new >= [0, 10, 1, 1]: 149 self.update_config_to_01011() 150 if old < [0, 10, 1, 2] and new >= [0, 10, 1, 2]: 151 self.update_config_to_01012() 152 if old < [0, 10, 1, 3] and new >= [0, 10, 1, 3]: 153 self.update_config_to_01013() 154 if old < [0, 10, 1, 4] and new >= [0, 10, 1, 4]: 155 self.update_config_to_01014() 156 if old < [0, 10, 1, 5] and new >= [0, 10, 1, 5]: 157 self.update_config_to_01015() 158 if old < [0, 10, 1, 6] and new >= [0, 10, 1, 6]: 159 self.update_config_to_01016() 160 if old < [0, 10, 1, 7] and new >= [0, 10, 1, 7]: 161 self.update_config_to_01017() 162 if old < [0, 10, 1, 8] and new >= [0, 10, 1, 8]: 163 self.update_config_to_01018() 164 if old < [0, 11, 0, 1] and new >= [0, 11, 0, 1]: 165 self.update_config_to_01101() 166 if old < [0, 11, 0, 2] and new >= [0, 11, 0, 2]: 167 self.update_config_to_01102() 168 if old < [0, 11, 1, 1] and new >= [0, 11, 1, 1]: 169 self.update_config_to_01111() 170 if old < [0, 11, 1, 2] and new >= [0, 11, 1, 2]: 171 self.update_config_to_01112() 172 if old < [0, 11, 1, 3] and new >= [0, 11, 1, 3]: 173 self.update_config_to_01113() 174 if old < [0, 11, 1, 4] and new >= [0, 11, 1, 4]: 175 self.update_config_to_01114() 176 if old < [0, 11, 1, 5] and new >= [0, 11, 1, 5]: 177 self.update_config_to_01115() 178 if old < [0, 11, 2, 1] and new >= [0, 11, 2, 1]: 179 self.update_config_to_01121() 180 if old < [0, 11, 4, 1] and new >= [0, 11, 4, 1]: 181 self.update_config_to_01141() 182 if old < [0, 11, 4, 2] and new >= [0, 11, 4, 2]: 183 self.update_config_to_01142() 184 if old < [0, 11, 4, 3] and new >= [0, 11, 4, 3]: 185 self.update_config_to_01143() 186 if old < [0, 11, 4, 4] and new >= [0, 11, 4, 4]: 187 self.update_config_to_01144() 188 if old < [0, 12, 0, 1] and new >= [0, 12, 0, 1]: 189 self.update_config_to_01201() 190 if old < [0, 12, 1, 1] and new >= [0, 12, 1, 1]: 191 self.update_config_to_01211() 192 if old < [0, 12, 1, 2] and new >= [0, 12, 1, 2]: 193 self.update_config_to_01212() 194 if old < [0, 12, 1, 3] and new >= [0, 12, 1, 3]: 195 self.update_config_to_01213() 196 if old < [0, 12, 1, 4] and new >= [0, 12, 1, 4]: 197 self.update_config_to_01214() 198 if old < [0, 12, 1, 5] and new >= [0, 12, 1, 5]: 199 self.update_config_to_01215() 200 if old < [0, 12, 3, 1] and new >= [0, 12, 3, 1]: 201 self.update_config_to_01231() 202 if old < [0, 12, 5, 1] and new >= [0, 12, 5, 1]: 203 self.update_config_from_0125() 204 self.update_config_to_01251() 205 if old < [0, 12, 5, 2] and new >= [0, 12, 5, 2]: 206 self.update_config_to_01252() 207 if old < [0, 12, 5, 3] and new >= [0, 12, 5, 3]: 208 self.update_config_to_01253() 209 if old < [0, 12, 5, 4] and new >= [0, 12, 5, 4]: 210 self.update_config_to_01254() 211 if old < [0, 12, 5, 5] and new >= [0, 12, 5, 5]: 212 self.update_config_to_01255() 213 if old < [0, 12, 5, 6] and new >= [0, 12, 5, 6]: 214 self.update_config_to_01256() 215 if old < [0, 12, 5, 7] and new >= [0, 12, 5, 7]: 216 self.update_config_to_01257() 217 if old < [0, 12, 5, 8] and new >= [0, 12, 5, 8]: 218 self.update_config_to_01258() 219 if old < [0, 13, 10, 0] and new >= [0, 13, 10, 0]: 220 self.update_config_to_013100() 221 if old < [0, 13, 10, 1] and new >= [0, 13, 10, 1]: 222 self.update_config_to_013101() 223 224 gajim.logger.init_vars() 225 gajim.logger.attach_cache_database() 226 gajim.config.set('version', new_version) 227 228 caps_cache.capscache.initialize_from_db()
229
231 """ 232 Create table unread_messages if there is no such table 233 """ 234 back = os.getcwd() 235 os.chdir(logger.LOG_DB_FOLDER) 236 con = sqlite.connect(logger.LOG_DB_FILE) 237 os.chdir(back) 238 cur = con.cursor() 239 try: 240 cur.executescript( 241 ''' 242 CREATE TABLE unread_messages ( 243 message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, 244 jid_id INTEGER 245 ); 246 ''' 247 ) 248 con.commit() 249 gajim.logger.init_vars() 250 except sqlite.OperationalError: 251 pass 252 con.close()
253
254 - def update_ft_proxies(self, to_remove=[], to_add=[]):
255 for account in gajim.config.get_per('accounts'): 256 proxies_str = gajim.config.get_per('accounts', account, 257 'file_transfer_proxies') 258 proxies = [p.strip() for p in proxies_str.split(',')] 259 for wrong_proxy in to_remove: 260 if wrong_proxy in proxies: 261 proxies.remove(wrong_proxy) 262 for new_proxy in to_add: 263 if new_proxy not in proxies: 264 proxies.append(new_proxy) 265 proxies_str = ', '.join(proxies) 266 gajim.config.set_per('accounts', account, 'file_transfer_proxies', 267 proxies_str)
268
269 - def update_config_x_to_09(self):
270 # Var name that changed: 271 # avatar_width /height -> chat_avatar_width / height 272 if 'avatar_width' in self.old_values: 273 gajim.config.set('chat_avatar_width', self.old_values['avatar_width']) 274 if 'avatar_height' in self.old_values: 275 gajim.config.set('chat_avatar_height', self.old_values['avatar_height']) 276 if 'use_dbus' in self.old_values: 277 gajim.config.set('remote_control', self.old_values['use_dbus']) 278 # always_compact_view -> always_compact_view_chat / _gc 279 if 'always_compact_view' in self.old_values: 280 gajim.config.set('always_compact_view_chat', 281 self.old_values['always_compact_view']) 282 gajim.config.set('always_compact_view_gc', 283 self.old_values['always_compact_view']) 284 # new theme: grocery, plain 285 d = ['accounttextcolor', 'accountbgcolor', 'accountfont', 286 'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont', 287 'groupfontattrs', 'contacttextcolor', 'contactbgcolor', 'contactfont', 288 'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont', 289 'bannerfontattrs'] 290 for theme_name in (_('grocery'), _('default')): 291 if theme_name not in gajim.config.get_per('themes'): 292 gajim.config.add_per('themes', theme_name) 293 theme = gajim.config.themes_default[theme_name] 294 for o in d: 295 gajim.config.set_per('themes', theme_name, o, theme[d.index(o)]) 296 # Remove cyan theme if it's not the current theme 297 if 'cyan' in gajim.config.get_per('themes'): 298 gajim.config.del_per('themes', 'cyan') 299 if _('cyan') in gajim.config.get_per('themes'): 300 gajim.config.del_per('themes', _('cyan')) 301 # If we removed our roster_theme, choose the default green one or another 302 # one if doesn't exists in config 303 if gajim.config.get('roster_theme') not in gajim.config.get_per('themes'): 304 theme = _('green') 305 if theme not in gajim.config.get_per('themes'): 306 theme = gajim.config.get_per('themes')[0] 307 gajim.config.set('roster_theme', theme) 308 # new proxies in accounts.name.file_transfer_proxies 309 self.update_ft_proxies(to_add=['proxy.netlab.cz']) 310 311 gajim.config.set('version', '0.9')
312
313 - def update_config_09_to_010(self):
314 if 'usetabbedchat' in self.old_values and not \ 315 self.old_values['usetabbedchat']: 316 gajim.config.set('one_message_window', 'never') 317 if 'autodetect_browser_mailer' in self.old_values and \ 318 self.old_values['autodetect_browser_mailer'] is True: 319 gajim.config.set('autodetect_browser_mailer', False) 320 if 'useemoticons' in self.old_values and \ 321 not self.old_values['useemoticons']: 322 gajim.config.set('emoticons_theme', '') 323 if 'always_compact_view_chat' in self.old_values and \ 324 self.old_values['always_compact_view_chat'] != 'False': 325 gajim.config.set('always_hide_chat_buttons', True) 326 if 'always_compact_view_gc' in self.old_values and \ 327 self.old_values['always_compact_view_gc'] != 'False': 328 gajim.config.set('always_hide_groupchat_buttons', True) 329 330 self.update_ft_proxies(to_remove=['proxy65.jabber.autocom.pl', 331 'proxy65.jabber.ccc.de'], to_add=['transfer.jabber.freenet.de']) 332 # create unread_messages table if needed 333 self.assert_unread_msgs_table_exists() 334 335 gajim.config.set('version', '0.10')
336
337 - def update_config_to_01011(self):
338 if 'print_status_in_muc' in self.old_values and \ 339 self.old_values['print_status_in_muc'] in (True, False): 340 gajim.config.set('print_status_in_muc', 'in_and_out') 341 gajim.config.set('version', '0.10.1.1')
342
343 - def update_config_to_01012(self):
344 # See [6456] 345 if 'emoticons_theme' in self.old_values and \ 346 self.old_values['emoticons_theme'] == 'Disabled': 347 gajim.config.set('emoticons_theme', '') 348 gajim.config.set('version', '0.10.1.2')
349
350 - def update_config_to_01013(self):
351 """ 352 Create table transports_cache if there is no such table 353 """ 354 # FIXME see #2812 355 back = os.getcwd() 356 os.chdir(logger.LOG_DB_FOLDER) 357 con = sqlite.connect(logger.LOG_DB_FILE) 358 os.chdir(back) 359 cur = con.cursor() 360 try: 361 cur.executescript( 362 ''' 363 CREATE TABLE transports_cache ( 364 transport TEXT UNIQUE, 365 type INTEGER 366 ); 367 ''' 368 ) 369 con.commit() 370 except sqlite.OperationalError: 371 pass 372 con.close() 373 gajim.config.set('version', '0.10.1.3')
374
375 - def update_config_to_01014(self):
376 """ 377 Apply indeces to the logs database 378 """ 379 print _('migrating logs database to indices') 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 # apply indeces 387 try: 388 cur.executescript( 389 ''' 390 CREATE INDEX idx_logs_jid_id_kind ON logs (jid_id, kind); 391 CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id); 392 ''' 393 ) 394 395 con.commit() 396 except Exception: 397 pass 398 con.close() 399 gajim.config.set('version', '0.10.1.4')
400
401 - def update_config_to_01015(self):
402 """ 403 Clean show values in logs database 404 """ 405 #FIXME see #2812 406 back = os.getcwd() 407 os.chdir(logger.LOG_DB_FOLDER) 408 con = sqlite.connect(logger.LOG_DB_FILE) 409 os.chdir(back) 410 cur = con.cursor() 411 status = dict((i[5:].lower(), logger.constants.__dict__[i]) for i in \ 412 logger.constants.__dict__.keys() if i.startswith('SHOW_')) 413 for show in status: 414 cur.execute('update logs set show = ? where show = ?;', (status[show], 415 show)) 416 cur.execute('update logs set show = NULL where show not in (0, 1, 2, 3, 4, 5);') 417 con.commit() 418 cur.close() # remove this in 2007 [pysqlite old versions need this] 419 con.close() 420 gajim.config.set('version', '0.10.1.5')
421
422 - def update_config_to_01016(self):
423 """ 424 #2494 : Now we play gc_received_message sound even if 425 notify_on_all_muc_messages is false. Keep precedent behaviour 426 """ 427 if 'notify_on_all_muc_messages' in self.old_values and \ 428 self.old_values['notify_on_all_muc_messages'] == 'False' and \ 429 gajim.config.get_per('soundevents', 'muc_message_received', 'enabled'): 430 gajim.config.set_per('soundevents',\ 431 'muc_message_received', 'enabled', False) 432 gajim.config.set('version', '0.10.1.6')
433
434 - def update_config_to_01017(self):
435 """ 436 trayicon_notification_on_new_messages -> trayicon_notification_on_events 437 """ 438 if 'trayicon_notification_on_new_messages' in self.old_values: 439 gajim.config.set('trayicon_notification_on_events', 440 self.old_values['trayicon_notification_on_new_messages']) 441 gajim.config.set('version', '0.10.1.7')
442
443 - def update_config_to_01018(self):
444 """ 445 chat_state_notifications -> outgoing_chat_state_notifications 446 """ 447 if 'chat_state_notifications' in self.old_values: 448 gajim.config.set('outgoing_chat_state_notifications', 449 self.old_values['chat_state_notifications']) 450 gajim.config.set('version', '0.10.1.8')
451
452 - def update_config_to_01101(self):
453 """ 454 Fill time_stamp from before_time and after_time 455 """ 456 if 'before_time' in self.old_values: 457 gajim.config.set('time_stamp', '%s%%X%s ' % ( 458 self.old_values['before_time'], self.old_values['after_time'])) 459 gajim.config.set('version', '0.11.0.1')
460
461 - def update_config_to_01102(self):
462 """ 463 Fill time_stamp from before_time and after_time 464 """ 465 if 'ft_override_host_to_send' in self.old_values: 466 gajim.config.set('ft_add_hosts_to_send', 467 self.old_values['ft_override_host_to_send']) 468 gajim.config.set('version', '0.11.0.2')
469
470 - def update_config_to_01111(self):
471 """ 472 Always_hide_chatbuttons -> compact_view 473 """ 474 if 'always_hide_groupchat_buttons' in self.old_values and \ 475 'always_hide_chat_buttons' in self.old_values: 476 gajim.config.set('compact_view', self.old_values['always_hide_groupchat_buttons'] and \ 477 self.old_values['always_hide_chat_buttons']) 478 gajim.config.set('version', '0.11.1.1')
479
480 - def update_config_to_01112(self):
481 """ 482 GTK+ theme is renamed to default 483 """ 484 if 'roster_theme' in self.old_values and \ 485 self.old_values['roster_theme'] == 'gtk+': 486 gajim.config.set('roster_theme', _('default')) 487 gajim.config.set('version', '0.11.1.2')
488
489 - def update_config_to_01113(self):
490 # copy&pasted from update_config_to_01013, possibly 'FIXME see #2812' applies too 491 back = os.getcwd() 492 os.chdir(logger.LOG_DB_FOLDER) 493 con = sqlite.connect(logger.LOG_DB_FILE) 494 os.chdir(back) 495 cur = con.cursor() 496 try: 497 cur.executescript( 498 ''' 499 CREATE TABLE caps_cache ( 500 node TEXT, 501 ver TEXT, 502 ext TEXT, 503 data BLOB 504 ); 505 ''' 506 ) 507 con.commit() 508 except sqlite.OperationalError: 509 pass 510 con.close() 511 gajim.config.set('version', '0.11.1.3')
512
513 - def update_config_to_01114(self):
514 # add default theme if it doesn't exist 515 d = ['accounttextcolor', 'accountbgcolor', 'accountfont', 516 'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont', 517 'groupfontattrs', 'contacttextcolor', 'contactbgcolor', 'contactfont', 518 'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont', 519 'bannerfontattrs'] 520 theme_name = _('default') 521 if theme_name not in gajim.config.get_per('themes'): 522 gajim.config.add_per('themes', theme_name) 523 if gajim.config.get_per('themes', 'gtk+'): 524 # copy from old gtk+ theme 525 for o in d: 526 val = gajim.config.get_per('themes', 'gtk+', o) 527 gajim.config.set_per('themes', theme_name, o, val) 528 gajim.config.del_per('themes', 'gtk+') 529 else: 530 # copy from default theme 531 theme = gajim.config.themes_default[theme_name] 532 for o in d: 533 gajim.config.set_per('themes', theme_name, o, theme[d.index(o)]) 534 gajim.config.set('version', '0.11.1.4')
535
536 - def update_config_to_01115(self):
537 # copy&pasted from update_config_to_01013, possibly 'FIXME see #2812' applies too 538 back = os.getcwd() 539 os.chdir(logger.LOG_DB_FOLDER) 540 con = sqlite.connect(logger.LOG_DB_FILE) 541 os.chdir(back) 542 cur = con.cursor() 543 try: 544 cur.executescript( 545 ''' 546 DELETE FROM caps_cache; 547 ''' 548 ) 549 con.commit() 550 except sqlite.OperationalError: 551 pass 552 con.close() 553 gajim.config.set('version', '0.11.1.5')
554
555 - def update_config_to_01121(self):
556 # remove old unencrypted secrets file 557 from common.configpaths import gajimpaths 558 559 new_file = gajimpaths['SECRETS_FILE'] 560 561 old_file = os.path.dirname(new_file) + '/secrets' 562 563 if os.path.exists(old_file): 564 os.remove(old_file) 565 566 gajim.config.set('version', '0.11.2.1')
567
568 - def update_config_to_01141(self):
569 back = os.getcwd() 570 os.chdir(logger.LOG_DB_FOLDER) 571 con = sqlite.connect(logger.LOG_DB_FILE) 572 os.chdir(back) 573 cur = con.cursor() 574 try: 575 cur.executescript( 576 ''' 577 CREATE TABLE IF NOT EXISTS caps_cache ( 578 node TEXT, 579 ver TEXT, 580 ext TEXT, 581 data BLOB 582 ); 583 ''' 584 ) 585 con.commit() 586 except sqlite.OperationalError: 587 pass 588 con.close() 589 gajim.config.set('version', '0.11.4.1')
590
591 - def update_config_to_01142(self):
592 """ 593 next_message_received sound event is splittedin 2 events 594 """ 595 gajim.config.add_per('soundevents', 'next_message_received_focused') 596 gajim.config.add_per('soundevents', 'next_message_received_unfocused') 597 if gajim.config.get_per('soundevents', 'next_message_received'): 598 enabled = gajim.config.get_per('soundevents', 'next_message_received', 599 'enabled') 600 path = gajim.config.get_per('soundevents', 'next_message_received', 601 'path') 602 gajim.config.del_per('soundevents', 'next_message_received') 603 gajim.config.set_per('soundevents', 'next_message_received_focused', 604 'enabled', enabled) 605 gajim.config.set_per('soundevents', 'next_message_received_focused', 606 'path', path) 607 gajim.config.set('version', '0.11.1.2')
608
609 - def update_config_to_01143(self):
610 back = os.getcwd() 611 os.chdir(logger.LOG_DB_FOLDER) 612 con = sqlite.connect(logger.LOG_DB_FILE) 613 os.chdir(back) 614 cur = con.cursor() 615 try: 616 cur.executescript( 617 ''' 618 CREATE TABLE IF NOT EXISTS rooms_last_message_time( 619 jid_id INTEGER PRIMARY KEY UNIQUE, 620 time INTEGER 621 ); 622 ''' 623 ) 624 con.commit() 625 except sqlite.OperationalError: 626 pass 627 con.close() 628 gajim.config.set('version', '0.11.4.3')
629
630 - def update_config_to_01144(self):
631 back = os.getcwd() 632 os.chdir(logger.LOG_DB_FOLDER) 633 con = sqlite.connect(logger.LOG_DB_FILE) 634 os.chdir(back) 635 cur = con.cursor() 636 try: 637 cur.executescript('DROP TABLE caps_cache;') 638 con.commit() 639 except sqlite.OperationalError: 640 pass 641 try: 642 cur.executescript( 643 ''' 644 CREATE TABLE caps_cache ( 645 hash_method TEXT, 646 hash TEXT, 647 data BLOB 648 ); 649 ''' 650 ) 651 con.commit() 652 except sqlite.OperationalError, e: 653 pass 654 con.close() 655 gajim.config.set('version', '0.11.4.4')
656
657 - def update_config_to_01201(self):
658 if 'uri_schemes' in self.old_values: 659 new_values = self.old_values['uri_schemes'].replace(' mailto', '').\ 660 replace(' xmpp', '') 661 gajim.config.set('uri_schemes', new_values) 662 gajim.config.set('version', '0.12.0.1')
663
664 - def update_config_to_01211(self):
665 if 'trayicon' in self.old_values: 666 if self.old_values['trayicon'] == 'False': 667 gajim.config.set('trayicon', 'never') 668 else: 669 gajim.config.set('trayicon', 'always') 670 gajim.config.set('version', '0.12.1.1')
671
672 - def update_config_to_01212(self):
673 for opt in ('ignore_unknown_contacts', 'send_os_info', 674 'log_encrypted_sessions'): 675 if opt in self.old_values: 676 val = self.old_values[opt] 677 for account in gajim.config.get_per('accounts'): 678 gajim.config.set_per('accounts', account, opt, val) 679 gajim.config.set('version', '0.12.1.2')
680
681 - def update_config_to_01213(self):
682 msgs = gajim.config.statusmsg_default 683 for msg_name in gajim.config.get_per('statusmsg'): 684 if msg_name in msgs: 685 gajim.config.set_per('statusmsg', msg_name, 'activity', 686 msgs[msg_name][1]) 687 gajim.config.set_per('statusmsg', msg_name, 'subactivity', 688 msgs[msg_name][2]) 689 gajim.config.set_per('statusmsg', msg_name, 'activity_text', 690 msgs[msg_name][3]) 691 gajim.config.set_per('statusmsg', msg_name, 'mood', 692 msgs[msg_name][4]) 693 gajim.config.set_per('statusmsg', msg_name, 'mood_text', 694 msgs[msg_name][5]) 695 gajim.config.set('version', '0.12.1.3')
696
697 - def update_config_to_01214(self):
698 for status in ['online', 'chat', 'away', 'xa', 'dnd', 'invisible', 699 'offline']: 700 if 'last_status_msg_' + status in self.old_values: 701 gajim.config.add_per('statusmsg', '_last_' + status) 702 gajim.config.set_per('statusmsg', '_last_' + status, 'message', 703 self.old_values['last_status_msg_' + status]) 704 gajim.config.set('version', '0.12.1.4')
705
706 - def update_config_to_01215(self):
707 """ 708 Remove hardcoded ../data/sounds from config 709 """ 710 dirs = ['../data', gajim.gajimpaths.data_root, gajim.DATA_DIR] 711 if os.name != 'nt': 712 dirs.append(os.path.expanduser(u'~/.gajim')) 713 for evt in gajim.config.get_per('soundevents'): 714 path = gajim.config.get_per('soundevents', evt, 'path') 715 # absolute and relative passes are necessary 716 path = helpers.strip_soundfile_path(path, dirs, abs=False) 717 path = helpers.strip_soundfile_path(path, dirs, abs=True) 718 gajim.config.set_per('soundevents', evt, 'path', path) 719 gajim.config.set('version', '0.12.1.5')
720
721 - def update_config_to_01231(self):
722 back = os.getcwd() 723 os.chdir(logger.LOG_DB_FOLDER) 724 con = sqlite.connect(logger.LOG_DB_FILE) 725 os.chdir(back) 726 cur = con.cursor() 727 try: 728 cur.executescript( 729 ''' 730 CREATE TABLE IF NOT EXISTS roster_entry( 731 account_jid_id INTEGER, 732 jid_id INTEGER, 733 name TEXT, 734 subscription INTEGER, 735 ask BOOLEAN, 736 PRIMARY KEY (account_jid_id, jid_id) 737 ); 738 739 CREATE TABLE IF NOT EXISTS roster_group( 740 account_jid_id INTEGER, 741 jid_id INTEGER, 742 group_name TEXT, 743 PRIMARY KEY (account_jid_id, jid_id, group_name) 744 ); 745 ''' 746 ) 747 con.commit() 748 except sqlite.OperationalError: 749 pass 750 con.close() 751 gajim.config.set('version', '0.12.3.1')
752
753 - def update_config_from_0125(self):
754 # All those functions need to be called for 0.12.5 to 0.13 transition 755 self.update_config_to_01211() 756 self.update_config_to_01213() 757 self.update_config_to_01214() 758 self.update_config_to_01215() 759 self.update_config_to_01231()
760
761 - def update_config_to_01251(self):
762 back = os.getcwd() 763 os.chdir(logger.LOG_DB_FOLDER) 764 con = sqlite.connect(logger.LOG_DB_FILE) 765 os.chdir(back) 766 cur = con.cursor() 767 try: 768 cur.executescript( 769 ''' 770 ALTER TABLE unread_messages 771 ADD shown BOOLEAN default 0; 772 ''' 773 ) 774 con.commit() 775 except sqlite.OperationalError: 776 pass 777 con.close() 778 gajim.config.set('version', '0.12.5.1')
779
780 - def update_config_to_01252(self):
781 if 'alwaysauth' in self.old_values: 782 val = self.old_values['alwaysauth'] 783 for account in gajim.config.get_per('accounts'): 784 gajim.config.set_per('accounts', account, 'autoauth', val) 785 gajim.config.set('version', '0.12.5.2')
786
787 - def update_config_to_01253(self):
788 if 'enable_zeroconf' in self.old_values: 789 val = self.old_values['enable_zeroconf'] 790 for account in gajim.config.get_per('accounts'): 791 if gajim.config.get_per('accounts', account, 'is_zeroconf'): 792 gajim.config.set_per('accounts', account, 'active', val) 793 else: 794 gajim.config.set_per('accounts', account, 'active', True) 795 gajim.config.set('version', '0.12.5.3')
796
797 - def update_config_to_01254(self):
798 vals = {'inmsgcolor': ['#a34526', '#a40000'], 799 'outmsgcolor': ['#164e6f', '#3465a4'], 800 'restored_messages_color': ['grey', '#555753'], 801 'statusmsgcolor': ['#1eaa1e', '#73d216'], 802 'urlmsgcolor': ['#0000ff', '#204a87'], 803 'gc_nicknames_colors': ['#a34526:#c000ff:#0012ff:#388a99:#045723:#7c7c7c:#ff8a00:#94452d:#244b5a:#32645a', '#4e9a06:#f57900:#ce5c00:#3465a4:#204a87:#75507b:#5c3566:#c17d11:#8f5902:#ef2929:#cc0000:#a40000']} 804 for c in vals: 805 if c not in self.old_values: 806 continue 807 val = self.old_values[c] 808 if val == vals[c][0]: 809 # We didn't change default value, so update it with new default 810 gajim.config.set(c, vals[c][1]) 811 gajim.config.set('version', '0.12.5.4')
812
813 - def update_config_to_01255(self):
814 vals = {'statusmsgcolor': ['#73d216', '#4e9a06'], 815 'outmsgtxtcolor': ['#a2a2a2', '#555753']} 816 for c in vals: 817 if c not in self.old_values: 818 continue 819 val = self.old_values[c] 820 if val == vals[c][0]: 821 # We didn't change default value, so update it with new default 822 gajim.config.set(c, vals[c][1]) 823 gajim.config.set('version', '0.12.5.5')
824
825 - def update_config_to_01256(self):
826 vals = {'gc_nicknames_colors': ['#4e9a06:#f57900:#ce5c00:#3465a4:#204a87:#75507b:#5c3566:#c17d11:#8f5902:#ef2929:#cc0000:#a40000', '#f57900:#ce5c00:#204a87:#75507b:#5c3566:#c17d11:#8f5902:#ef2929:#cc0000:#a40000']} 827 for c in vals: 828 if c not in self.old_values: 829 continue 830 val = self.old_values[c] 831 if val == vals[c][0]: 832 # We didn't change default value, so update it with new default 833 gajim.config.set(c, vals[c][1]) 834 gajim.config.set('version', '0.12.5.6')
835
836 - def update_config_to_01257(self):
837 if 'iconset' in self.old_values: 838 if self.old_values['iconset'] in ('nuvola', 'crystal', 'gossip', 839 'simplebulb', 'stellar'): 840 gajim.config.set('iconset', gajim.config.DEFAULT_ICONSET) 841 gajim.config.set('version', '0.12.5.7')
842
843 - def update_config_to_01258(self):
844 self.update_ft_proxies(to_remove=['proxy65.talkonaut.com', 845 'proxy.jabber.org', 'proxy.netlab.cz', 'transfer.jabber.freenet.de', 846 'proxy.jabber.cd.chalmers.se'], to_add=['proxy.eu.jabber.org', 847 'proxy.jabber.ru', 'proxy.jabbim.cz']) 848 gajim.config.set('version', '0.12.5.8')
849
850 - def update_config_to_013100(self):
851 back = os.getcwd() 852 os.chdir(logger.LOG_DB_FOLDER) 853 con = sqlite.connect(logger.LOG_DB_FILE) 854 os.chdir(back) 855 cur = con.cursor() 856 try: 857 cur.executescript( 858 ''' 859 ALTER TABLE caps_cache 860 ADD last_seen INTEGER default %d; 861 ''' % int(time()) 862 ) 863 con.commit() 864 except sqlite.OperationalError: 865 pass 866 con.close() 867 gajim.config.set('version', '0.13.10.0')
868
869 - def update_config_to_013101(self):
870 back = os.getcwd() 871 os.chdir(logger.LOG_DB_FOLDER) 872 con = sqlite.connect(logger.LOG_DB_FILE) 873 os.chdir(back) 874 cur = con.cursor() 875 try: 876 cur.executescript( 877 ''' 878 DROP INDEX IF EXISTS idx_logs_jid_id_kind; 879 880 CREATE INDEX IF NOT EXISTS 881 idx_logs_jid_id_time ON logs (jid_id, time DESC); 882 ''' 883 ) 884 con.commit() 885 except sqlite.OperationalError: 886 pass 887 con.close() 888 gajim.config.set('version', '0.13.10.1')
889