Skip to content
Permalink
Browse files

plugin installer: switch to pyqt wrappers

  • Loading branch information
jef-n committed Mar 21, 2016
1 parent 4dc6321 commit 06f995316e9674c62929f8277841d16b6ae2e754
@@ -30,8 +30,8 @@


# import functions for easier access
import installer
from installer import initPluginInstaller
from . import installer
from .installer import initPluginInstaller # NOQA


def instance():
@@ -23,19 +23,19 @@
***************************************************************************/
"""

from PyQt4.QtCore import Qt, QObject, QSettings, QDir, QUrl
from PyQt4.QtGui import QMessageBox, QLabel, QFrame, QApplication
from PyQt4.QtNetwork import QNetworkRequest
from PyQt.QtCore import Qt, QObject, QSettings, QDir, QUrl
from PyQt.QtWidgets import QMessageBox, QLabel, QFrame, QApplication
from PyQt.QtNetwork import QNetworkRequest

import qgis
from qgis.core import QgsApplication, QgsNetworkAccessManager
from qgis.gui import QgsMessageBar
from qgis.utils import iface, startPlugin, unloadPlugin, loadPlugin, reloadPlugin, updateAvailablePlugins
from installer_data import repositories, plugins, officialRepo, settingsGroup, reposGroup, removeDir
from qgsplugininstallerinstallingdialog import QgsPluginInstallerInstallingDialog
from qgsplugininstallerpluginerrordialog import QgsPluginInstallerPluginErrorDialog
from qgsplugininstallerfetchingdialog import QgsPluginInstallerFetchingDialog
from qgsplugininstallerrepositorydialog import QgsPluginInstallerRepositoryDialog
from .installer_data import repositories, plugins, officialRepo, settingsGroup, reposGroup, removeDir
from .qgsplugininstallerinstallingdialog import QgsPluginInstallerInstallingDialog
from .qgsplugininstallerpluginerrordialog import QgsPluginInstallerPluginErrorDialog
from .qgsplugininstallerfetchingdialog import QgsPluginInstallerFetchingDialog
from .qgsplugininstallerrepositorydialog import QgsPluginInstallerRepositoryDialog


# public instances:
@@ -58,7 +58,7 @@ class QgsPluginInstaller(QObject):
def __init__(self):
""" Initialize data objects, starts fetching if appropriate, and warn about/removes obsolete plugins """

QObject.__init__(self) # initialize QObject in order to to use self.tr()
QObject.__init__(self) # initialize QObject in order to to use self.tr()
repositories.load()
plugins.getAllInstalled()

@@ -109,7 +109,7 @@ def fetchAvailablePlugins(self, reloadMode):
plugins.getAllInstalled()

for key in repositories.allEnabled():
if reloadMode or repositories.all()[key]["state"] == 3: # if state = 3 (error or not fetched yet), try to fetch once again
if reloadMode or repositories.all()[key]["state"] == 3: # if state = 3 (error or not fetched yet), try to fetch once again
repositories.requestFetching(key)

if repositories.fetchingInProgress():
@@ -147,12 +147,12 @@ def checkingDone(self):
for key in plugins.all():
if plugins.all()[key]["status"] == "new":
status = self.tr("There is a new plugin available")
tabIndex = 4 # PLUGMAN_TAB_NEW
tabIndex = 4 # PLUGMAN_TAB_NEW
# then check for updates (and eventually overwrite status)
for key in plugins.all():
if plugins.all()[key]["status"] == "upgradeable":
status = self.tr("There is a plugin update available")
tabIndex = 3 # PLUGMAN_TAB_UPGRADEABLE
tabIndex = 3 # PLUGMAN_TAB_UPGRADEABLE
# finally set the notify label
if status:
self.statusLabel.setText(u' <a href="%d">%s</a> ' % (tabIndex, status))
@@ -275,7 +275,7 @@ def installPlugin(self, key, quiet=False):
previousStatus = plugin["status"]
if not plugin:
return
if plugin["status"] == "newer" and not plugin["error"]: # ask for confirmation if user downgrades an usable plugin
if plugin["status"] == "newer" and not plugin["error"]: # ask for confirmation if user downgrades an usable plugin
if QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), self.tr("Are you sure you want to downgrade the plugin to the latest available version? The installed one is newer!"), QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
return

@@ -310,11 +310,11 @@ def installPlugin(self, key, quiet=False):
settings.setValue("/PythonPlugins/" + plugin["id"], True)
else:
settings = QSettings()
if settings.value("/PythonPlugins/" + key, False, type=bool): # plugin will be reloaded on the fly only if currently loaded
reloadPlugin(key) # unloadPlugin + loadPlugin + startPlugin
if settings.value("/PythonPlugins/" + key, False, type=bool): # plugin will be reloaded on the fly only if currently loaded
reloadPlugin(key) # unloadPlugin + loadPlugin + startPlugin
infoString = (self.tr("Plugin reinstalled successfully"), "")
else:
unloadPlugin(key) # Just for a case. Will exit quietly if really not loaded
unloadPlugin(key) # Just for a case. Will exit quietly if really not loaded
loadPlugin(key)
infoString = (self.tr("Plugin reinstalled successfully"), self.tr("Python plugin reinstalled.\nYou need to restart QGIS in order to reload it."))
if quiet:
@@ -456,7 +456,7 @@ def editRepository(self, reposName):
dlg.labelInfo.setText(self.tr("This repository is blocked due to incompatibility with your QGIS version"))
dlg.labelInfo.setFrameShape(QFrame.Box)
if not dlg.exec_():
return # nothing to do if cancelled
return # nothing to do if cancelled
for i in repositories.all().values():
if dlg.editURL.text().strip() == i["url"] and dlg.editURL.text().strip() != repositories.all()[reposName]["url"]:
iface.pluginManagerInterface().pushMessage(self.tr("Unable to add another repository with the same URL!"), QgsMessageBar.WARNING)
@@ -476,7 +476,7 @@ def editRepository(self, reposName):
if dlg.editURL.text().strip() == repositories.all()[reposName]["url"] and dlg.checkBoxEnabled.checkState() == checkState[repositories.all()[reposName]["enabled"]]:
repositories.rename(reposName, newName)
self.exportRepositoriesToManager()
return # nothing else to do if only repository name was changed
return # nothing else to do if only repository name was changed
plugins.removeRepository(reposName)
self.reloadAndExportData()

@@ -23,9 +23,9 @@
***************************************************************************/
"""

from PyQt4.QtCore import pyqtSignal, QObject, QCoreApplication, QFile, QDir, QDirIterator, QSettings, QDate, QUrl, QFileInfo, QLocale, QByteArray
from PyQt4.QtXml import QDomDocument
from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply
from PyQt.QtCore import pyqtSignal, QObject, QCoreApplication, QFile, QDir, QDirIterator, QSettings, QDate, QUrl, QFileInfo, QLocale, QByteArray
from PyQt.QtXml import QDomDocument
from PyQt.QtNetwork import QNetworkRequest, QNetworkReply
import sys
import os
import codecs
@@ -34,7 +34,7 @@
from qgis.core import QGis, QgsNetworkAccessManager, QgsAuthManager
from qgis.gui import QgsMessageBar
from qgis.utils import iface, plugin_paths
from version_compare import compareVersions, normalizeVersion, isCompatible
from .version_compare import compareVersions, normalizeVersion, isCompatible


"""
@@ -118,7 +118,7 @@ def removeDir(path):
result = ""
if not QFile(path).exists():
result = QCoreApplication.translate("QgsPluginInstaller", "Nothing to remove! Plugin directory doesn't exist:") + "\n" + path
elif QFile(path).remove(): # if it is only link, just remove it without resolving.
elif QFile(path).remove(): # if it is only link, just remove it without resolving.
pass
else:
fltr = QDir.Dirs | QDir.Files | QDir.Hidden
@@ -314,7 +314,7 @@ def load(self):
if url == officialRepo[1]:
officialRepoPresent = True
if url == officialRepo[2]:
settings.setValue(key + "/url", officialRepo[1]) # correct a depreciated url
settings.setValue(key + "/url", officialRepo[1]) # correct a depreciated url
officialRepoPresent = True
if not officialRepoPresent:
settings.setValue(officialRepo[0] + "/url", officialRepo[1])
@@ -499,10 +499,10 @@ class Plugins(QObject):

def __init__(self):
QObject.__init__(self)
self.mPlugins = {} # the dict of plugins (dicts)
self.repoCache = {} # the dict of lists of plugins (dicts)
self.localCache = {} # the dict of plugins (dicts)
self.obsoletePlugins = [] # the list of outdated 'user' plugins masking newer 'system' ones
self.mPlugins = {} # the dict of plugins (dicts)
self.repoCache = {} # the dict of lists of plugins (dicts)
self.localCache = {} # the dict of plugins (dicts)
self.obsoletePlugins = [] # the list of outdated 'user' plugins masking newer 'system' ones

# ----------------------------------------- #
def all(self):
@@ -566,7 +566,7 @@ def metadataParser(fct):
return cp.get('general', fct)
except Exception as e:
if not errorDetails:
errorDetails = e.args[0] # set to the first problem
errorDetails = e.args[0] # set to the first problem
return ""

def pluginMetadata(fct):
@@ -585,7 +585,7 @@ def pluginMetadata(fct):
if not QDir(path).exists():
return

global errorDetails # to communicate with the metadataParser fn
global errorDetails # to communicate with the metadataParser fn
plugin = dict()
error = ""
errorDetails = ""
@@ -728,7 +728,7 @@ def rebuild(self):
allowDeprecated = settings.value(settingsGroup + "/allowDeprecated", False, type=bool)
for i in self.repoCache.values():
for j in i:
plugin = j.copy() # do not update repoCache elements!
plugin = j.copy() # do not update repoCache elements!
key = plugin["id"]
# check if the plugin is allowed and if there isn't any better one added already.
if (allowExperimental or not plugin["experimental"]) \
@@ -24,10 +24,10 @@
***************************************************************************/
"""

from PyQt4.QtGui import QDialog, QTreeWidgetItem
from PyQt.QtWidgets import QDialog, QTreeWidgetItem

from ui_qgsplugininstallerfetchingbase import Ui_QgsPluginInstallerFetchingDialogBase
from installer_data import repositories
from .ui_qgsplugininstallerfetchingbase import Ui_QgsPluginInstallerFetchingDialogBase
from .installer_data import repositories


class QgsPluginInstallerFetchingDialog(QDialog, Ui_QgsPluginInstallerFetchingDialogBase):
@@ -24,16 +24,16 @@
***************************************************************************/
"""

from PyQt4.QtCore import QDir, QUrl, QFile, QCoreApplication
from PyQt4.QtGui import QDialog
from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply
from PyQt.QtCore import QDir, QUrl, QFile, QCoreApplication
from PyQt.QtWidgets import QDialog
from PyQt.QtNetwork import QNetworkRequest, QNetworkReply

import qgis
from qgis.core import QgsNetworkAccessManager, QgsAuthManager

from ui_qgsplugininstallerinstallingbase import Ui_QgsPluginInstallerInstallingDialogBase
from installer_data import removeDir, repositories
from unzip import unzip
from .ui_qgsplugininstallerinstallingbase import Ui_QgsPluginInstallerInstallingDialogBase
from .installer_data import removeDir, repositories
from .unzip import unzip


class QgsPluginInstallerInstallingDialog(QDialog, Ui_QgsPluginInstallerInstallingDialogBase):
@@ -118,10 +118,10 @@ def requestFinished(self):
# if the target directory already exists as a link, remove the link without resolving:
QFile(pluginDir + unicode(QDir.separator()) + self.plugin["id"]).remove()
try:
unzip(unicode(tmpPath), unicode(pluginDir)) # test extract. If fails, then exception will be raised and no removing occurs
unzip(unicode(tmpPath), unicode(pluginDir)) # test extract. If fails, then exception will be raised and no removing occurs
# removing old plugin files if exist
removeDir(QDir.cleanPath(pluginDir + "/" + self.plugin["id"])) # remove old plugin if exists
unzip(unicode(tmpPath), unicode(pluginDir)) # final extract.
removeDir(QDir.cleanPath(pluginDir + "/" + self.plugin["id"])) # remove old plugin if exists
unzip(unicode(tmpPath), unicode(pluginDir)) # final extract.
except:
self.mResult = self.tr("Failed to unzip the plugin package. Probably it's broken or missing from the repository. You may also want to make sure that you have write permission to the plugin directory:") + "\n" + pluginDir
self.reject()
@@ -24,9 +24,9 @@
***************************************************************************/
"""

from PyQt4.QtGui import QDialog
from PyQt.QtWidgets import QDialog

from ui_qgsplugininstallerpluginerrorbase import Ui_QgsPluginInstallerPluginErrorDialogBase
from .ui_qgsplugininstallerpluginerrorbase import Ui_QgsPluginInstallerPluginErrorDialogBase


class QgsPluginInstallerPluginErrorDialog(QDialog, Ui_QgsPluginInstallerPluginErrorDialogBase):
@@ -25,10 +25,10 @@
"""

from qgis.gui import QgsAuthConfigSelect
from PyQt4.QtGui import QDialog, QDialogButtonBox, QVBoxLayout
from PyQt4.QtCore import Qt
from PyQt.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout
from PyQt.QtCore import Qt

from ui_qgsplugininstallerrepositorybase import Ui_QgsPluginInstallerRepositoryDetailsDialogBase
from .ui_qgsplugininstallerrepositorybase import Ui_QgsPluginInstallerRepositoryDetailsDialogBase


class QgsPluginInstallerRepositoryDialog(QDialog, Ui_QgsPluginInstallerRepositoryDetailsDialogBase):

0 comments on commit 06f9953

Please sign in to comment.
You can’t perform that action at this time.