[QGIS Commit] r9700 - trunk/qgis/python/plugins/plugin_installer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Nov 24 18:13:56 EST 2008


Author: borysiasty
Date: 2008-11-24 18:13:56 -0500 (Mon, 24 Nov 2008)
New Revision: 9700

Modified:
   trunk/qgis/python/plugins/plugin_installer/__init__.py
   trunk/qgis/python/plugins/plugin_installer/installer_data.py
   trunk/qgis/python/plugins/plugin_installer/installer_gui.py
   trunk/qgis/python/plugins/plugin_installer/version_compare.py
Log:
Plugin Installer minor updates

Modified: trunk/qgis/python/plugins/plugin_installer/__init__.py
===================================================================
--- trunk/qgis/python/plugins/plugin_installer/__init__.py	2008-11-24 19:29:49 UTC (rev 9699)
+++ trunk/qgis/python/plugins/plugin_installer/__init__.py	2008-11-24 23:13:56 UTC (rev 9700)
@@ -14,7 +14,7 @@
   return "Plugin Installer"
 
 def version():
-  return "Version 0.9.2"
+  return "Version 0.9.3"
 
 def description():
   return "Downloads and installs QGIS python plugins"

Modified: trunk/qgis/python/plugins/plugin_installer/installer_data.py
===================================================================
--- trunk/qgis/python/plugins/plugin_installer/installer_data.py	2008-11-24 19:29:49 UTC (rev 9699)
+++ trunk/qgis/python/plugins/plugin_installer/installer_data.py	2008-11-24 23:13:56 UTC (rev 9700)
@@ -24,7 +24,7 @@
 
 """
 Data structure:
-mRepositories = dict of dicts: {repoName : {"url" string,
+mRepositories = dict of dicts: {repoName : {"url" QString,
                                             "enabled" bool,
                                             "valid" bool,
                                             "QPHttp" QPHttp,
@@ -32,20 +32,20 @@
                                             "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}}
 """
 
@@ -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","")]
 
 
 
@@ -84,7 +84,13 @@
     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())
@@ -138,7 +144,7 @@
     """ 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()
@@ -284,7 +290,6 @@
     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()
@@ -293,7 +298,8 @@
       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"),
@@ -312,7 +318,9 @@
             "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
@@ -393,7 +401,7 @@
       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   = ""
@@ -510,7 +518,7 @@
       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:
@@ -524,7 +532,7 @@
     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)
 

Modified: trunk/qgis/python/plugins/plugin_installer/installer_gui.py
===================================================================
--- trunk/qgis/python/plugins/plugin_installer/installer_gui.py	2008-11-24 19:29:49 UTC (rev 9699)
+++ trunk/qgis/python/plugins/plugin_installer/installer_gui.py	2008-11-24 23:13:56 UTC (rev 9700)
@@ -33,7 +33,6 @@
     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
@@ -41,19 +40,17 @@
       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
@@ -152,7 +149,6 @@
     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)
@@ -189,36 +185,29 @@
       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()
 
 
@@ -373,9 +362,10 @@
       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
 
@@ -592,7 +582,7 @@
           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)
@@ -629,13 +619,18 @@
       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:
         pass
@@ -673,7 +668,6 @@
   # ----------------------------------------- #
   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()
@@ -688,7 +682,6 @@
   # ----------------------------------------- #
   def addRepository(self):
     """ add repository button has been clicked """
-    #print "add"
     dlg = QgsPluginInstallerRepositoryDialog(self)
     dlg.checkBoxEnabled.setCheckState(Qt.Checked)
     if not dlg.exec_():
@@ -703,8 +696,6 @@
     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())))
@@ -719,7 +710,6 @@
   # ----------------------------------------- #
   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:
@@ -766,7 +756,6 @@
   # ----------------------------------------- #
   def deleteRepository(self):
     """ delete repository button has been clicked """
-    #print "delete"
     current = self.treeRepositories.currentItem()
     if current == None:
       return

Modified: trunk/qgis/python/plugins/plugin_installer/version_compare.py
===================================================================
--- trunk/qgis/python/plugins/plugin_installer/version_compare.py	2008-11-24 19:29:49 UTC (rev 9699)
+++ trunk/qgis/python/plugins/plugin_installer/version_compare.py	2008-11-24 23:13:56 UTC (rev 9700)
@@ -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)
 
@@ -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                                *
  *                                                                         *
  ***************************************************************************
  *                                                                         *
@@ -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
 
 
@@ -94,15 +95,11 @@
     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



More information about the QGIS-commit mailing list