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())
def _setFieldSpecificData(self, zeroFields, fileField, rootNode, fileSchema, filePointedTo, subFile): if fileField.getType() == FileManField.FIELD_TYPE_FILE_POINTER: fileGlobalRoot = "" if len(zeroFields) >= 3: fileGlobalRoot = zeroFields[2] if filePointedTo: if filePointedTo not in self._allSchema: """ create a new fileman file """ self._allSchema[filePointedTo] = Global( fileGlobalRoot, filePointedTo, "") pointedToFile = self._allSchema[filePointedTo] assert pointedToFile.isRootFile() fileField.setPointedToFile(pointedToFile) globalName = pointedToFile.getName() fileNo = fileSchema.getFileNo() if fileSchema.isSubFile(): fileNo = fileSchema.getRootFile().getFileNo() self._addToFileDepDict(fileNo, pointedToFile.getFileNo()) if fileGlobalRoot: if not globalName: pointedToFile.setName(fileGlobalRoot) elif globalName != fileGlobalRoot: logging.error( "%s: FileMan global root mismatch %s: %s" % (zeroFields, globalName, fileGlobalRoot)) else: logging.info("@TODO, find file global root for # %s" % filePointedTo) elif fileGlobalRoot: self._noPointedToFiles[fileGlobalRoot] = Global(fileGlobalRoot) logging.info("@TODO, set the file number for %s" % fileGlobalRoot) else: logging.warn( "No pointed to file set for file:%s: field:%r 0-index:%s" % (fileSchema.getFileNo(), fileField, zeroFields)) elif fileField.getType() == FileManField.FIELD_TYPE_SUBFILE_POINTER: if subFile: if subFile not in self._allSchema: self._allSchema[subFile] = FileManFile( subFile, "", fileSchema) subFileSchema = self._allSchema[subFile] subFileSchema.setParentFile(fileSchema) fileSchema.addFileManSubFile(subFileSchema) fileField.setPointedToSubFile(subFileSchema) else: logging.warn( "No subfile is set for file:%s, field:%r 0-index:%s" % (fileSchema.getFileNo(), fileField, zeroFields)) elif fileField.getType( ) == FileManField.FIELD_TYPE_SET and not subFile: setDict = dict( [x.split(':') for x in zeroFields[2].rstrip(';').split(';')]) fileField.setSetMembers(setDict) elif fileField.getType( ) == FileManField.FIELD_TYPE_VARIABLE_FILE_POINTER: if "V" in rootNode: # parsing variable pointer vptrs = parsingVariablePointer(rootNode['V']) vpFileSchemas = [] if vptrs: logging.debug("variable points: %s" % vptrs) for x in vptrs: if x not in self._allSchema: self._allSchema[x] = Global("", x, "") pointedToFile = self._allSchema[x] if pointedToFile.isSubFile(): logging.error( "Field: %r point to subFile: %s, parent: %s" % (fileField, pointedToFile, pointedToFile.getParentFile())) else: fileNo = fileSchema.getFileNo() if fileSchema.isSubFile(): fileNo = fileSchema.getRootFile().getFileNo() self._addToFileDepDict(fileNo, pointedToFile.getFileNo()) vpFileSchemas.append(self._allSchema[x]) fileField.setPointedToFiles(vpFileSchemas) elif fileField.getType() == FileManField.FIELD_TYPE_COMPUTED: if len(zeroFields) >= 5: logging.debug("Computed Mumps Code: %s for %r" % ("".join(zeroFields[4:]), fileField))
def __handleFileManSubFiles__(self, fileManFile, subFilesJson): for subFileNo in subFilesJson: fileManFile.addFileManSubFile( FileManFile(subFileNo, "", fileManFile))