Skip to content

Commit

Permalink
plugin installer: switch to pyqt wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Mar 21, 2016
1 parent 4dc6321 commit 06f9953
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
4 changes: 2 additions & 2 deletions python/pyplugin_installer/__init__.py
Expand Up @@ -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():
Expand Down
36 changes: 18 additions & 18 deletions python/pyplugin_installer/installer.py
Expand Up @@ -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:
Expand All @@ -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()

Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down
26 changes: 13 additions & 13 deletions python/pyplugin_installer/installer_data.py
Expand Up @@ -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
Expand All @@ -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


"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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 = ""
Expand Down Expand Up @@ -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"]) \
Expand Down
6 changes: 3 additions & 3 deletions python/pyplugin_installer/qgsplugininstallerfetchingdialog.py
Expand Up @@ -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):
Expand Down
18 changes: 9 additions & 9 deletions python/pyplugin_installer/qgsplugininstallerinstallingdialog.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
Expand Up @@ -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):
Expand Down
Expand Up @@ -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):
Expand Down

0 comments on commit 06f9953

Please sign in to comment.