Exemplo n.º 1
0
 def __createFieldByType__(self, fieldNo, fType, fName, fLocation, line,
                           Global, CrossReference):
     logger.debug("Current Type is [%s]" % fType)
     result = self.UNDEFINED_POINTER.search(fType)
     if result:
         self._field = FileManFieldFactory.createField(
             fieldNo, fName, FileManField.FIELD_TYPE_FILE_POINTER,
             fLocation)
         return
     result = self.POINTER_TO_REGEX.search(fType)
     if result:
         fileNo = result.group('File')
         filePointedTo = CrossReference.getGlobalByFileNo(fileNo)
         self._field = FileManFieldFactory.createField(
             fieldNo, fName, FileManField.FIELD_TYPE_FILE_POINTER,
             fLocation)
         if not filePointedTo:
             logger.error(
                 "Could not find file pointed to [%s], [%s], line:[%s]" %
                 (fileNo, self._curFile, line))
         else:
             self._field.setPointedToFile(filePointedTo)
         return
     # deal with file pointer to subFiles
     result = self.SUBFILE_REGEX.search(fType)
     if result:
         # create a field for sub file type
         self._field = FileManFieldFactory.createField(
             fieldNo, fName, FileManField.FIELD_TYPE_SUBFILE_POINTER,
             fLocation)
         fileNo = result.group('File')
         logger.debug("Pointer to subFile %s" % fileNo)
         subFile = Global.getSubFileByFileNo(fileNo)
         if not subFile:
             subFile = FileManFile(fileNo, fName, self._curFile)
             self._curFile.addFileManSubFile(subFile)
             logger.debug("Added subFile %s to File %s" %
                          (fileNo, self._curFile.getFileNo()))
             if self._isSubFile:
                 Global.addFileManSubFile(subFile)
         self._field.setPointedToSubFile(subFile)
         return
     for (key, value) in self.StringTypeMappingDict.iteritems():
         if fType.startswith(key):
             self._field = FileManFieldFactory.createField(
                 fieldNo, fName, value, fLocation)
             break
     if not self._field:
         # double check the loc and type
         if line.find(fType) > self.MAXIMIUM_TYPE_START_INDEX:
             fType = line[self.MAXIMIUM_TYPE_START_INDEX:]
             if fLocation:
                 fLocation = line[line.find(fLocation):self.
                                  MAXIMIUM_TYPE_START_INDEX]
             logger.warn("new Type is [%s], loc is [%s]" %
                         (fType, fLocation))
             self.__createFieldByType__(fieldNo, fType, fName, fLocation,
                                        line, Global, CrossReference)
     assert self._field, "Could not find the right type for %s, %s, %s, %s, %s" % (
         fType, fLocation, fieldNo, line, self._curFile.getFileNo())
Exemplo n.º 2
0
 def __createFieldByType__(self, fieldNo, fType, fName, fLocation, line, Global, CrossReference):
     logger.debug("Current Type is [%s]" % fType)
     result = self.UNDEFINED_POINTER.search(fType)
     if result:
         self._field = FileManFieldFactory.createField(fieldNo, fName,
                            FileManField.FIELD_TYPE_FILE_POINTER, fLocation)
         return
     result = self.POINTER_TO_REGEX.search(fType)
     if result:
         fileNo = result.group('File')
         filePointedTo = CrossReference.getGlobalByFileNo(fileNo)
         self._field = FileManFieldFactory.createField(fieldNo, fName,
                            FileManField.FIELD_TYPE_FILE_POINTER, fLocation)
         if not filePointedTo:
             logger.error("Could not find file pointed to [%s], [%s], line:[%s]" % (fileNo, self._curFile, line))
         else:
             self._field.setPointedToFile(filePointedTo)
         return
     # deal with file pointer to subFiles
     result = self.SUBFILE_REGEX.search(fType)
     if result:
         # create a field for sub file type
         self._field = FileManFieldFactory.createField(fieldNo, fName,
                             FileManField.FIELD_TYPE_SUBFILE_POINTER, fLocation)
         fileNo = result.group('File')
         logger.debug("Pointer to subFile %s" % fileNo)
         subFile = Global.getSubFileByFileNo(fileNo)
         if not subFile: # this is a new subfile
             subFile = FileManFile(fileNo, fName, self._curFile)
             self._curFile.addFileManSubFile(subFile)
             logger.debug("Added subFile %s to File %s" % (fileNo, self._curFile.getFileNo()))
             if self._isSubFile:
                 Global.addFileManSubFile(subFile)
         self._field.setPointedToSubFile(subFile)
         CrossReference.addFileManSubFile(subFile)
         return
     for (key, value) in self.StringTypeMappingDict.iteritems():
         if fType.startswith(key):
             self._field = FileManFieldFactory.createField(fieldNo, fName, value, fLocation)
             break
     if not self._field:
       # double check the loc and type
       if line.find(fType) > self.MAXIMIUM_TYPE_START_INDEX:
           fType = line[self.MAXIMIUM_TYPE_START_INDEX:]
           if fLocation:
               fLocation = line[line.find(fLocation):self.MAXIMIUM_TYPE_START_INDEX]
           logger.warn("new Type is [%s], loc is [%s]" % (fType, fLocation))
           self.__createFieldByType__(fieldNo, fType, fName, fLocation, line, Global, CrossReference)
     assert self._field, "Could not find the right type for %s, %s, %s, %s, %s" % (fType, fLocation, fieldNo, line, self._curFile.getFileNo())
Exemplo n.º 3
0
 def onSectionStart(self, line, section, Global, CrossReference):
     logger.debug("[%s]" % line)
     self._lines = []
     result = DataDictionaryListFileLogParser.FILEMAN_FIELD_START.search(
         line)
     assert result
     fileNo = result.group('FileNo')
     fieldNo = result.group("FieldNo")
     self._isSubFile = float(fileNo) != float(Global.getFileNo())
     if self._isSubFile:
         logger.debug("%s is a subfile" % fileNo)
         self._curFile = Global.getSubFileByFileNo(fileNo)
         assert self._curFile, "Could not find subFile [%s] in file [%s] line [%s]" % (
             fileNo, Global.getFileNo(), line)
     else:
         self._curFile = Global
     restOfLineStart = line.find("," + fieldNo) + len(fieldNo)
     startIdent = self.DEFAULT_NAME_INDENT
     #if len(fileNo) + 4 > startIdent:
     #    startIdent = self
     defaultIdentLevel = self.__getDefaultIndentLevel__(
         self._curFile, self.DEFAULT_NAME_INDENT)
     if restOfLineStart > defaultIdentLevel:
         logger.debug(
             "FileNo: %s, FieldNo: %s, line: %s, may not be a valid field no, %d, %d"
             % (fileNo, fieldNo, line, restOfLineStart, defaultIdentLevel))
         try:
             floatValue = float(fieldNo)
         except ValueError:
             logger.error("invalid fieldNo %s" % fieldNo)
             fieldNo = line[line.find(",") + 1:defaultIdentLevel]
             floatValue = float(fieldNo)
     restOfLine = line[line.find("," + fieldNo) + len(fieldNo) + 1:].strip()
     logger.debug("Parsing [%s]" % restOfLine)
     result = self.NAME_LOC_TYPE_REGEX.search(restOfLine)
     fName, fType, fLocation = None, None, None
     if result:
         logger.debug("FileNo: %s, Field#: %s, Name: %s, Loc %s, Type %s" %
                      (fileNo, fieldNo, result.group('Name').rstrip(),
                       result.group('Loc'), result.group('Type')))
         fName = result.group('Name').strip()
         fLocation = result.group('Loc').strip()
         if fLocation == ";":
             fLocation = None
         fType = result.group('Type').strip()
     else:
         # handle three cases, 1. no location info 2. no type info 3. Both
         if restOfLine.find(";") != -1:  # missing type info
             logger.warn("Missing Type information [%s]" % line)
             result = self.NAME_LOC_REGEX.search(restOfLine)
             if result:
                 logger.debug("Name: %s, Loc %s" %
                              (result.group('Name'), result.group('Loc')))
                 fName = result.group('Name').strip()
                 fLocation = result.group('Loc').strip()
             else:
                 logger.error("Could not parse [%s]" % restOfLine)
                 return
         else:  # missing location, assume at least two space seperate name and type
             logger.warn("Missing location information [%s]" % line)
             result = self.NAME_TYPE_REGEX.search(restOfLine)
             if result:
                 fName = result.group('Name').strip()
                 fType = result.group('Type').strip()
                 logger.debug("Name: %s, Type %s" %
                              (result.group('Name'), result.group('Type')))
             else:
                 logger.warn("Guessing Name: %s at line [%s]" %
                             (restOfLine.strip(), line))
     stripedType = ""
     if fType:
         stripedType = self.__stripFieldAttributes__(fType)
     if len(stripedType) > 0:
         self.__createFieldByType__(fieldNo, stripedType, fName, fLocation,
                                    line, Global, CrossReference)
     else:
         self._field = FileManFieldFactory.createField(
             fieldNo, fName, FileManField.FIELD_TYPE_NONE, fLocation)
     logger.debug("Add field %s to File %s" %
                  (fName, self._curFile.getFileNo()))
     self._curFile.addFileManField(self._field)
     if len(stripedType) > 0:
         self.__parseFieldAttributes__(fType)
Exemplo n.º 4
0
 def onSectionStart(self, line, section, Global, CrossReference):
     self._lines = []
     result = DataDictionaryListFileLogParser.FILEMAN_FIELD_START.search(line)
     assert result
     fileNo = result.group('FileNo')
     fieldNo = result.group("FieldNo")
     self._isSubFile = float(fileNo) != float(Global.getFileNo())
     if self._isSubFile:
         self._curFile = Global.getSubFileByFileNo(fileNo)
         assert self._curFile, "Could not find subFile [%s] in file [%s] line [%s]" % (fileNo, Global.getFileNo(), line)
     else:
         self._curFile = Global
     restOfLineStart = line.find("," + fieldNo) + len(fieldNo)
     startIdent = self.DEFAULT_NAME_INDENT
     defaultIdentLevel = self.__getDefaultIndentLevel__(self._curFile, self.DEFAULT_NAME_INDENT)
     if restOfLineStart > defaultIdentLevel:
         logger.warning("FileNo: %s, FieldNo: %s, line: %s, may not be a valid field no, %d, %d" %
                         (fileNo, fieldNo, line, restOfLineStart, defaultIdentLevel))
         try:
             floatValue = float(fieldNo)
         except ValueError:
             logger.error("invalid fieldNo %s" % fieldNo)
             fieldNo = line[line.find(",")+1:defaultIdentLevel]
             floatValue = float(fieldNo)
     restOfLine = line[line.find("," + fieldNo) + len(fieldNo)+1:].strip()
     result = NAME_LOC_TYPE_REGEX.search(restOfLine)
     fName, fType, fLocation = None, None, None
     if result:
         fName = result.group('Name').strip()
         fLocation = result.group('Loc').strip()
         if fLocation == ";":
             fLocation = None
         fType = result.group('Type').strip()
     else:
         # handle three cases, 1. no location info 2. no type info 3. Both
         if restOfLine.find(";") != -1: # missing type info
             logger.warn("Missing Type information [%s]" % line)
             result = NAME_LOC_REGEX.search(restOfLine)
             if result:
                 fName = result.group('Name').strip()
                 fLocation = result.group('Loc').strip()
             else:
                 logger.error("Could not parse [%s]" % restOfLine)
                 return
         else: # missing location, assume at least two space seperate name and type
             result = NAME_TYPE_REGEX.search(restOfLine)
             if result:
                 fName = result.group('Name').strip()
                 fType = result.group('Type').strip()
             else:
                 logger.warn("Guessing Name: %s at line [%s]" % (restOfLine.strip(), line))
     stripedType = ""
     if fType:
         stripedType = self.__stripFieldAttributes__(fType)
     if stripedType:
         self.__createFieldByType__(fieldNo, stripedType, fName, fLocation, line, Global, CrossReference)
     else:
         self._field = FileManFieldFactory.createField(fieldNo, fName, FileManField.FIELD_TYPE_NONE, fLocation)
     self._curFile.addFileManField(self._field)
     if stripedType:
         self.__parseFieldAttributes__(fType)