PluginManager/PluginInstallDialog.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 3056
9986ec0e559a
parent 2992
dbdf27746da5
child 3060
5883ce99ee12
--- a/PluginManager/PluginInstallDialog.py	Tue Oct 15 22:03:54 2013 +0200
+++ b/PluginManager/PluginInstallDialog.py	Fri Oct 18 23:00:41 2013 +0200
@@ -21,8 +21,8 @@
     import urlparse as parse
 
 from PyQt4.QtCore import pyqtSlot, Qt, QDir, QFileInfo
-from PyQt4.QtGui import QWidget, QDialogButtonBox, QAbstractButton, QApplication, \
-    QDialog, QVBoxLayout
+from PyQt4.QtGui import QWidget, QDialogButtonBox, QAbstractButton, \
+    QApplication, QDialog, QVBoxLayout
 
 from E5Gui import E5FileDialog
 from E5Gui.E5MainWindow import E5MainWindow
@@ -60,24 +60,26 @@
             self.__pluginManager = pluginManager
             self.__external = False
         
-        self.__backButton = \
-            self.buttonBox.addButton(self.trUtf8("< Back"), QDialogButtonBox.ActionRole)
-        self.__nextButton = \
-            self.buttonBox.addButton(self.trUtf8("Next >"), QDialogButtonBox.ActionRole)
-        self.__finishButton = \
-            self.buttonBox.addButton(self.trUtf8("Install"), QDialogButtonBox.ActionRole)
+        self.__backButton = self.buttonBox.addButton(
+            self.trUtf8("< Back"), QDialogButtonBox.ActionRole)
+        self.__nextButton = self.buttonBox.addButton(
+            self.trUtf8("Next >"), QDialogButtonBox.ActionRole)
+        self.__finishButton = self.buttonBox.addButton(
+            self.trUtf8("Install"), QDialogButtonBox.ActionRole)
         
         self.__closeButton = self.buttonBox.button(QDialogButtonBox.Close)
         self.__cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel)
         
         userDir = self.__pluginManager.getPluginDir("user")
         if userDir is not None:
-            self.destinationCombo.addItem(self.trUtf8("User plugins directory"),
+            self.destinationCombo.addItem(
+                self.trUtf8("User plugins directory"),
                 userDir)
         
         globalDir = self.__pluginManager.getPluginDir("global")
         if globalDir is not None and os.access(globalDir, os.W_OK):
-            self.destinationCombo.addItem(self.trUtf8("Global plugins directory"),
+            self.destinationCombo.addItem(
+                self.trUtf8("Global plugins directory"),
                 globalDir)
         
         self.__installedDirs = []
@@ -89,7 +91,8 @@
         for pluginFileName in pluginFileNames:
             fi = QFileInfo(pluginFileName)
             if fi.isRelative():
-                pluginFileName = QFileInfo(downloadDir, fi.fileName()).absoluteFilePath()
+                pluginFileName = QFileInfo(
+                    downloadDir, fi.fileName()).absoluteFilePath()
             self.archivesList.addItem(pluginFileName)
             self.archivesList.sortItems()
         
@@ -139,7 +142,8 @@
             self.__closeButton.hide()
             self.__cancelButton.show()
             
-            msg = self.trUtf8("Plugin ZIP-Archives:\n{0}\n\nDestination:\n{1} ({2})")\
+            msg = self.trUtf8(
+                "Plugin ZIP-Archives:\n{0}\n\nDestination:\n{1} ({2})")\
                 .format("\n".join(self.__createArchivesList()),
                         self.destinationCombo.currentText(),
                         self.destinationCombo.itemData(
@@ -176,7 +180,8 @@
         """
         Private slot called, when the selection of the archives list changes.
         """
-        self.removeArchivesButton.setEnabled(len(self.archivesList.selectedItems()) > 0)
+        self.removeArchivesButton.setEnabled(
+            len(self.archivesList.selectedItems()) > 0)
     
     @pyqtSlot()
     def on_removeArchivesButton_clicked(self):
@@ -184,7 +189,8 @@
         Private slot to remove archives from the list.
         """
         for archiveItem in self.archivesList.selectedItems():
-            itm = self.archivesList.takeItem(self.archivesList.row(archiveItem))
+            itm = self.archivesList.takeItem(
+                self.archivesList.row(archiveItem))
             del itm
         
         self.__nextButton.setEnabled(self.archivesList.count() > 0)
@@ -193,6 +199,8 @@
     def on_buttonBox_clicked(self, button):
         """
         Private slot to handle the click of a button of the button box.
+        
+        @param button reference to the button pressed (QAbstractButton)
         """
         if button == self.__backButton:
             self.__currentIndex -= 1
@@ -215,7 +223,8 @@
         res = True
         self.summaryEdit.clear()
         for archive in self.__createArchivesList():
-            self.summaryEdit.append(self.trUtf8("Installing {0} ...").format(archive))
+            self.summaryEdit.append(
+                self.trUtf8("Installing {0} ...").format(archive))
             ok, msg, restart = self.__installPlugin(archive)
             res = res and ok
             if ok:
@@ -247,8 +256,8 @@
         installedPluginName = ""
         
         archive = archiveFilename
-        destination = \
-            self.destinationCombo.itemData(self.destinationCombo.currentIndex())
+        destination = self.destinationCombo.itemData(
+            self.destinationCombo.currentIndex())
         
         # check if archive is a local url
         url = parse.urlparse(archive)
@@ -258,22 +267,25 @@
         # check, if the archive exists
         if not os.path.exists(archive):
             return False, \
-                self.trUtf8("""<p>The archive file <b>{0}</b> does not exist. """
-                            """Aborting...</p>""").format(archive), \
+                self.trUtf8(
+                    """<p>The archive file <b>{0}</b> does not exist. """
+                    """Aborting...</p>""").format(archive), \
                 False
         
         # check, if the archive is a valid zip file
         if not zipfile.is_zipfile(archive):
             return False, \
-                self.trUtf8("""<p>The file <b>{0}</b> is not a valid plugin """
-                            """ZIP-archive. Aborting...</p>""").format(archive), \
+                self.trUtf8(
+                    """<p>The file <b>{0}</b> is not a valid plugin """
+                    """ZIP-archive. Aborting...</p>""").format(archive), \
                 False
         
         # check, if the destination is writeable
         if not os.access(destination, os.W_OK):
             return False, \
-                self.trUtf8("""<p>The destination directory <b>{0}</b> is not """
-                            """writeable. Aborting...</p>""").format(destination), \
+                self.trUtf8(
+                    """<p>The destination directory <b>{0}</b> is not """
+                    """writeable. Aborting...</p>""").format(destination), \
                 False
         
         zip = zipfile.ZipFile(archive, "r")
@@ -290,8 +302,9 @@
         
         if not pluginFound:
             return False, \
-                self.trUtf8("""<p>The file <b>{0}</b> is not a valid plugin """
-                            """ZIP-archive. Aborting...</p>""").format(archive), \
+                self.trUtf8(
+                    """<p>The file <b>{0}</b> is not a valid plugin """
+                    """ZIP-archive. Aborting...</p>""").format(archive), \
                 False
         
         # parse the plugin module's plugin header
@@ -313,7 +326,8 @@
                             packageName = "None"
             elif line.startswith("internalPackages"):
                 tokens = line.split("=")
-                token = tokens[1].strip()[1:-1]    # it is a comma separated string
+                token = tokens[1].strip()[1:-1]
+                # it is a comma separated string
                 internalPackages = [p.strip() for p in token.split(",")]
             elif line.startswith("needsRestart"):
                 tokens = line.split("=")
@@ -333,15 +347,17 @@
         
         if not packageName:
             return False, \
-                self.trUtf8("""<p>The plugin module <b>{0}</b> does not contain """
-                            """a 'packageName' attribute. Aborting...</p>""")\
+                self.trUtf8(
+                    """<p>The plugin module <b>{0}</b> does not contain """
+                    """a 'packageName' attribute. Aborting...</p>""")\
                     .format(pluginFileName), \
                 False
         
         if pyqtApi < 2:
             return False, \
-                self.trUtf8("""<p>The plugin module <b>{0}</b> does not conform"""
-                            """ with the PyQt v2 API. Aborting...</p>""")\
+                self.trUtf8(
+                    """<p>The plugin module <b>{0}</b> does not conform"""
+                    """ with the PyQt v2 API. Aborting...</p>""")\
                     .format(pluginFileName), \
                 False
         
@@ -367,7 +383,8 @@
         activatePlugin = False
         if not self.__external:
             activatePlugin = \
-                not self.__pluginManager.isPluginLoaded(installedPluginName) or \
+                not self.__pluginManager.isPluginLoaded(
+                    installedPluginName) or \
                 (self.__pluginManager.isPluginLoaded(installedPluginName) and \
                  self.__pluginManager.isPluginActive(installedPluginName))
             # try to unload a plugin with the same name
@@ -425,17 +442,20 @@
         except os.error as why:
             self.__rollback()
             return False, \
-                self.trUtf8("Error installing plugin. Reason: {0}").format(str(why)), \
+                self.trUtf8(
+                    "Error installing plugin. Reason: {0}").format(str(why)), \
                 False
         except IOError as why:
             self.__rollback()
             return False, \
-                self.trUtf8("Error installing plugin. Reason: {0}").format(str(why)), \
+                self.trUtf8(
+                    "Error installing plugin. Reason: {0}").format(str(why)), \
                 False
         except OSError as why:
             self.__rollback()
             return False, \
-                self.trUtf8("Error installing plugin. Reason: {0}").format(str(why)), \
+                self.trUtf8(
+                    "Error installing plugin. Reason: {0}").format(str(why)), \
                 False
         except:
             sys.stderr.write("Unspecific exception installing plugin.\n")
@@ -446,12 +466,15 @@
         
         # now compile the plugins
         if doCompile:
-            compileall.compile_dir(os.path.join(destination, packageName), quiet=True)
-            compileall.compile_file(os.path.join(destination, pluginFileName), quiet=True)
+            compileall.compile_dir(
+                os.path.join(destination, packageName), quiet=True)
+            compileall.compile_file(
+                os.path.join(destination, pluginFileName), quiet=True)
         
         if not self.__external:
             # now load and activate the plugin
-            self.__pluginManager.loadPlugin(installedPluginName, destination, reload_)
+            self.__pluginManager.loadPlugin(installedPluginName, destination,
+                                            reload_)
             if activatePlugin:
                 self.__pluginManager.activatePlugin(installedPluginName)
         
@@ -483,7 +506,8 @@
             head, tail = os.path.split(head)
         if head and tail and not os.path.exists(head):
             self.__makedirs(head, mode)
-            if tail == os.curdir:           # xxx/newdir/. exists if xxx/newdir exists
+            if tail == os.curdir:
+                # xxx/newdir/. exists if xxx/newdir exists
                 return
         os.mkdir(name, mode)
         self.__installedDirs.append(name)
@@ -515,14 +539,18 @@
             if os.path.exists(fnamec):
                 os.remove(fnamec)
             
-            pluginDirCache = os.path.join(os.path.dirname(pluginFile), "__pycache__")
+            pluginDirCache = os.path.join(
+                os.path.dirname(pluginFile), "__pycache__")
             if os.path.exists(pluginDirCache):
-                pluginFileName = os.path.splitext(os.path.basename(pluginFile))[0]
+                pluginFileName = os.path.splitext(
+                    os.path.basename(pluginFile))[0]
                 for fnameo in glob.glob(
-                    os.path.join(pluginDirCache, "{0}*.pyo".format(pluginFileName))):
+                    os.path.join(pluginDirCache,
+                                 "{0}*.pyo".format(pluginFileName))):
                     os.remove(fnameo)
                 for fnamec in glob.glob(
-                    os.path.join(pluginDirCache, "{0}*.pyc".format(pluginFileName))):
+                    os.path.join(pluginDirCache,
+                                 "{0}*.pyc".format(pluginFileName))):
                     os.remove(fnamec)
             
             os.remove(pluginFile)
@@ -586,7 +614,8 @@
         self.setCentralWidget(self.cw)
         self.resize(size)
         
-        self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet"))
+        self.setStyle(Preferences.getUI("Style"),
+                      Preferences.getUI("StyleSheet"))
         
         self.cw.buttonBox.accepted[()].connect(self.close)
         self.cw.buttonBox.rejected[()].connect(self.close)

eric ide

mercurial