#!/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')
up2date = self.get_update_status(current, lastest)
if lastest != None and up2date != None:
msg = '''Your version is: %s
Lastest version is: %s'''
caption = msg % (current, lastest if lastest != None else 'unknown')
if up2date:
caption = caption + '''
Your software is up-to-date.'''
else:
caption = caption + '''
Your software is outdated.'''
else:
msg = '''Your version is: %s
An error occurred while dealing with revision numbers.'''
caption = msg % current
else:
msg = '''Your version is: %s
To display the lastest available version, please install the urllib3 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://localhost/mediawiki/data/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 plache."""
return [ 2, 0, 1, 1 ]