PluginVulture.py

changeset 2
b517a1c5d5de
parent 1
ea6aed49cd69
child 4
2a12ec365dd1
diff -r ea6aed49cd69 -r b517a1c5d5de PluginVulture.py
--- a/PluginVulture.py	Sat Oct 03 19:07:40 2015 +0200
+++ b/PluginVulture.py	Sun Oct 04 18:28:36 2015 +0200
@@ -17,6 +17,7 @@
 from E5Gui.E5Action import E5Action
 
 import Preferences
+from Utilities import determinePythonVersion
 
 # Start-Of-Header
 name = "PluginVulture"
@@ -42,12 +43,14 @@
     """
     Class documentation goes here.
     
-    @signal metricsDone(str, dict) emitted when the code metrics were
-        determined for a file
+    @signal analysisDone(str, dict) emitted when the code analysis has
+        been completed for a file
     @signal error(str, str) emitted in case of an error
     @signal batchFinished() emitted when a style check batch is done
     """
+    analysisDone = pyqtSignal(str, dict)
     batchFinished = pyqtSignal()
+    error = pyqtSignal(str, str)
     
     def __init__(self, ui):
         """
@@ -73,6 +76,7 @@
                 self.vultureCheckDone,
                 onErrorCallback=self.serviceErrorPy3,
                 onBatchDone=self.batchJobDone)
+            self.hasBatch = True
         except TypeError:
             # backward compatibility for eric 6.0
             self.backgroundService.serviceConnect(
@@ -83,6 +87,7 @@
                 'vulture', 'Python3', path, 'VultureCheckerService',
                 self.vultureCheckDone,
                 onErrorCallback=self.serviceErrorPy3)
+            self.hasBatch = False
         
         self.queuedBatches = []
         self.batchesFinished = True
@@ -160,6 +165,17 @@
                 self.batchFinished.emit()
                 self.batchesFinished = True
     
+    def vultureCheckDone(self, filename, result):
+        """
+        Public slot to dispatch the result.
+        
+        @param filename name of the file the results belong to
+        @type str
+        @param result result dictionary
+        @type dict
+        """
+        self.analysisDone.emit(filename, result)
+    
     def __initialize(self):
         """
         Private slot to (re)initialize the plug-in.
@@ -167,17 +183,60 @@
         self.__projectAct = None
         self.__projectVultureCheckerDialog = None
 
-    def vultureCheck(self, lang, filenames):
+    def vultureCheck(self, lang, filename, source):
         """
         Public method to prepare a vulture check for a Python project.
 
         @param lang language of the files or None to determine by internal
             algorithm
         @type str or None
-        @param filenames list of file names to include in the check
-        @type list of str
+        @param filename name of the file to analyze
+        @type str
+        @param source string containing the code
+        @type str
+        """
+        if lang is None:
+            lang = 'Python{0}'.format(determinePythonVersion(filename, source))
+        if lang not in ['Python2', 'Python3']:
+            return
+        
+        self.backgroundService.enqueueRequest(
+            'vulture', lang, filename, [source])
+
+    def vultureCheckBatch(self, argumentsList):
+        """
+        Public method to prepare a vulture check for a Python project using
+        the batch mode.
+        
+        @param argumentsList list of arguments tuples with each tuple
+            containing filename and source
+        @type (str, str)
         """
-        # TODO: implement this
+        data = {
+            "Python2": [],
+            "Python3": [],
+        }
+        for filename, source in argumentsList:
+            lang = 'Python{0}'.format(determinePythonVersion(filename, source))
+            if lang not in ['Python2', 'Python3']:
+                continue
+            else:
+                data[lang].append((filename, source))
+        
+        self.queuedBatches = []
+        for lang in ['Python2', 'Python3']:
+            if data[lang]:
+                self.queuedBatches.append(lang)
+                self.backgroundService.enqueueRequest('batch_vulture', lang,
+                                                      "", data[lang])
+                self.batchesFinished = False
+    
+    def cancelVultureCheckBatch(self):
+        """
+        Public method to cancel all batch jobs.
+        """
+        for lang in ['Python2', 'Python3']:
+            self.backgroundService.requestCancel('batch_vulture', lang)
     
     def activate(self):
         """
@@ -206,8 +265,8 @@
             menu.addAction(self.__projectAct)
         
         e5App().getObject("Project").showMenu.connect(self.__projectShowMenu)
-        e5App().getObject("Project").projectClosed.connect(
-            self.__projectClosed)
+##        e5App().getObject("Project").projectClosed.connect(
+##            self.__projectClosed)
         
         return None, True
     
@@ -279,6 +338,6 @@
         if self.__projectVultureCheckerDialog is None:
             from VultureChecker.VultureCheckerDialog import \
                 VultureCheckerDialog
-            self.__projectRawMetricsDialog = VultureCheckerDialog(self)
+            self.__projectVultureCheckerDialog = VultureCheckerDialog(self)
         self.__projectVultureCheckerDialog.show()
         self.__projectVultureCheckerDialog.prepare(files, project)

eric ide

mercurial