root/branches/gajim_0.8.2/src/check_for_new_version.py

Revision 2960, 2.9 kB (checked in by nk, 3 years ago)

hardcode float()

Line 
1##      check_for_new_version.py
2##
3## Gajim Team:
4## - Yann Le Boulanger <asterix@lagaule.org>
5## - Vincent Hanquez <tab@snarc.org>
6## - Nikos Kouremenos <kourem@gmail.com>
7##
8##      Copyright (C) 2003-2005 Gajim Team
9##
10## This program is free software; you can redistribute it and/or modify
11## it under the terms of the GNU General Public License as published
12## by the Free Software Foundation; version 2 only.
13##
14## This program is distributed in the hope that it will be useful,
15## but WITHOUT ANY WARRANTY; without even the implied warranty of
16## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17## GNU General Public License for more details.
18##
19
20import gtk
21import gtk.glade
22
23from common import gajim
24from common import helpers
25from common import i18n
26
27_ = i18n._
28APP = i18n.APP
29gtk.glade.bindtextdomain(APP, i18n.DIR)
30gtk.glade.textdomain(APP)
31
32GTKGUI_GLADE='gtkgui.glade'
33
34class Check_for_new_version_dialog:
35        def __init__(self, plugin):
36                self.plugin = plugin
37                try:
38                        self.check_for_new_version()
39                except:
40                        pass
41
42        def parse_glade(self):
43                xml = gtk.glade.XML(GTKGUI_GLADE, 'new_version_available_dialog', APP)
44                self.window = xml.get_widget('new_version_available_dialog')
45                self.information_label = xml.get_widget('information_label')
46                self.changes_textview = xml.get_widget('changes_textview')
47                xml.signal_autoconnect(self)
48
49        def on_new_version_available_dialog_delete_event(self, widget, event):
50                self.window.destroy()
51
52        def on_open_download_page_button_clicked(self, widget):
53                url = 'http://www.gajim.org/downloads.php?lang='
54                helpers.launch_browser_mailer('url', url)
55                self.window.destroy()
56
57        def check_for_new_version(self):
58                '''parse online Changelog to find out last version
59                and the changes for that latest version'''
60                import urllib2
61                import socket
62                dto = socket.getdefaulttimeout()
63                socket.setdefaulttimeout(5)
64
65                url = 'http://trac.gajim.org/file/trunk/Changelog?rev=latest&format=txt'
66                changelog = urllib2.urlopen(url)
67
68                socket.setdefaulttimeout(dto)
69
70                # format is 'Gajim version (date)'
71                first_line = changelog.readline()
72                finish_version = first_line.find(' ', 6) # start search after 'Gajim'
73                latest_version = first_line[6:finish_version]
74                if float(latest_version) > float(gajim.version):
75                        start_date = finish_version + 2 # one space and one (
76                        date = first_line[start_date:-2] # remove the last ) and \n
77                        info = 'Gajim ' + latest_version + ' was released in ' + date + '!'
78                        changes = ''
79                        while True:
80                                line = changelog.readline().lstrip()
81                                if line.startswith('Gajim'):
82                                        break
83                                else:
84                                        if line != '\n' or line !='': # line has some content
85                                                if not line.startswith('*'):
86                                                        # the is not a new *real* line
87                                                        # but a continuation from previous line.
88                                                        # So remove \n from previous 'line' beforing adding it
89                                                        changes = changes[:-1]
90
91                                                changes += line
92                       
93                        self.parse_glade()
94                        self.information_label.set_text(info)
95                        buf = self.changes_textview.get_buffer()
96                        buf.set_text(changes)
97                        self.window.show_all()
Note: See TracBrowser for help on using the browser.