From 4a90f80cfa13aa6b8ac45727e8a8747a32835125 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Sun, 8 May 2005 15:06:24 +0000 Subject: [PATCH] chk new version commit: fixing a bug introduced by tab when he changed the names of the var in config and adding a timeout --- src/check_for_new_version.py | 76 +++++++++++++++++++----------------- src/gajim.py | 2 +- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/check_for_new_version.py b/src/check_for_new_version.py index 9dc05cb23..f2a93aaaf 100644 --- a/src/check_for_new_version.py +++ b/src/check_for_new_version.py @@ -33,10 +33,7 @@ GTKGUI_GLADE='gtkgui.glade' class Check_for_new_version_dialog: def __init__(self, plugin): self.plugin = plugin - try: - self.check_for_new_version() - except: - pass + self.check_for_new_version() def parse_glade(self): xml = gtk.glade.XML(GTKGUI_GLADE, 'new_version_available_dialog', APP) @@ -56,37 +53,44 @@ class Check_for_new_version_dialog: def check_for_new_version(self): '''parse online Changelog to find out last version and the changes for that latest version''' - check_for_new_version_available = True # Why that ? - if check_for_new_version_available: - import urllib + import urllib2 + import socket + dto = socket.getdefaulttimeout() + socket.setdefaulttimeout(5) - url = 'http://trac.gajim.org/file/trunk/Changelog?rev=latest&format=txt' - changelog = urllib.urlopen(url) - # format is Gajim version (date) - first_line = changelog.readline() - finish_version = first_line.find(' ', 6) # start search after 'Gajim' - latest_version = first_line[6:finish_version] - if latest_version > gajim.version: - start_date = finish_version + 2 # one space and one ( - date = first_line[start_date:-2] # remove the last ) and \n - info = 'Gajim ' + latest_version + ' was released in ' + date + '!' - changes = '' - while True: - line = changelog.readline().lstrip() - if line.startswith('Gajim'): - break - else: - if line != '\n' or line !='': # line has some content - if not line.startswith('*'): - # the is not a new *real* line - # but a continuation from previous line. - # So remove \n from previous 'line' beforing adding it - changes = changes[:-1] + url = 'http://trac.gajim.org/file/trunk/Changelog?rev=latest&format=txt' + try: + changelog = urllib2.urlopen(url) + except: + pass - changes += line - - self.parse_glade() - self.information_label.set_text(info) - buf = self.changes_textview.get_buffer() - buf.set_text(changes) - self.window.show_all() + socket.setdefaulttimeout(dto) + + # format is 'Gajim version (date)' + first_line = changelog.readline() + finish_version = first_line.find(' ', 6) # start search after 'Gajim' + latest_version = first_line[6:finish_version] + if latest_version > gajim.version: + start_date = finish_version + 2 # one space and one ( + date = first_line[start_date:-2] # remove the last ) and \n + info = 'Gajim ' + latest_version + ' was released in ' + date + '!' + changes = '' + while True: + line = changelog.readline().lstrip() + if line.startswith('Gajim'): + break + else: + if line != '\n' or line !='': # line has some content + if not line.startswith('*'): + # the is not a new *real* line + # but a continuation from previous line. + # So remove \n from previous 'line' beforing adding it + changes = changes[:-1] + + changes += line + + self.parse_glade() + self.information_label.set_text(info) + buf = self.changes_textview.get_buffer() + buf.set_text(changes) + self.window.show_all() diff --git a/src/gajim.py b/src/gajim.py index 2ec6bee35..6fc80c31d 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -696,7 +696,7 @@ class Interface: if self.systray_capabilities: self.show_systray() - if not gajim.config.get('check_for_new_version'): + if gajim.config.get('check_for_new_version'): check_for_new_version.Check_for_new_version_dialog(self) self.init_regexp()