1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
from welcome.board import SmallBoard
from gi.repository import Gtk
import pychrysalide
try:
import urllib3
has_urllib3 = True
except:
has_urllib3 = False
class VersionChecker(SmallBoard):
"""Affichage des versions courante et disponible, ainsi que des conclusions associées."""
def __init__(self):
"""Construit le panneau avec son contenu."""
super(VersionChecker, self).__init__()
current = pychrysalide.revision()
if has_urllib3:
lastest = self.get_lastest_version('community')
if lastest != None:
up2date = self.get_update_status(current, lastest)
else:
up2date = None
if lastest != None and up2date != None:
msg = '''Your version is: <b>%s</b>
Lastest version is: <b>%s</b>'''
caption = msg % (current, lastest if lastest != None else 'unknown')
if up2date:
caption = caption + '''
Your software is <span color='green'><b>up-to-date</b></span>.'''
else:
caption = caption + '''
Your software is <b><span color='red'>outdated</span></b>.'''
else:
msg = '''Your version is: <b>%s</b>
An error occurred while dealing with revision numbers.'''
caption = msg % current
else:
msg = '''Your version is: <b>%s</b>
To display the lastest available version, please install the <b>urllib3</b> package for Python.'''
caption = msg % current
desc = Gtk.Label(caption, use_markup=True, wrap=True)
desc.set_track_visited_links(False)
self.add(desc)
def get_lastest_version(self, category):
"""Retrouve la dernière version disponible à partir du site officiel."""
lastest = None
http = urllib3.PoolManager()
request = http.request('GET', 'http://0xdeadc0de.fr/chrysalide/updates/versions')
html = request.data.decode('utf-8')
request.release_conn()
available = html.split('\n')
for a in available:
desc = a.split('=')
if desc[0] == category:
lastest = desc[1]
break
return lastest
def get_update_status(self, current, lastest):
"""Détermine le degré de mise à jour du système."""
if current[0] != 'r' or lastest[0] != 'r':
return None
cur_rev = int(current[1:])
last_rev = int(lastest[1:])
return (cur_rev >= last_rev)
def get_location(self):
"""Fournit la localisation souhaitée pour la planche."""
return [ 2, 0, 1, 1 ]
|