Skip to content

Commit

Permalink
Plugin Installer minor updates
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9700 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
borysiasty committed Nov 24, 2008
1 parent 4bb72a0 commit 8ae22c3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 69 deletions.
2 changes: 1 addition & 1 deletion python/plugins/plugin_installer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def name():
return "Plugin Installer"

def version():
return "Version 0.9.2"
return "Version 0.9.3"

def description():
return "Downloads and installs QGIS python plugins"
Expand Down
58 changes: 33 additions & 25 deletions python/plugins/plugin_installer/installer_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@

"""
Data structure:
mRepositories = dict of dicts: {repoName : {"url" string,
mRepositories = dict of dicts: {repoName : {"url" QString,
"enabled" bool,
"valid" bool,
"QPHttp" QPHttp,
"Relay" Relay, # Relay object for transmitting signals from QPHttp with adding the repoName information
"xmlData" QDomDocument,
"state" int, (0 - disabled, 1-loading, 2-loaded ok, 3-error (to be retried), 4-rejected)
"error" QString}}
mPlugins = dict of dicts {id : {"name" string,
"version_avail" string,
"version_inst" string,
"desc_repo" string,
"desc_local" string,
"author" string,
"status" string, ("not installed", "installed", "upgradeable", "orphan", "new", "newer")
"error" string, ("", "broken", "incompatible", "dependent")
"error_details" string,
"homepage" string,
"url" string,
"filename" string,
"repository" string,
"localdir" string,
mPlugins = dict of dicts {id : {"name" QString,
"version_avail" QString,
"version_inst" QString,
"desc_repo" QString,
"desc_local" QString,
"author" QString,
"status" QString, ("not installed", "installed", "upgradeable", "orphan", "new", "newer")
"error" QString, ("", "broken", "incompatible", "dependent")
"error_details" QString,
"homepage" QString,
"url" QString,
"filename" QString,
"repository" QString,
"localdir" QString,
"read-only" boolean}}
"""

Expand All @@ -68,9 +68,9 @@

# knownRepos: (name, url for QGIS 0.x, url for QGIS 1.x, possible depreciated url, another possible depreciated url)
knownRepos = [("Official QGIS Repository","http://spatialserver.net/cgi-bin/pyqgis_plugin.rb","http://spatialserver.net/cgi-bin/pyqgis_plugin.rb","",""),
("Carson Farmer's Repository","http://www.ftools.ca/cfarmerQgisRepo_0.xx.xml","http://www.ftools.ca/cfarmerQgisRepo.xml", "http://www.geog.uvic.ca/spar/carson/cfarmerQgisRepo.xml",""),
("Carson Farmer's Repository","http://www.ftools.ca/cfarmerQgisRepo.xml","http://www.ftools.ca/cfarmerQgisRepo.xml", "http://www.geog.uvic.ca/spar/carson/cfarmerQgisRepo.xml","http://www.ftools.ca/cfarmerQgisRepo_0.xx.xml"),
("Borys Jurgiel's Repository","http://bwj.aster.net.pl/qgis-oldapi/plugins.xml","http://bwj.aster.net.pl/qgis/plugins.xml","",""),
("Faunalia Repository","http://faunalia.it/qgis/plugins.xml","http://faunalia.it/qgis/1.x/plugins.xml","","")]
("Faunalia Repository","http://faunalia.it/qgis/plugins.xml","http://faunalia.it/qgis/plugins.xml","http://faunalia.it/qgis/1.x/plugins.xml","")]



Expand All @@ -84,7 +84,13 @@ def __init__(self,*args):
settings.beginGroup("proxy")
if settings.value("/proxyEnabled").toBool():
self.proxy=QNetworkProxy()
self.proxy.setType(QNetworkProxy.HttpProxy)
proxyType = settings.value( "/proxyType", QVariant(0)).toString()
if proxyType in ["1","Socks5Proxy"]: self.proxy.setType(QNetworkProxy.Socks5Proxy)
elif proxyType in ["2","NoProxy"]: self.proxy.setType(QNetworkProxy.NoProxy)
elif proxyType in ["3","HttpProxy"]: self.proxy.setType(QNetworkProxy.HttpProxy)
elif proxyType in ["4","HttpCachingProxy"] and QT_VERSION >= 0X040400: self.proxy.setType(QNetworkProxy.HttpCachingProxy)
elif proxyType in ["5","FtpCachingProxy"] and QT_VERSION >= 0X040400: self.proxy.setType(QNetworkProxy.FtpCachingProxy)
else: self.proxy.setType(QNetworkProxy.DefaultProxy)
self.proxy.setHostName(settings.value("/proxyHost").toString())
self.proxy.setPort(settings.value("/proxyPort").toUInt()[0])
self.proxy.setUser(settings.value("/proxyUser").toString())
Expand Down Expand Up @@ -138,7 +144,7 @@ def addKnownRepos(self):
""" add known 3rd party repositories to QSettings """
presentURLs = []
for i in self.all().values():
presentURLs += [str(i["url"])]
presentURLs += [QString(i["url"])]
for i in knownRepos:
if i[QGIS_MAJOR_VER+1] and presentURLs.count(i[QGIS_MAJOR_VER+1]) == 0:
settings = QSettings()
Expand Down Expand Up @@ -284,7 +290,6 @@ def xmlDownloaded(self,nr,state):
if state: # fetching failed
self.mRepositories[reposName]["state"] = 3
self.mRepositories[reposName]["error"] = self.mRepositories[reposName]["QPHttp"].errorString()
#print "Repository fetching failed! " , reposName , str(self.mRepositories[reposName]["error"])
else:
repoData = self.mRepositories[reposName]["xmlData"]
reposXML = QDomDocument()
Expand All @@ -293,7 +298,8 @@ def xmlDownloaded(self,nr,state):
if pluginNodes.size():
for i in range(pluginNodes.size()):
name = QFileInfo(pluginNodes.item(i).firstChildElement("download_url").text().trimmed()).fileName()
name = str(name[0:len(name)-4])
name.chop(4)
name = str(name)
plugin = {}
plugin[name] = {
"name" : pluginNodes.item(i).toElement().attribute("name"),
Expand All @@ -312,7 +318,9 @@ def xmlDownloaded(self,nr,state):
"localdir" : name,
"read-only" : False}
#if compatible, add the plugin to list
if compareVersions(QGIS_VER, pluginNodes.item(i).firstChildElement("qgis_minimum_version").text().trimmed()) < 2:
qgisMinimumVersion = pluginNodes.item(i).firstChildElement("qgis_minimum_version").text().trimmed()
if not qgisMinimumVersion: qgisMinimumVersion = "0"
if compareVersions(QGIS_VER, qgisMinimumVersion) < 2:
plugins.addPlugin(plugin)
plugins.workarounds()
self.mRepositories[reposName]["state"] = 2
Expand Down Expand Up @@ -393,7 +401,7 @@ def updatePlugin(self, key, readOnly):
path = QgsApplication.pkgDataPath()
else:
path = QgsApplication.qgisSettingsDirPath()
path = QDir.cleanPath(unicode(path) + "/python/plugins/" + key)
path = QDir.cleanPath(path) + "/python/plugins/" + key
if not QDir(path).exists():
return
nam = ""
Expand Down Expand Up @@ -510,7 +518,7 @@ def getAllInstalled(self):
pluginDir = QDir(pluginDir)
pluginDir.setFilter(QDir.AllDirs)
for key in pluginDir.entryList():
key = str(key)
key = unicode(key)
if not key in [".",".."]:
self.updatePlugin(key, True)
except:
Expand All @@ -524,7 +532,7 @@ def getAllInstalled(self):
except:
return QCoreApplication.translate("QgsPluginInstaller","Couldn't open the local plugin directory")
for key in pluginDir.entryList():
key = str(key)
key = unicode(key)
if not key in [".",".."]:
self.updatePlugin(key, False)

Expand Down
47 changes: 18 additions & 29 deletions python/plugins/plugin_installer/installer_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,24 @@ def removeDir(path):
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.
#print " Link removing successfull: %s" % path
pass
else:
fltr = QDir.Dirs | QDir.Files | QDir.Hidden
iterator = QDirIterator(path, fltr, QDirIterator.Subdirectories)
while iterator.hasNext():
item = iterator.next()
if QFile(item).remove():
#print " File removing successfull: %s" % item
pass
fltr = QDir.Dirs | QDir.Hidden
iterator = QDirIterator(path, fltr, QDirIterator.Subdirectories)
while iterator.hasNext():
item = iterator.next()
if QDir().rmpath(item):
#print " Directory removing successfull: %s" % item
pass
if QFile(path).exists():
result = QCoreApplication.translate("QgsPluginInstaller","Failed to remove the directory:")+"\n"+path+"\n"+QCoreApplication.translate("QgsPluginInstaller","Check permissions or remove it manually")
# restore plugin directory if removed by QDir().rmpath()
pluginDir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()+"/python/plugins")
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins"
if not QDir(pluginDir).exists():
QDir().mkpath(pluginDir)
return result
Expand Down Expand Up @@ -152,7 +149,6 @@ def __init__(self, parent, plugin):
url = QUrl(plugin["url"])
path = QString(url.toPercentEncoding(url.path(), "!$&'()*+,;=:/@"))
fileName = plugin["filename"]
#print "Retrieving from %s" % path
tmpDir = QDir.tempPath()
tmpPath = QDir.cleanPath(tmpDir+"/"+fileName)
self.file = QFile(tmpPath)
Expand Down Expand Up @@ -189,36 +185,29 @@ def requestFinished(self, requestId, state):
self.mResult = self.http.errorString()
self.reject()
return

self.file.close()
pluginDir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()+"/python/plugins")
tmpPath = unicode(self.file.fileName())

pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins"
tmpPath = self.file.fileName()
# make sure that the parent directory exists
if not QDir(pluginDir).exists():
QDir().mkpath(pluginDir)

# if the target directory already exists as a link, remove the link without resolving:
QFile(pluginDir+QString(QDir.separator())+self.plugin["localdir"]).remove()

#print "Extracting to plugin directory (%s)" % pluginDir
try:
un = unzip()
un.extract(tmpPath, pluginDir) # test extract. If fails, then exception will be raised and no removing occurs
#print "Removing old plugin files if exist"
un.extract(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["localdir"])) # remove old plugin if exists
un.extract(tmpPath, pluginDir) # final extract.
un.extract(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()
return

try:
#print "Cleaning: removing the zip file (%s)" % tmpPath
# cleaning: removing the temporary zip file
QFile(tmpPath).remove()
except:
pass

self.close()


Expand Down Expand Up @@ -373,9 +362,10 @@ def filterCheck(self,plugin):
return True
else:
for i in ["name","version_inst","version_avail","desc_repo","desc_local","author","status","repository"]:
item = str(plugin[i]).upper()
item = QString(plugin[i]) #.toUpper()
if item != None:
if item.find(self.lineFilter.text().toUpper()) > -1:
if item.contains(self.lineFilter.text(), Qt.CaseInsensitive):
#if item.find(self.lineFilter.text().toUpper()) > -1:
return True
return False

Expand Down Expand Up @@ -592,7 +582,7 @@ def installPlugin(self):
plugins.setPluginData(key, "desc_local", "")
plugins.setPluginData(key, "error", "")
plugins.setPluginData(key, "error_details", "")
pluginDir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()+"/python/plugins/"+ str(plugin["localdir"]))
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/" + plugin["localdir"]
removeDir(pluginDir)
if QDir(pluginDir).exists():
infoString = (self.tr("Plugin uninstall failed"), result)
Expand Down Expand Up @@ -629,12 +619,17 @@ def uninstallPlugin(self):
warning += "\n\n"+self.tr("Warning: this plugin isn't available in any accessible repository!")
if QMessageBox.warning(self, self.tr("QGIS Python Plugin Installer"), warning , QMessageBox.Yes, QMessageBox.No) == QMessageBox.No:
return
pluginDir = unicode(QFileInfo(QgsApplication.qgisUserDbFilePath()).path()+"/python/plugins/"+ str(plugin["localdir"]))
#print "Uninstalling plugin", plugin["name"], pluginDir
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/" + plugin["localdir"]
result = removeDir(pluginDir)
if result:
QMessageBox.warning(self, self.tr("Plugin uninstall failed"), result)
else:
# safe remove
try:
exec ("plugins[%s].unload()" % plugin["localdir"])
exec ("del plugins[%s]" % plugin["localdir"])
except:
pass
try:
exec ("del sys.modules[%s]" % plugin["localdir"])
except:
Expand Down Expand Up @@ -673,7 +668,6 @@ def ChangeCheckingPolicy(self,policy):
# ----------------------------------------- #
def addKnownRepositories(self):
""" update list of known repositories - in the future it will be replaced with an online fetching """
#print "add known repositories"
message = self.tr("You are going to add some plugin repositories neither authorized nor supported by the Quantum GIS team, however provided by folks associated with us. Plugin authors generally make efforts to make their works useful and safe, but we can't assume any responsibility for them. FEEL WARNED!")
if QMessageBox.question(self, self.tr("QGIS Python Plugin Installer"), message, QMessageBox.Ok, QMessageBox.Abort) == QMessageBox.Ok:
repositories.addKnownRepos()
Expand All @@ -688,7 +682,6 @@ def addKnownRepositories(self):
# ----------------------------------------- #
def addRepository(self):
""" add repository button has been clicked """
#print "add"
dlg = QgsPluginInstallerRepositoryDialog(self)
dlg.checkBoxEnabled.setCheckState(Qt.Checked)
if not dlg.exec_():
Expand All @@ -703,8 +696,6 @@ def addRepository(self):
reposURL = dlg.editURL.text()
if repositories.all().has_key(reposName):
reposName = reposName + "(2)"
#print "name: "+reposName
#print "url: "+reposURL
# add to settings
settings.setValue(reposName+"/url", QVariant(reposURL))
settings.setValue(reposName+"/enabled", QVariant(bool(dlg.checkBoxEnabled.checkState())))
Expand All @@ -719,7 +710,6 @@ def addRepository(self):
# ----------------------------------------- #
def editRepository(self):
""" edit repository button has been clicked """
#print "edit"
checkState={False:Qt.Unchecked,True:Qt.Checked}
current = self.treeRepositories.currentItem()
if current == None:
Expand Down Expand Up @@ -766,7 +756,6 @@ def editRepository(self):
# ----------------------------------------- #
def deleteRepository(self):
""" delete repository button has been clicked """
#print "delete"
current = self.treeRepositories.currentItem()
if current == None:
return
Expand Down
25 changes: 11 additions & 14 deletions python/plugins/plugin_installer/version_compare.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
This is a Python module to compare version numbers. It's case insensitive
and recognizes all major notations, prefixes (ver. and version), delimiters
(. - and _) and suffixes (alpha, beta, rc, preview and final).
(. - and _) and suffixes (alpha, beta, rc, preview and trunk).
Usage: compareVersions(version1, version2)
Expand All @@ -25,11 +25,11 @@
The comparing stops when one of elements is greater. If comparing achieves
the end of the shorter list and the matter is still unresolved, the longer
list is usually recognized as higher, except following suffixes:
ALPHA, BETA, RC and PREVIEW which make the version number lower.
ALPHA, BETA, RC, PREVIEW and TRUNK which make the version number lower.
/***************************************************************************
* *
* Copyright (C) 2008-11-11 Borys Jurgiel *
* Copyright (C) 2008-11-24 Borys Jurgiel *
* *
***************************************************************************
* *
Expand All @@ -44,13 +44,14 @@
# ------------------------------------------------------------------------ #
def normalizeVersion(s):
""" remove possible prefix from given string and convert to uppercase """
prefixes = ['VERSION','VER.','VER','V.','V','REVISION','REV.','REV','R.','R']
if not s:
return unicode()
s = unicode(s).upper()
s = s.replace('VERSION','')
s = s.replace('VER.','')
s = s.replace('VER','')
s = s.lstrip()
for i in prefixes:
if s[:len(i)] == i:
s = s.replace(i,'')
s = s.strip()
return s


Expand Down Expand Up @@ -94,15 +95,11 @@ def compareElements(s1,s2):
else:
return 2
# if the strings aren't numeric or start from 0, compare them as a strings:
# but first, set ALPHA < BETA < PREVIEW < RC < FINAL < [NOTHING] < [ANYTHING_ELSE]
if s1 == 'FINAL':
# but first, set ALPHA < BETA < PREVIEW < RC < TRUNK < [NOTHING] < [ANYTHING_ELSE]
if not s1 in ['ALPHA','BETA','PREVIEW','RC','TRUNK']:
s1 = 'Z' + s1
elif not s1 in ['ALPHA','BETA','PREVIEW','RC']:
s1 = 'ZZ' + s1
if s2 == 'FINAL':
if not s2 in ['ALPHA','BETA','PREVIEW','RC','TRUNK']:
s2 = 'Z' + s2
elif not s2 in ['ALPHA','BETA','PREVIEW','RC']:
s2 = 'ZZ' + s2
# the final test:
if s1 > s2:
return 1
Expand Down

0 comments on commit 8ae22c3

Please sign in to comment.