mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
pyplugin_installer moved to QNetworkAccessManager from QHttp
This commit is contained in:
parent
1bfa97091c
commit
84eb6f81f7
@ -40,9 +40,10 @@ Data structure:
|
|||||||
mRepositories = dict of dicts: {repoName : {"url" unicode,
|
mRepositories = dict of dicts: {repoName : {"url" unicode,
|
||||||
"enabled" bool,
|
"enabled" bool,
|
||||||
"valid" bool,
|
"valid" bool,
|
||||||
"QPHttp" QPHttp,
|
"QPNAME" QPNetworkAccessManager,
|
||||||
"Relay" Relay, # Relay object for transmitting signals from QPHttp with adding the repoName information
|
"Relay" Relay, # Relay object for transmitting signals from QPHttp with adding the repoName information
|
||||||
"xmlData" QBuffer,
|
"Request" QNetworkRequest,
|
||||||
|
"xmlData" QNetworkReply,
|
||||||
"state" int, (0 - disabled, 1-loading, 2-loaded ok, 3-error (to be retried), 4-rejected)
|
"state" int, (0 - disabled, 1-loading, 2-loaded ok, 3-error (to be retried), 4-rejected)
|
||||||
"error" unicode}}
|
"error" unicode}}
|
||||||
|
|
||||||
@ -169,17 +170,17 @@ def removeDir(path):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --- class QPHttp ----------------------------------------------------------------------- #
|
# --- class QPNetworkAccessManager ----------------------------------------------------------------------- #
|
||||||
# --- It's a temporary workaround for broken proxy handling in Qt ------------------------- #
|
# --- It's a temporary workaround for broken proxy handling in Qt ------------------------- #
|
||||||
class QPHttp(QHttp):
|
class QPNetworkAccessManager(QNetworkAccessManager):
|
||||||
def __init__(self,*args):
|
def __init__(self,*args):
|
||||||
QHttp.__init__(self,*args)
|
QNetworkAccessManager.__init__(self,)
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
settings.beginGroup("proxy")
|
settings.beginGroup("proxy")
|
||||||
if settings.value("/proxyEnabled", False, type=bool):
|
if settings.value("/proxyEnabled", False, type=bool):
|
||||||
self.proxy=QNetworkProxy()
|
self.proxy=QNetworkProxy()
|
||||||
proxyType = settings.value( "/proxyType", "0", type=unicode)
|
proxyType = settings.value( "/proxyType", "0", type=unicode)
|
||||||
if len(args) > 0 and args[0] in settings.value("/proxyExcludedUrls","", type=unicode):
|
if len(args)>0 and settings.value("/proxyExcludedUrls","", type=unicode).contains(args[0]):
|
||||||
proxyType = "NoProxy"
|
proxyType = "NoProxy"
|
||||||
if proxyType in ["1","Socks5Proxy"]: self.proxy.setType(QNetworkProxy.Socks5Proxy)
|
if proxyType in ["1","Socks5Proxy"]: self.proxy.setType(QNetworkProxy.Socks5Proxy)
|
||||||
elif proxyType in ["2","NoProxy"]: self.proxy.setType(QNetworkProxy.NoProxy)
|
elif proxyType in ["2","NoProxy"]: self.proxy.setType(QNetworkProxy.NoProxy)
|
||||||
@ -194,7 +195,7 @@ class QPHttp(QHttp):
|
|||||||
self.setProxy(self.proxy)
|
self.setProxy(self.proxy)
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
return None
|
return None
|
||||||
# --- /class QPHttp ---------------------------------------------------------------------- #
|
# --- /class QPNetworkAccessManager ---------------------------------------------------------------------- #
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -216,7 +217,7 @@ class Relay(QObject):
|
|||||||
# ----------------------------------------- #
|
# ----------------------------------------- #
|
||||||
def dataReadProgress(self, done, total):
|
def dataReadProgress(self, done, total):
|
||||||
state = 4
|
state = 4
|
||||||
if total:
|
if total > 0:
|
||||||
progress = int(float(done)/float(total)*100)
|
progress = int(float(done)/float(total)*100)
|
||||||
else:
|
else:
|
||||||
progress = 0
|
progress = 0
|
||||||
@ -379,7 +380,8 @@ class Repositories(QObject):
|
|||||||
self.mRepositories[key]["url"] = settings.value(key+"/url", "", type=unicode)
|
self.mRepositories[key]["url"] = settings.value(key+"/url", "", type=unicode)
|
||||||
self.mRepositories[key]["enabled"] = settings.value(key+"/enabled", True, type=bool)
|
self.mRepositories[key]["enabled"] = settings.value(key+"/enabled", True, type=bool)
|
||||||
self.mRepositories[key]["valid"] = settings.value(key+"/valid", True, type=bool)
|
self.mRepositories[key]["valid"] = settings.value(key+"/valid", True, type=bool)
|
||||||
self.mRepositories[key]["QPHttp"] = QPHttp()
|
self.mRepositories[key]["QPNAM"] = QPNetworkAccessManager()
|
||||||
|
|
||||||
self.mRepositories[key]["Relay"] = Relay(key)
|
self.mRepositories[key]["Relay"] = Relay(key)
|
||||||
self.mRepositories[key]["xmlData"] = QBuffer()
|
self.mRepositories[key]["xmlData"] = QBuffer()
|
||||||
self.mRepositories[key]["state"] = 0
|
self.mRepositories[key]["state"] = 0
|
||||||
@ -392,20 +394,17 @@ class Repositories(QObject):
|
|||||||
""" start fetching the repository given by key """
|
""" start fetching the repository given by key """
|
||||||
self.mRepositories[key]["state"] = 1
|
self.mRepositories[key]["state"] = 1
|
||||||
url = QUrl(self.mRepositories[key]["url"])
|
url = QUrl(self.mRepositories[key]["url"])
|
||||||
path = url.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
|
|
||||||
path = unicode(path)
|
|
||||||
v=str(QGis.QGIS_VERSION_INT)
|
v=str(QGis.QGIS_VERSION_INT)
|
||||||
path += "?qgis=%d.%d" % ( int(v[0]), int(v[1:3]) )
|
|
||||||
port = url.port()
|
|
||||||
if port < 0:
|
url.addQueryItem('qgis', '.'.join([str(int(s)) for s in [v[0], v[1:3], v[3:5]]]) )
|
||||||
port = 80
|
|
||||||
self.mRepositories[key]["QPHttp"] = QPHttp(url.host(), port)
|
self.mRepositories[key]["QRequest"] = QNetworkRequest(url)
|
||||||
self.mRepositories[key]["QPHttp"].requestFinished.connect(self.xmlDownloaded)
|
self.mRepositories[key]["QRequest"].setAttribute( QNetworkRequest.User, key)
|
||||||
self.mRepositories[key]["QPHttp"].stateChanged.connect(self.mRepositories[key]["Relay"].stateChanged)
|
self.mRepositories[key]["xmlData"] = self.mRepositories[key]["QPNAM"].get( self.mRepositories[key]["QRequest"] )
|
||||||
self.mRepositories[key]["QPHttp"].dataReadProgress.connect(self.mRepositories[key]["Relay"].dataReadProgress)
|
self.mRepositories[key]["xmlData"].setProperty( 'reposName', key)
|
||||||
self.connect(self.mRepositories[key]["Relay"], SIGNAL("anythingChanged(unicode, int, int)"), self, SIGNAL("anythingChanged (unicode, int, int)"))
|
self.mRepositories[key]["xmlData"].downloadProgress.connect( self.mRepositories[key]["Relay"].dataReadProgress )
|
||||||
i = self.mRepositories[key]["QPHttp"].get(path, self.mRepositories[key]["xmlData"])
|
self.mRepositories[key]["QPNAM"].finished.connect( self.xmlDownloaded )
|
||||||
self.httpId[i] = key
|
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------- #
|
# ----------------------------------------- #
|
||||||
@ -420,23 +419,22 @@ class Repositories(QObject):
|
|||||||
# ----------------------------------------- #
|
# ----------------------------------------- #
|
||||||
def killConnection(self, key):
|
def killConnection(self, key):
|
||||||
""" kill the fetching on demand """
|
""" kill the fetching on demand """
|
||||||
if self.mRepositories[key]["QPHttp"].state():
|
if self.mRepositories[key]["xmlData"].isRunning():
|
||||||
self.mRepositories[key]["QPHttp"].abort()
|
self.mRepositories[key]["QPNAM"].finished.disconnect()
|
||||||
|
self.mRepositories[key]["xmlData"].abort()
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------- #
|
# ----------------------------------------- #
|
||||||
def xmlDownloaded(self,nr,state):
|
def xmlDownloaded(self, reply):
|
||||||
""" populate the plugins object with the fetched data """
|
""" populate the plugins object with the fetched data """
|
||||||
if not self.httpId.has_key(nr):
|
reposName = reply.property( 'reposName' )
|
||||||
return
|
if reply.error() != QNetworkReply.NoError: # fetching failed
|
||||||
reposName = self.httpId[nr]
|
|
||||||
if state: # fetching failed
|
|
||||||
self.mRepositories[reposName]["state"] = 3
|
self.mRepositories[reposName]["state"] = 3
|
||||||
self.mRepositories[reposName]["error"] = self.mRepositories[reposName]["QPHttp"].errorString()
|
self.mRepositories[reposName]["error"] = str(reply.error())
|
||||||
else:
|
else:
|
||||||
repoData = self.mRepositories[reposName]["xmlData"]
|
repoData = self.mRepositories[reposName]["xmlData"]
|
||||||
reposXML = QDomDocument()
|
reposXML = QDomDocument()
|
||||||
reposXML.setContent(repoData.data())
|
reposXML.setContent(repoData.readAll())
|
||||||
pluginNodes = reposXML.elementsByTagName("pyqgis_plugin")
|
pluginNodes = reposXML.elementsByTagName("pyqgis_plugin")
|
||||||
if pluginNodes.size():
|
if pluginNodes.size():
|
||||||
for i in range(pluginNodes.size()):
|
for i in range(pluginNodes.size()):
|
||||||
|
@ -49,20 +49,21 @@ class QgsPluginInstallerInstallingDialog(QDialog, Ui_QgsPluginInstallerInstallin
|
|||||||
self.buttonBox.clicked.connect(self.abort)
|
self.buttonBox.clicked.connect(self.abort)
|
||||||
|
|
||||||
url = QUrl(plugin["download_url"])
|
url = QUrl(plugin["download_url"])
|
||||||
path = unicode(url.toPercentEncoding(url.path(), "!$&'()*+,;=:/@"))
|
|
||||||
fileName = plugin["filename"]
|
fileName = plugin["filename"]
|
||||||
tmpDir = QDir.tempPath()
|
tmpDir = QDir.tempPath()
|
||||||
tmpPath = QDir.cleanPath(tmpDir+"/"+fileName)
|
tmpPath = QDir.cleanPath(tmpDir+"/"+fileName)
|
||||||
self.file = QFile(tmpPath)
|
self.file = QFile(tmpPath)
|
||||||
port = url.port()
|
|
||||||
if port < 0:
|
|
||||||
port = 80
|
|
||||||
self.http = QPHttp(url.host(), port)
|
|
||||||
self.http.stateChanged.connect(self.stateChanged)
|
|
||||||
self.http.dataReadProgress.connect(self.readProgress)
|
|
||||||
self.http.requestFinished.connect(self.requestFinished)
|
|
||||||
self.httpGetId = self.http.get(path, self.file)
|
|
||||||
|
|
||||||
|
self.nam = QPNetworkAccessManager(url.host(), )
|
||||||
|
#self.http = QPHttp(url.host(), port)
|
||||||
|
self.request = QNetworkRequest(url)
|
||||||
|
self.reply = self.nam.get( self.request )
|
||||||
|
|
||||||
|
self.reply.downloadProgress.connect( self.readProgress )
|
||||||
|
self.nam.finished.connect(self.requestFinished)
|
||||||
|
|
||||||
|
self.stateChanged(4)
|
||||||
|
|
||||||
# ----------------------------------------- #
|
# ----------------------------------------- #
|
||||||
def result(self):
|
def result(self):
|
||||||
@ -77,20 +78,21 @@ class QgsPluginInstallerInstallingDialog(QDialog, Ui_QgsPluginInstallerInstallin
|
|||||||
|
|
||||||
# ----------------------------------------- #
|
# ----------------------------------------- #
|
||||||
def readProgress(self, done, total):
|
def readProgress(self, done, total):
|
||||||
|
if total > 0:
|
||||||
self.progressBar.setMaximum(total)
|
self.progressBar.setMaximum(total)
|
||||||
self.progressBar.setValue(done)
|
self.progressBar.setValue(done)
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------- #
|
# ----------------------------------------- #
|
||||||
def requestFinished(self, requestId, state):
|
def requestFinished(self, reply):
|
||||||
if requestId != self.httpGetId:
|
|
||||||
return
|
|
||||||
self.buttonBox.setEnabled(False)
|
self.buttonBox.setEnabled(False)
|
||||||
if state:
|
if reply.error() != QNetworkReply.NoError:
|
||||||
self.mResult = self.http.errorString()
|
self.mResult = self.http.errorString()
|
||||||
self.reject()
|
self.reject()
|
||||||
return
|
return
|
||||||
|
self.file.open(QFile.WriteOnly)
|
||||||
|
self.file.write( reply.readAll() )
|
||||||
self.file.close()
|
self.file.close()
|
||||||
|
self.stateChanged(0)
|
||||||
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins"
|
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins"
|
||||||
tmpPath = self.file.fileName()
|
tmpPath = self.file.fileName()
|
||||||
# make sure that the parent directory exists
|
# make sure that the parent directory exists
|
||||||
@ -117,6 +119,8 @@ class QgsPluginInstallerInstallingDialog(QDialog, Ui_QgsPluginInstallerInstallin
|
|||||||
|
|
||||||
# ----------------------------------------- #
|
# ----------------------------------------- #
|
||||||
def abort(self):
|
def abort(self):
|
||||||
self.http.abort()
|
if self.reply.isRunning():
|
||||||
|
self.nam.finished.disconnect()
|
||||||
|
self.reply.abort()
|
||||||
self.mResult = self.tr("Aborted by user")
|
self.mResult = self.tr("Aborted by user")
|
||||||
self.reject()
|
self.reject()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user