1
2
3
4
5
6
7
8
9
10
11 from __future__ import with_statement
12 import copy
13 import urllib2
14 import xml.dom.minidom
15 import webbrowser
16
17
18 import wx
19
20
21 import guihelper
22 import version
23
24
39
40
64
65
67 - def __init__(self, frm, to, priority, alert):
68 self.__frm=frm
69 self.__to=to
70 self.__priority=priority
71 self.__alert=alert
73 return (self.__frm, self.__to, self.__priority, self.__alert)
74 info=property(fget=__get_info)
75
76
79 self.__xml_version='Unknown'
80 self.__updates={}
81 self.__versions={}
82 self.__latest=None
84 return self.__xml_version
85 xml_version=property(fget=__get_xml_version)
87 return copy.deepcopy(self.__versions, {})
89 return copy.deepcopy(self.__updates, {})
92 versions=property(fget=__get_versions)
93 updates=property(fget=__get_updates)
94 latest_version=property(fget=__get_latest_version)
95
97 try:
98 return node.getElementsByTagName(name)[0].firstChild.data
99 except IndexError:
100
101 return None
102 except:
103 if __debug__: raise
104 return None
105
106 __default_url='http://www.bitpim.org/updates.xml'
108
109 dom=xml.dom.minidom.parseString(urllib2.urlopen(url).read())
110
111 bp_update=dom.getElementsByTagName('BitPimUpdate')[0]
112 self.__xml_version=bp_update.getAttribute('version')
113 self.__latest=bp_update.getAttribute('latest')
114
115 updates=dom.getElementsByTagName('update')
116 for n in updates:
117 frm=n.getAttribute('from')
118 self.__updates[frm]=Update(frm,
119 self.__get_node_value(n, 'to'),
120 self.__get_node_value(n, 'priority'),
121 self.__get_node_value(n, 'alert'))
122 versions=dom.getElementsByTagName('version')
123 for n in versions:
124 name=n.getAttribute('name')
125 v=Version(name, self.__get_node_value(n, 'releasedate'),
126 n.getElementsByTagName('changelog')[0].getAttribute('src'))
127 downloads=n.getElementsByTagName('download')
128 for d in downloads:
129 v.add_download(Download(\
130 d.getAttribute('src'),
131 d.getAttribute('platform'),
132 d.getAttribute('flavor')))
133 self.__versions[name]=v
134
136
137
138 u=self.__updates.get(current_version, None)
139 if u is None:
140
141 return 'There are no updates to the current version: '+current_version
142
143 (frm, next_version, priority, alert)=u.info
144 v=self.__versions.get(next_version, None)
145 if v is None:
146
147 return 'No download info on version '+next_version+' available.'
148 dl=v.get_download(platform, flavor)
149 if dl is None or not len(dl.source):
150
151 return 'Load '+next_version+' is not available on platform '+platform+'/'+flavor
152
153 lines=[]
154 lines.append('Current Version: '+current_version)
155 s='Platform: '+platform
156 if flavor is not None and len(flavor):
157 s+='/'+flavor
158 lines.append(s)
159 lines.append('Available for Upgrade:')
160 lines.append('\tVersion: '+next_version)
161 lines.append('\tRelease Date: '+v.release_date)
162 if priority is not None and len(priority):
163 lines.append('\tPriority: '+priority)
164 if alert is not None and len(alert):
165 lines.append('\tWarning: '+alert)
166 lines.append('updates.xml Version: '+self.xml_version)
167 lines.append('Latest BitPim Version: '+self.latest_version)
168 with guihelper.WXDialogWrapper(UpdateDialog(None, dl.source, v.change_log, lines),
169 True):
170 pass
171
172
174 - def __init__(self, parent, source_url, change_log_url, lines,
175 _title='BitPim Update'):
176 wx.Dialog.__init__(self, parent, -1, _title)
177 self.__source_url=source_url
178 self.__changelog_url=change_log_url
179 vbs=wx.BoxSizer(wx.VERTICAL)
180 for l in lines:
181 vbs.Add(wx.StaticText(self, -1, l), 0, wx.EXPAND|wx.ALL, 5)
182 vbs.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
183 change_log_btn=wx.Button(self, wx.NewId(), 'View Change Log')
184 hbs=wx.BoxSizer(wx.HORIZONTAL)
185 hbs.Add(change_log_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
186 get_update_btn=wx.Button(self, wx.NewId(), 'Download Update')
187 hbs.Add(get_update_btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
188 hbs.Add(wx.Button(self, wx.ID_CANCEL, 'Quit'), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
189 vbs.Add(hbs, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
190
191 wx.EVT_BUTTON(self, change_log_btn.GetId(), self.__OnChangelog)
192 wx.EVT_BUTTON(self, get_update_btn.GetId(), self.__OnGetUpdate)
193
194 self.SetSizer(vbs)
195 self.SetAutoLayout(True)
196 vbs.Fit(self)
197
199 webbrowser.open(self.__changelog_url)
200
202 webbrowser.open(self.__source_url)
203
204
205 -def check_update(update_url=None, current_version=None,
206 platform=None, flavor=''):
207
208 if current_version is None:
209 current_version=version.version
210
211 if platform is None:
212 if guihelper.IsMSWindows():
213 platform='windows'
214 elif guihelper.IsGtk():
215 platform='linux'
216 elif guihelper.IsMac():
217 platform='mac'
218 else:
219 raise ValueError, 'Invalid platform'
220
221
222
223 print 'Checking update for BitPim ', current_version, ' running on ', \
224 platform, '-', flavor
225 with guihelper.WXDialogWrapper(wx.ProgressDialog('BitPim Update',
226 'Retrieving BitPim Update Information...',
227 style=wx.PD_AUTO_HIDE)) as dlg:
228 bp_update=BitPimUpdate()
229 s=None
230 try:
231 if update_url is None:
232 bp_update.get_update_info()
233 else:
234 bp_update.get_update_info(update_url)
235 dlg.Update(100)
236 except:
237 s='Failed to get BitPim update info.'
238 if s is None:
239 s=bp_update.display_update_info(current_version, platform, flavor)
240 latest_version=bp_update.latest_version
241 else:
242 latest_version=''
243 if s is not None:
244
245 guihelper.MessageDialog(None, s, 'BitPim Update', wx.OK|wx.ICON_INFORMATION)
246 return latest_version
247
248
249 if __name__ == '__main__':
250 import sys
251 if len(sys.argv)==2 and (sys.argv[1]=='help' or sys.argv[1]=='-help' \
252 or sys.argv[1]=='-h'):
253 print sys.argv[0], '<updates.xml URL> <current BitPim Version> <Platform> <Flavor>'
254 sys.exit(0)
255 app=wx.PySimpleApp()
256 if len(sys.argv)==1:
257 s=check_update()
258 else:
259 s=check_update(*sys.argv[1:])
260 print 'The latest version is: ', s
261