| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
import webbrowser |
| 23 |
from urllib.request import urlopen |
| 24 |
|
| 25 |
from PyQt5.QtCore import QObject, pyqtSignal |
| 26 |
from PyQt5.QtWidgets import QMessageBox |
| 27 |
|
| 28 |
from ..pylib import print_error |
| 29 |
from .. import param |
| 30 |
from .qtlib import GenericThread |
| 31 |
from .app import app |
| 32 |
|
| 33 |
|
| 34 |
class Gestionnaire_mises_a_jour(QObject): |
| 35 |
url_version = "http://wxgeo.free.fr/wordpress/version_geophar" |
| 36 |
url_telechargement = "http://sourceforge.net/projects/geophar/files/latest/download" |
| 37 |
|
| 38 |
def __init__(self, parent): |
| 39 |
QObject.__init__(self) |
| 40 |
self.parent = parent |
| 41 |
self.derniere_version = None |
| 42 |
self.sent.connect(self.termine) |
| 43 |
|
| 44 |
sent = pyqtSignal(bool, bool, str, str) |
| 45 |
|
| 46 |
|
| 47 |
def termine(self, success, update, version, msg): |
| 48 |
if success: |
| 49 |
if update: |
| 50 |
self.derniere_version = version |
| 51 |
QMessageBox.information(self.parent, "Une mise à jour a été trouvée.", |
| 52 |
("La version %s de %s est sortie.\n" |
| 53 |
"Vous allez être redirigé vers la page de téléchargement.") |
| 54 |
% (version, param.NOMPROG)) |
| 55 |
webbrowser.open(self.url_telechargement) |
| 56 |
else: |
| 57 |
QMessageBox.information(self.parent, "Aucune mise à jour trouvée.", |
| 58 |
"Aucune mise à jour n'est disponible actuellement.<br>" |
| 59 |
"Consultez <a href='http://wxgeo.free.fr/wordpress/'>" |
| 60 |
"http://wxgeo.free.fr</a> pour plus d'informations.") |
| 61 |
else: |
| 62 |
print('Connexion impossible à ' + self.url_version + ' : ' + msg) |
| 63 |
QMessageBox.warning(self.parent, "Connexion impossible", |
| 64 |
"Impossible de vérifier si une nouvelle version existe.<br>" |
| 65 |
"Consultez <a href='http://wxgeo.free.fr/wordpress/'>" |
| 66 |
"http://wxgeo.free.fr</a> pour plus d'informations.") |
| 67 |
|
| 68 |
|
| 69 |
def verifier_version(self, event=None): |
| 70 |
self.thread = GenericThread(self._verifier_version) |
| 71 |
self.thread.start() |
| 72 |
|
| 73 |
|
| 74 |
def _verifier_version(self): |
| 75 |
|
| 76 |
. |
| 77 |
version = '?' |
| 78 |
success = False |
| 79 |
update = False |
| 80 |
msg = 'Unknown error.' |
| 81 |
try: |
| 82 |
if param.debug: |
| 83 |
app.safe_print("Checking %s..." % self.url_version) |
| 84 |
with urlopen(self.url_version) as f: |
| 85 |
version = f.read(60).decode('utf8') |
| 86 |
if len(version) > 50 or not version.replace(" ", "").replace(".", "").isalnum(): |
| 87 |
raise Exception("Incorrect file format, unable to find current version.") |
| 88 |
success = True |
| 89 |
if version.split(".") > param.version.split('.'): |
| 90 |
update = True |
| 91 |
else: |
| 92 |
update = False |
| 93 |
except Exception as e: |
| 94 |
|
| 95 |
app.safe_print_error() |
| 96 |
msg = str(e) |
| 97 |
|
| 98 |
self.sent.emit(success, update, version, msg) |