Commits

berson_r  committed 25de26a

Added comments, fixed some methods' names, removed method endFile (useless)

  • Participants
  • Parent commits 4f7a006

Comments (0)

Files changed (3)

File src/modelViewer/importScan.py

 
 
 def getScan():
+    """
+    Return an object with the scanner corresponding
+    to this module.
+    """
     return ImportScan()
 
+
 class ImportScan:
+    """
+    Scanner that will detect the import directives in a python files
+    and return edges of the corresponding graph.
+    """
 
     def __init__(self):
+        """
+        Defines list of edges and the regex that will detect the import directives.
+        -> edges have the corresponding format :  (obj, base, info)
+        """
         self.edges = []
         mod = '[a-zA-Z, _-]+'
         simpleImport = 'import[ ]+(?P<mod1>%s)' % (mod)
         self.prefix = fileName.split('.')[0]
         self.edges = []
 
-    def endFile(self):
-        pass
-
-    def scanLine(self, f):
+    def scanFile(self, f):
         for m in self.importPattern.finditer(f.read()):
             info = ''
             if m.group('info'):

File src/modelViewer/inheritanceScan.py

 import re
 
 def getScan():
+    """
+    Return an object with the scanner corresponding
+    to this module.
+    """
     return InheritanceScan()
 
 
 class InheritanceScan:
+    """
+    Scanner that will detect the inheritance in a python files
+    and return edges of the corresponding graph.
+    """
 
     def __init__(self):
+        """
+        Defines list of edges and the regex that will detect the import directives.
+        -> edges have the corresponding format :  (obj, base, info)
+        """
         self.edges = []
         mod = '[a-zA-Z, _\.-]+'
         inheritPattern = 'class[ ]+(?P<obj>%s)\((?P<base>%s)\):' % (mod, mod)
     def beginFile(self, fileName):
         self.edges = []
 
-    def endFile(self):
-        pass
-
-    def scanLine(self, f):
+    def scanFile(self, f):
         for m in self.inheritPattern.finditer(f.read()):
             self.edges.append((m.group('obj'), m.group('base'), ''))

File src/modelViewer/modelViewer.py

     """
 
     def __init__(self, validExt, dotName, scanner):
+        """
+        Init the modelViewer with the good scanner,
+        colors, dot file, etc.
+        """
         self.scanner = scanner
         self.ext = validExt
         self.dot = open(dotName, 'w')
-        self.colors = ['black', 'blue', 'red', 'gray', 'green', 'yellow',\
-                       'turquoise', 'sienna']
+        self.colors = ['black', 'blue', 'red', 'gray',\
+                       'green', 'yellow', 'turquoise', 'sienna']
 
         # Manage colors
         self.currentCol = 0
         Parse files and subdirectories from the @path given
         as argument. Result will be added in the dot file.
         """
-
         current = os.getcwd()
         os.chdir(path)
         self.setColor(os.getcwd())
         """
         End and close the @dot file.
         """
-        # Close dot file
         self.dot.write("}")
         self.dot.close()
 
 
     def parseFile(self, filePath):
         """
-        Parse the file @filePath looking for models
-        and writes new edges in the @dot file using the
-        good colors.
+        Parse the file @filePath using the current scanner.
+        Write the edges to the dot file.
         """
-
         self.scanner.beginFile(filePath)
 
         # Parse file
         f = open(filePath, 'r')
-        self.scanner.scanLine(f)
+        self.scanner.scanFile(f)
         f.close()
 
         for u, v, info in self.scanner.getEdges():
             self.dotAddEdge(u, v, info)
 
-        self.scanner.endFile()
-
 
     def dotAddEdge(self, u, v, info):
         """