2013-04-06 12:30:01 -07:00
|
|
|
"""
|
|
|
|
Version checker
|
|
|
|
"""
|
|
|
|
|
|
|
|
"""
|
|
|
|
Copyright 2013 Anthony Beville
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
2015-02-12 14:57:46 -08:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2013-04-06 12:30:01 -07:00
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
"""
|
2015-02-13 15:08:07 -08:00
|
|
|
|
2013-04-06 12:30:01 -07:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import platform
|
2015-02-15 02:44:00 -08:00
|
|
|
import urllib
|
|
|
|
import urllib2
|
2015-02-13 15:08:07 -08:00
|
|
|
|
2013-04-06 12:30:01 -07:00
|
|
|
import ctversion
|
|
|
|
|
|
|
|
try:
|
2015-02-12 14:57:46 -08:00
|
|
|
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply
|
|
|
|
from PyQt4.QtCore import QUrl, pyqtSignal, QObject, QByteArray
|
2013-04-06 12:30:01 -07:00
|
|
|
except ImportError:
|
2015-02-12 14:57:46 -08:00
|
|
|
# No Qt, so define a few dummy QObjects to help us compile
|
|
|
|
class QObject():
|
2015-02-15 02:44:00 -08:00
|
|
|
|
|
|
|
def __init__(self, *args):
|
2015-02-12 14:57:46 -08:00
|
|
|
pass
|
2015-02-15 02:44:00 -08:00
|
|
|
|
2015-02-12 14:57:46 -08:00
|
|
|
class pyqtSignal():
|
2015-02-15 02:44:00 -08:00
|
|
|
|
|
|
|
def __init__(self, *args):
|
2015-02-12 14:57:46 -08:00
|
|
|
pass
|
2015-02-15 02:44:00 -08:00
|
|
|
|
|
|
|
def emit(a, b, c):
|
2015-02-12 14:57:46 -08:00
|
|
|
pass
|
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
|
2013-04-06 12:30:01 -07:00
|
|
|
class VersionChecker(QObject):
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def getRequestUrl(self, uuid, use_stats):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
base_url = "http://comictagger1.appspot.com/latest"
|
|
|
|
args = ""
|
|
|
|
|
|
|
|
if use_stats:
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
plat = "win"
|
|
|
|
elif platform.system() == "Linux":
|
|
|
|
plat = "lin"
|
|
|
|
elif platform.system() == "Darwin":
|
|
|
|
plat = "mac"
|
|
|
|
else:
|
|
|
|
plat = "other"
|
2015-02-15 02:44:00 -08:00
|
|
|
args = "?uuid={0}&platform={1}&version={2}".format(
|
|
|
|
uuid, plat, ctversion.version)
|
2015-02-12 14:57:46 -08:00
|
|
|
if not getattr(sys, 'frozen', None):
|
|
|
|
args += "&src=T"
|
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
return base_url + args
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def getLatestVersion(self, uuid, use_stats=True):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
try:
|
2015-02-13 15:08:07 -08:00
|
|
|
resp = urllib2.urlopen(self.getRequestUrl(uuid, use_stats))
|
2015-02-12 14:57:46 -08:00
|
|
|
new_version = resp.read()
|
|
|
|
except Exception as e:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if new_version is None or new_version == "":
|
|
|
|
return None
|
|
|
|
return new_version.strip()
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
versionRequestComplete = pyqtSignal(str)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def asyncGetLatestVersion(self, uuid, use_stats):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
url = self.getRequestUrl(uuid, use_stats)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
self.nam = QNetworkAccessManager()
|
2015-02-13 15:08:07 -08:00
|
|
|
self.nam.finished.connect(self.asyncGetLatestVersionComplete)
|
2015-02-12 14:57:46 -08:00
|
|
|
self.nam.get(QNetworkRequest(QUrl(str(url))))
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def asyncGetLatestVersionComplete(self, reply):
|
2015-02-12 14:57:46 -08:00
|
|
|
if (reply.error() != QNetworkReply.NoError):
|
|
|
|
return
|
|
|
|
|
|
|
|
# read in the response
|
|
|
|
new_version = str(reply.readAll())
|
|
|
|
|
|
|
|
if new_version is None or new_version == "":
|
|
|
|
return
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
self.versionRequestComplete.emit(new_version.strip())
|