def _generateDataTableHtml(self, fileManData, fileNo): outDir = self.outDir isLargeFile = len(fileManData.dataEntries) > 4500 tName = normalizePackageName(fileManData.name) outDir = os.path.join(self.outDir, fileNo.replace(".","_")) if not os.path.exists(outDir): os.mkdir(outDir) with open("%s/%s.html" % (outDir, fileNo), 'w') as output: output.write("<html>\n") if isLargeFile: ajexSrc = "%s_array.txt" % fileNo outputLargeDataListTableHeader(output, ajexSrc, tName) else: outputDataListTableHeader(output, tName) output.write("<body id=\"dt_example\">") output.write("""<div id="container" style="width:80%">""") output.write("<h1>File %s(%s) Data List</h1>" % (tName, fileNo)) writeTableListInfo(output, tName) if not isLargeFile: output.write("<tbody>\n") for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] if not dataEntry.name: logging.warn("no name for %s" % dataEntry) continue name = dataEntry.name if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(dataEntry.name) dataHtmlLink = "<a href=\"../%s/%s\">%s</a>" % (fileNo.replace(".","_"),getDataEntryHtmlFile(dataEntry, ien, fileNo), name) tableRow = [dataHtmlLink, dataEntry.ien] output.write("<tr>\n") """ table body """ for item in tableRow: output.write("<td>%s</td>\n" % item) output.write("</tr>\n") output.write("</tbody>\n") output.write("</table>\n") output.write("</div>\n") output.write("</div>\n") output.write ("</body></html>\n") if isLargeFile: logging.info("Ajex source file: %s" % ajexSrc) """ Write out the data file in JSON format """ outJson = {"aaData": []} with open(os.path.join(outDir, ajexSrc), 'w') as output: outArray = outJson["aaData"] for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] if not dataEntry.name: logging.warn("no name for %s" % dataEntry) continue name = dataEntry.name if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(dataEntry.name) dataHtmlLink = "<a href=\"../%s/%s\">%s</a>" % (fileNo.replace(".","_"),getDataEntryHtmlFile(dataEntry, ien, fileNo), name) outArray.append([dataHtmlLink, ien]) json.dump(outJson, output)
def _generateDataTableHtml(self, fileManData, fileNo): outDir = self.outDir isLargeFile = len(fileManData.dataEntries) > 4500 tName = normalizePackageName(fileManData.name) with open("%s/%s.html" % (outDir, fileNo), "w") as output: output.write("<html>\n") if isLargeFile: ajexSrc = "%s_array.txt" % fileNo outputLargeDataListTableHeader(output, ajexSrc, tName) else: outputDataListTableHeader(output, tName) output.write('<body id="dt_example">') output.write("""<div id="container" style="width:80%">""") output.write("<h1>File %s(%s) Data List</h1>" % (tName, fileNo)) writeTableListInfo(output, tName) if not isLargeFile: output.write("<tbody>\n") for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] if not dataEntry.name: logging.warn("no name for %s" % dataEntry) continue name = dataEntry.name if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(dataEntry.name) dataHtmlLink = '<a href="%s">%s</a>' % (getDataEntryHtmlFile(dataEntry, ien, fileNo), name) tableRow = [dataHtmlLink, dataEntry.ien] output.write("<tr>\n") """ table body """ for item in tableRow: output.write("<td>%s</td>\n" % item) output.write("</tr>\n") output.write("</tbody>\n") output.write("</table>\n") output.write("</div>\n") output.write("</div>\n") output.write("</body></html>\n") if isLargeFile: logging.info("Ajex source file: %s" % ajexSrc) """ Write out the data file in JSON format """ outJson = {"aaData": []} with open(os.path.join(outDir, ajexSrc), "w") as output: outArray = outJson["aaData"] for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] if not dataEntry.name: logging.warn("no name for %s" % dataEntry) continue name = dataEntry.name if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(dataEntry.name) dataHtmlLink = '<a href="%s">%s</a>' % (getDataEntryHtmlFile(dataEntry, ien, fileNo), name) outArray.append([dataHtmlLink, ien]) json.dump(outJson, output)
def _generateSchema(self): files = getKeys(self._ddRoot, float) # sort files by float value logging.debug("Parsing files %s" % files) for file in files: if file not in self._allSchema: self._allSchema[file] = Global("", file, "") self._generateFileSchema(self._ddRoot[file], self._allSchema[file])
def _parseDataBySchema(self, dataRoot, fileSchema, outGlbData): """ first sort the schema Root by location """ locFieldDict = sortSchemaByLocation(fileSchema) """ for each data entry, parse data by location """ floatKey = getKeys(dataRoot, float) for ien in floatKey: if float(ien) <=0: continue #if level == 0 and int(ien) != 160: continue dataEntry = dataRoot[ien] outDataEntry = FileManDataEntry(fileSchema.getFileNo(), ien) dataKeys = [x for x in dataEntry] sortedKey = sorted(dataKeys, cmp=sortDataEntryFloatFirst) for locKey in sortedKey: if locKey == '0' and fileSchema.getFileNo() == '1': self._parseFileDetail(dataEntry[locKey], ien) if locKey in locFieldDict: fieldDict = locFieldDict[locKey] # a dict of {pos: field} curDataRoot = dataEntry[locKey] if len(fieldDict) == 1: fieldAttr = fieldDict.values()[0] if fieldAttr.isSubFilePointerType(): # Multiple self._parseSubFileField(curDataRoot, fieldAttr, outDataEntry) else: self._parseSingleDataValueField(curDataRoot, fieldAttr, outDataEntry) else: self._parseDataValueField(curDataRoot, fieldDict, outDataEntry) outGlbData.addFileManDataEntry(ien, outDataEntry) if fileSchema.getFileNo() == self._curFileNo: self._addFileKeyIndex(self._curFileNo, ien, outDataEntry.name)
def printFileManFileData(fileManData, level=0): curIndent = "\t"*(level+1) if level == 0: print "File#: %s, Name: %s" % (fileManData.fileNo, fileManData.name) for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] printFileManDataEntry(dataEntry, ien, level)
def _parseSubFilesNode(self, rootNode, fileNo): """ Get the subFiles used in the file """ for key in getKeys(rootNode['SB'], float): assert key in self._allSchema assert self._allSchema[key].isSubFile() assert self._allSchema[key].getParentFile().getFileNo() == fileNo self._subFiles.add(key)
def _convertFileManDataToHtml(self, fileManData): for ien in getKeys(fileManData.dataEntries.keys(), float): outDir = self.outDir tName = "%s-%s" % (fileManData.fileNo.replace(".","_"), ien) dataEntry = fileManData.dataEntries[ien] if not dataEntry.name: logging.warn("no name for %s" % dataEntry) continue name = dataEntry.name if dataEntry.fileNo: outDir = os.path.join(self.outDir, dataEntry.fileNo.replace(".","_")) if not os.path.exists(outDir): os.mkdir(outDir) if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(dataEntry.name) outHtmlFileName = getDataEntryHtmlFile(ien, fileManData.fileNo) with open("%s/%s" % (outDir, outHtmlFileName), 'w') as output: output.write ("<html>") outputDataRecordTableHeader(output, tName) output.write("<body id=\"dt_example\">") output.write("""<div id="container" style="width:80%">""") output.write ("<h1>%s (%s) %s (%s)</h1>\n" % (name, ien, fileManData.name, fileManData.fileNo)) outputFileEntryTableList(output, tName) """ table body """ output.write("<tbody>\n") self._fileManDataEntryToHtml(output, dataEntry, True) output.write("</tbody>\n") output.write("</table>\n") output.write("</div>\n") output.write("</div>\n") output.write ("</body></html>")
def printFileManFileData(fileManData, level=0): curIndent = "\t" * (level + 1) if level == 0: print "File#: %s, Name: %s" % (fileManData.fileNo, fileManData.name) for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] printFileManDataEntry(dataEntry, ien, level)
def _getKeyNameBySchema(self, dataRoot, keyLoc, keyField): floatKey = getKeys(dataRoot, float) logging.debug('Total # of entry is %s' % len(floatKey)) for ien in floatKey: if float(ien) <= 0: continue dataEntry = dataRoot[ien] index, loc = keyLoc.split(';') if not index or index not in dataEntry: continue dataEntry = dataEntry[index] if not dataEntry.value: return (ien, None) values = dataEntry.value.split('^') dataValue = None if convertToType(loc, int): intLoc = int(loc) if intLoc > 0 and intLoc <= len(values): dataValue = values[intLoc - 1] else: dataValue = str(dataEntry.value) if dataValue: return (ien, self._parseIndividualFieldDetail( dataValue, keyField, None)) return (None, None)
def _convertFileManDataToHtml(self, fileManData): for ien in getKeys(fileManData.dataEntries.keys(), float): outDir = self.outDir tName = safeElementId("%s-%s" % (fileManData.fileNo, ien)) dataEntry = fileManData.dataEntries[ien] if not dataEntry.name: logging.warn("no name for %s" % dataEntry) continue name = dataEntry.name if dataEntry.fileNo: outDir = os.path.join(self.outDir, dataEntry.fileNo.replace(".", "_")) if not os.path.exists(outDir): os.mkdir(outDir) if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(dataEntry.name) outHtmlFileName = getDataEntryHtmlFile(dataEntry, ien, fileManData.fileNo) with open("%s/%s" % (outDir, outHtmlFileName), 'w') as output: output.write("<html>") outputDataRecordTableHeader(output, tName) output.write("<body id=\"dt_example\">") output.write("""<div id="container" style="width:80%">""") output.write("<h1>%s (%s) %s (%s)</h1>\n" % (name, ien, fileManData.name, fileManData.fileNo)) outputFileEntryTableList(output, tName) """ table body """ output.write("<tbody>\n") self._fileManDataEntryToHtml(output, dataEntry, True) output.write("</tbody>\n") output.write("</table>\n") output.write("</div>\n") output.write("</div>\n") output.write("</body></html>")
def _parseDataBySchema(self, dataRoot, fileSchema, outGlbData): """ first sort the schema Root by location """ locFieldDict = sortSchemaByLocation(fileSchema) """ for each data entry, parse data by location """ floatKey = getKeys(dataRoot, float) for ien in floatKey: if float(ien) <= 0: continue #if level == 0 and int(ien) != 160: continue dataEntry = dataRoot[ien] outDataEntry = FileManDataEntry(fileSchema.getFileNo(), ien) dataKeys = [x for x in dataEntry] sortedKey = sorted(dataKeys, cmp=sortDataEntryFloatFirst) for locKey in sortedKey: if locKey == '0' and fileSchema.getFileNo() == '1': self._parseFileDetail(dataEntry[locKey], ien) if locKey in locFieldDict: fieldDict = locFieldDict[locKey] # a dict of {pos: field} curDataRoot = dataEntry[locKey] if len(fieldDict) == 1: fieldAttr = fieldDict.values()[0] if fieldAttr.isSubFilePointerType(): # Multiple self._parseSubFileField(curDataRoot, fieldAttr, outDataEntry) else: self._parseSingleDataValueField( curDataRoot, fieldAttr, outDataEntry) else: self._parseDataValueField(curDataRoot, fieldDict, outDataEntry) outGlbData.addFileManDataEntry(ien, outDataEntry) if fileSchema.getFileNo() == self._curFileNo: self._addFileKeyIndex(self._curFileNo, ien, outDataEntry.name)
def _convertFileManDataToHtml(self, fileManData): outDir = self.outDir for ien in getKeys(fileManData.dataEntries.keys(), float): tName = safeElementId("%s-%s" % (fileManData.fileNo, ien)) dataEntry = fileManData.dataEntries[ien] if not dataEntry.name: logging.warn("no name for %s" % dataEntry) continue name = dataEntry.name if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(dataEntry.name) outHtmlFileName = getDataEntryHtmlFile(dataEntry, ien, fileManData.fileNo) with open("%s/%s" % (outDir, outHtmlFileName), "w") as output: output.write("<html>") outputDataRecordTableHeader(output, tName) output.write('<body id="dt_example">') output.write("""<div id="container" style="width:80%">""") output.write( "<h1>%s (%s) %s (%s)</h1>\n" % (name, ien, fileManData.name, fileManData.fileNo) ) outputFileEntryTableList(output, tName) """ table body """ output.write("<tbody>\n") self._fileManDataEntryToHtml(output, dataEntry, True) output.write("</tbody>\n") output.write("</table>\n") output.write("</div>\n") output.write("</div>\n") output.write("</body></html>")
def _parseSubFilesNode(self, rootNode, fileNo): """ Get the subFiles used in the file """ for key in getKeys(rootNode["SB"], float): logging.debug("Checking subfiles: %s" % key) assert key in self._allSchema assert self._allSchema[key].isSubFile() assert self._allSchema[key].getParentFile().getFileNo() == fileNo self._subFiles.add(key)
def parsingVariablePointer(vpRoot): intKey = getKeys(vpRoot) outVptr = [] for key in intKey: if '0' in vpRoot[key]: value = vpRoot[key]['0'].value if value: value = value.split('^')[0] outVptr.append(value) return outVptr
def parseSchemaDDFileV2(self, inputDDZWRFile): for ddRoot in readGlobalNodeFromZWRFileV2(inputDDZWRFile, '^DD'): files = getKeys(ddRoot, float) # sort files by float value for file in files: if file not in self._allSchema: self._allSchema[file] = Global("", file, "") self._generateFileSchema(ddRoot[file], self._allSchema[file]) self._updateMultiple() self._sccSet = self._generateSCCSet() return self._allSchema
def _generateFileSchema(self, rootNode, fileSchema): """ handle the "PT" and "SB" subscript first """ for key in getKeys(rootNode, float): if key == '0': continue # ignore the fields 0 field = self._parseSchemaField(key, rootNode[key], fileSchema) if field: fileSchema.addFileManField(field) if 'SB' in rootNode: self._parseSubFilesNode(rootNode, fileSchema.getFileNo())
def _getTableRows(self, fileManData, fileNo): rows = [] for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] if not dataEntry.name: logger.warn("No name for %s" % dataEntry) continue name = dataEntry.name if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(name) dataHtmlLink = "<a href=\"../%s/%s\">%s</a>" % (fileNo.replace( ".", "_"), getDataEntryHtmlFile( ien, fileNo), str(name).replace("\xa0", "")) rows.append([dataHtmlLink, ien]) return rows
def _getTableRows(self, fileManData, fileNo, fieldsList): rows = [] for ien in getKeys(fileManData.dataEntries.keys(), float): row = [""] * len(fieldsList) row[0] = ien dataEntry = fileManData.dataEntries[ien] name = dataEntry.name if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(name) dataHtmlLink = "<a href=\"%s/%s/%s\">%s</a>" % (VIV_URL, fileNo.replace(".","_"), getDataEntryHtmlFileName(ien, fileNo), str(name).replace("\xa0", "")) for field in dataEntry.fields: # Use index of field name to place data correctly in row row[fieldsList.index(dataEntry.fields[field].name)] = dataEntry.fields[field].value if field == '.01': row[fieldsList.index(dataEntry.fields[field].name)] = dataHtmlLink rows.append(row) return rows
def parseZWRGlobalDataBySchema(self, dataRoot, allSchemaDict, fileNumber, subscript): self._allSchemaDict = allSchemaDict schemaFile = allSchemaDict[fileNumber] fileDataRoot = dataRoot if subscript: if subscript in dataRoot: logging.info("using subscript %s" % subscript) fileDataRoot = dataRoot[subscript] self._glbData[fileNumber] = FileManFileData(fileNumber, self.getFileManFileNameByFileNo(fileNumber)) self._parseDataBySchema(fileDataRoot, schemaFile, self._glbData[fileNumber]) else: # assume this is for all files in the entry for fileNo in getKeys(self._dataRoot, float): fileDataRoot = self._dataRoot[fileNo] self._glbData[fileNo] = FileManFileData(fileNo, schemaFile.getFileManName()) self._parseDataBySchema(fileDataRoot, schemaFile, self._glbData[fileNo]) self._resolveSelfPointer() if self._crossRef: self._updateCrossReference()
def _convertFileManDataToHtml(self, fileManData): fileManDataFileNo = fileManData.fileNo pathSafeFileManDataFileNo = fileManDataFileNo.replace(".", "_") for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] name = dataEntry.name if not name: logger.warn("no name for %s" % dataEntry) continue outDir = self.outDir fileNo = dataEntry.fileNo if fileNo: outDir = os.path.join(self.outDir, fileNo.replace(".", "_")) tName = "%s-%s" % (pathSafeFileManDataFileNo, ien) if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(name) outHtmlFileName = getDataEntryHtmlFile(ien, fileManDataFileNo) with open(os.path.join(outDir, outHtmlFileName), 'w') as output: output.write("<html>") outputDataRecordTableHeader(output, tName) output.write("<body id=\"dt_example\">") output.write("""<div id="container" style="width:80%">""") output.write("<h1>%s (%s) %s (%s)</h1>\n" % (name, ien, fileManData.name, fileManDataFileNo)) if fileNo in ['19', '101']: # Todo: Check if the object exists in options/menus first. output.write( "<a style='font-size: 15px;' href='%s../vista_menus.php#%s?name=%s'>View in ViViaN Menu</a>" % (VIV_URL, fileNo, urllib.quote_plus(name))) outputFileEntryTableList(output, tName) """ table body """ output.write("<tbody>\n") self._fileManDataEntryToHtml(output, dataEntry, True) output.write("</tbody>\n") output.write("</table>\n") output.write("</div>\n") output.write("</div>\n") output.write("</body></html>")
def _convertFileManDataToHtml(self, fileManData): fileManDataFileNo = fileManData.fileNo pathSafeFileManDataFileNo = fileManDataFileNo.replace(".", "_") for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] name = dataEntry.name if not name: logger.warn("no name for %s" % dataEntry) continue outDir = self.outDir fileNo = dataEntry.fileNo if fileNo: outDir = os.path.join(self.outDir, fileNo.replace(".","_")) tName = "%s-%s" % (pathSafeFileManDataFileNo, ien) if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(name) outHtmlFileName = getDataEntryHtmlFileName(ien, fileManDataFileNo) with open(os.path.join(outDir, outHtmlFileName), 'w') as output: output.write ("<html>") outputDataRecordTableHeader(output, tName) output.write("<body id=\"dt_example\">") output.write("""<div id="container" style="width:80%">""") output.write ("<h1>%s (%s) %s (%s)</h1>\n" % (name, ien, fileManData.name, fileManDataFileNo)) if fileNo in ['19','101']: # Todo: Check if the object exists in options/menus first. output.write("<a style='font-size: 15px;' href='%s../vista_menus.php#%s?name=%s'>View in ViViaN Menu</a>" % (VIV_URL, fileNo, urllib.quote_plus(name))) outputFileEntryTableList(output, tName) """ table body """ output.write("<tbody>\n") self._fileManDataEntryToHtml(output, dataEntry, True) output.write("</tbody>\n") output.write("</table>\n") output.write("</div>\n") output.write("</div>\n") output.write ("</body></html>")
def _getTableRows(self, fileManData, fileNo, fieldsList): rows = [] for ien in getKeys(fileManData.dataEntries.keys(), float): row = [""] * len(fieldsList) row[0] = ien dataEntry = fileManData.dataEntries[ien] name = dataEntry.name if isFilePointerType(dataEntry): link, name = convertFilePointerToHtml(name) dataHtmlLink = "<a href=\"%s/%s/%s\">%s</a>" % ( VIV_URL, fileNo.replace( ".", "_"), getDataEntryHtmlFileName( ien, fileNo), str(name).replace("\xa0", "")) for field in dataEntry.fields: # Use index of field name to place data correctly in row row[fieldsList.index(dataEntry.fields[field].name )] = dataEntry.fields[field].value if field == '.01': row[fieldsList.index( dataEntry.fields[field].name)] = dataHtmlLink rows.append(row) return rows
def parseZWRGlobalDataBySchema(self, dataRoot, allSchemaDict, fileNumber, subscript): self._allSchemaDict = allSchemaDict schemaFile = allSchemaDict[fileNumber] fileDataRoot = dataRoot if subscript: if subscript in dataRoot: logging.info("using subscript %s" % subscript) fileDataRoot = dataRoot[subscript] self._glbData[fileNumber] = FileManFileData( fileNumber, self.getFileManFileNameByFileNo(fileNumber)) self._parseDataBySchema(fileDataRoot, schemaFile, self._glbData[fileNumber]) else: # assume this is for all files in the entry for fileNo in getKeys(self._dataRoot, float): fileDataRoot = self._dataRoot[fileNo] self._glbData[fileNo] = FileManFileData( fileNo, schemaFile.getFileManName()) self._parseDataBySchema(fileDataRoot, schemaFile, self._glbData[fileNo]) self._resolveSelfPointer() if self._crossRef: self._updateCrossReference()
def _getKeyNameBySchema(self, dataRoot, keyLoc, keyField): floatKey = getKeys(dataRoot, float) for ien in floatKey: if float(ien) <=0: continue dataEntry = dataRoot[ien] index, loc = keyLoc.split(';') if not index or index not in dataEntry: continue dataEntry = dataEntry[index] if not dataEntry.value: return (ien, None) values = dataEntry.value.split('^') dataValue = None if convertToType(loc, int): intLoc = int(loc) if intLoc > 0 and intLoc <= len(values): dataValue = values[intLoc-1] else: dataValue = str(dataEntry.value) if dataValue: return (ien, self._parseIndividualFieldDetail(dataValue, keyField, None)) return (None, None)
def testGlobalParser(crosRef=None): parser = createArgParser() result = parser.parse_args() print result from InitCrossReferenceGenerator import parseCrossRefGeneratorWithArgs from FileManDataToHtml import FileManDataToHtml outputFile = open(os.path.join(result.outdir, "filesInfo.json"), 'wb') __generateGitRepositoryKey__(result.gitPath, result.MRepositDir, outputFile) crossRef = parseCrossRefGeneratorWithArgs(result) glbDataParser = FileManGlobalDataParser(crossRef) #glbDataParser.parseAllZWRGlobaFilesBySchema(result.MRepositDir, allSchemaDict) allFiles = glbDataParser.getAllFileManZWRFiles(os.path.join(result.MRepositDir, 'Packages'), "*/Globals/*.zwr") assert '0' in allFiles and '1' in allFiles and set(result.fileNos).issubset(allFiles) schemaParser = FileManSchemaParser() allSchemaDict = schemaParser.parseSchemaDDFileV2(allFiles['0']['path']) isolatedFiles = schemaParser.isolatedFiles glbDataParser.parseZWRGlobalFileBySchemaV2(allFiles['1']['path'], allSchemaDict, '1', '^DIC(') glbDataParser._allFiles = allFiles glbDataParser._allSchemaDict = allSchemaDict for fileNo in result.fileNos: assert fileNo in glbDataParser.globalLocationMap if result.outdir: glbDataParser.outDir = result.outdir if result.patchRepositDir: glbDataParser.patchDir = result.patchRepositDir htmlGen = FileManDataToHtml(crossRef, result.outdir) if not result.all or set(result.fileNos).issubset(isolatedFiles): for fileNo in result.fileNos: gdFile = allFiles[fileNo]['path'] logging.info("Parsing file: %s at %s" % (fileNo, gdFile)) glbDataParser.parseZWRGlobalFileBySchemaV2(gdFile, allSchemaDict, fileNo) if result.outdir: htmlGen.outputFileManDataAsHtml(glbDataParser) else: fileManDataMap = glbDataParser.outFileManData for file in getKeys(fileManDataMap.iterkeys(), float): printFileManFileData(fileManDataMap[file]) del glbDataParser.outFileManData[fileNo] glbDataParser.outRtnReferenceDict() return """ Also generate all required files as well """ sccSet = schemaParser.sccSet fileSet = set(result.fileNos) for idx, value in enumerate(sccSet): fileSet.difference_update(value) if not fileSet: break for i in xrange(0,idx+1): fileSet = sccSet[i] fileSet &= set(allFiles.keys()) fileSet -= isolatedFiles fileSet.discard('757') if len(fileSet) > 1: for file in fileSet: zwrFile = allFiles[file]['path'] globalSub = allFiles[file]['name'] logging.info("Generate file key index for: %s at %s" % (file, zwrFile)) glbDataParser.generateFileIndex(zwrFile, allSchemaDict, file) for file in fileSet: zwrFile = allFiles[file]['path'] globalSub = allFiles[file]['name'] logging.info("Parsing file: %s at %s" % (file, zwrFile)) glbDataParser.parseZWRGlobalFileBySchemaV2(zwrFile, allSchemaDict, file) if result.outdir: htmlGen.outputFileManDataAsHtml(glbDataParser) del glbDataParser.outFileManData[file]
def _parsingWordProcessingNode(self, dataRoot): outLst = [] for key in getKeys(dataRoot, int): if '0' in dataRoot[key]: outLst.append("%s" % dataRoot[key]['0'].value) return outLst
def outputFileManDataAsHtml(self, gblDataParser): """ This is the entry pointer to generate Html output format based on FileMan Data object @TODO: integrate with FileManFileOutputFormat.py """ outDir = self.outDir crossRef = self.crossRef fileManDataMap = gblDataParser.outFileManData self.dataMap = gblDataParser for fileNo in getKeys(fileManDataMap.iterkeys(), float): fileManData = fileManDataMap[fileNo] if fileNo == "8994": if crossRef: allPackages = crossRef.getAllPackages() allRpcs = [] for package in allPackages.itervalues(): if package.rpcs: logging.info("generating RPC list for package: %s" % package.getName()) self._generateRPCListHtml(package.rpcs, package.getName()) allRpcs.extend(package.rpcs) if allRpcs: self._generateRPCListHtml(allRpcs, "All") elif fileNo == "101": if crossRef: allPackages = crossRef.getAllPackages() allHl7s = [] allProtocols = [] for package in allPackages.itervalues(): if package.hl7: logging.info("generating HL7 list for package: %s" % package.getName()) self._generateHL7ListByPackage(package.hl7, package.getName()) allHl7s.extend(package.hl7) if package.protocol: logging.info("generating Protocol list for package: %s" % package.getName()) self._generateProtocolListByPackage(package.protocol, package.getName()) allProtocols.extend(package.protocol) if allHl7s: self._generateHL7ListByPackage(allHl7s, "All") if allProtocols: self._generateProtocolListByPackage(allProtocols, "All") elif fileNo == "779.2": if crossRef: allPackages = crossRef.getAllPackages() allHLOs = [] for package in allPackages.itervalues(): if package.hlo: logging.info("generating HLO list for package: %s" % package.getName()) self._generateHLOListByPackage(package.hlo, package.getName(), gblDataParser) allHLOs.extend(package.hlo) if allHLOs: self._generateHLOListByPackage(allHLOs, "All", gblDataParser) elif fileNo == "19": """ generate all option list """ allOptionList = [] allMenuList = [] serverMenuList = [] for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] allOptionList.append(dataEntry) if "4" in dataEntry.fields: if dataEntry.fields["4"].value == "menu": allMenuList.append(dataEntry) # Separate list for the "server" OPTIONS elif dataEntry.fields["4"].value == "server": serverMenuList.append(dataEntry) else: logging.error("ien: %s of file 19 does not have a type" % ien) self._generateDataListByPackage( allOptionList, "All", option_list_fields, "Option", [x[0] for x in option_list_fields], ["Name", "Lock"], ) self._generateDataListByPackage( allMenuList, "All", menu_list_fields, "Menu", [x[0] for x in menu_list_fields], ["Name", "Menu Text", "Lock"], ) self._generateServerMenu(allMenuList, allOptionList, serverMenuList) self._generateMenuDependency(allMenuList, allOptionList) self._generateDataTableHtml(fileManData, fileNo) self._convertFileManDataToHtml(fileManData)
def parsingDelTest(globalRoot): intKey = getKeys(globalRoot) for key in intKey: if '0' in globalRoot[key]: print "\t%s,0)= %s" % (key, globalRoot[key]['0'].value)
def outputFileManDataAsHtml(self, gblDataParser): """ This is the entry pointer to generate Html output format based on FileMan Data object @TODO: integrate with FileManFileOutputFormat.py """ outDir = self.outDir crossRef = self.crossRef fileManDataMap = gblDataParser.outFileManData self.dataMap = gblDataParser for fileNo in getKeys(fileManDataMap.iterkeys(), float): fileManData = fileManDataMap[fileNo] if fileNo == '8994': if crossRef: allPackages = crossRef.getAllPackages() allRpcs = [] for package in allPackages.itervalues(): if package.rpcs: logging.info( "generating RPC list for package: %s" % package.getName()) self._generateRPCListHtml(package.rpcs, package.getName()) allRpcs.extend(package.rpcs) if allRpcs: self._generateRPCListHtml(allRpcs, "All") elif fileNo == '101': if crossRef: allPackages = crossRef.getAllPackages() allHl7s = [] allProtocols = [] for package in allPackages.itervalues(): if package.hl7: logging.info( "generating HL7 list for package: %s" % package.getName()) self._generateHL7ListByPackage( package.hl7, package.getName()) allHl7s.extend(package.hl7) if package.protocol: logging.info( "generating Protocol list for package: %s" % package.getName()) self._generateProtocolListByPackage( package.protocol, package.getName()) allProtocols.extend(package.protocol) if allHl7s: self._generateHL7ListByPackage(allHl7s, "All") if allProtocols: self._generateProtocolListByPackage( allProtocols, "All") elif fileNo == '779.2': if crossRef: allPackages = crossRef.getAllPackages() allHLOs = [] for package in allPackages.itervalues(): if package.hlo: logging.info( "generating HLO list for package: %s" % package.getName()) self._generateHLOListByPackage( package.hlo, package.getName(), gblDataParser) allHLOs.extend(package.hlo) if allHLOs: self._generateHLOListByPackage(allHLOs, "All", gblDataParser) elif fileNo == '19': """ generate all option list """ allOptionList = [] allMenuList = [] serverMenuList = [] for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] allOptionList.append(dataEntry) if '4' in dataEntry.fields: if dataEntry.fields['4'].value == 'menu': allMenuList.append(dataEntry) # Separate list for the "server" OPTIONS elif (dataEntry.fields['4'].value == 'server'): serverMenuList.append(dataEntry) else: logging.error( "ien: %s of file 19 does not have a type" % ien) self._generateDataListByPackage( allOptionList, "All", option_list_fields, "Option", [x[0] for x in option_list_fields], ["Name", "Lock"]) self._generateDataListByPackage( allMenuList, "All", menu_list_fields, "Menu", [x[0] for x in menu_list_fields], ["Name", "Menu Text", "Lock"]) self._generateServerMenu(allMenuList, allOptionList, serverMenuList) self._generateMenuDependency(allMenuList, allOptionList) self._generateDataTableHtml(fileManData, fileNo) self._convertFileManDataToHtml(fileManData)
def printAllSchemas(allSchemaDict): files = getKeys(allSchemaDict.keys(), float) for file in files: allSchemaDict[file].printFileManInfo()
def _generateSchema(self): files = getKeys(self._ddRoot, float) # sort files by float value for file in files: if file not in self._allSchema: self._allSchema[file] = Global("", file, "") self._generateFileSchema(self._ddRoot[file], self._allSchema[file])
def outputFileManDataAsHtml(self, fileNo, gblDataParser): """ This is the entry pointer to generate Html output format based on FileMan Data object @TODO: integrate with FileManFileOutputFormat.py """ crossRef = self.crossRef fileManDataMap = gblDataParser.outFileManData self.dataMap = gblDataParser fileManData = fileManDataMap[fileNo] fileNoPathSafe = fileNo.replace('.', '_') fileNoOutDir = os.path.join(self.outDir, fileNoPathSafe) if not os.path.exists(fileNoOutDir): os.mkdir(fileNoOutDir) if fileNo == '8994': if crossRef: allPackages = crossRef.getAllPackages() allRpcs = [] for package in allPackages.itervalues(): if package.rpcs: self._generateRPCListHtml(package.rpcs, package.getName(), fileNoOutDir) allRpcs.extend(package.rpcs) if allRpcs: self._generateRPCListHtml(allRpcs, "All", fileNoOutDir) elif fileNo == '101': menuOutDir = os.path.join(self.outDir, "menus", "101") if not os.path.exists(menuOutDir): os.makedirs(menuOutDir) allProtoMenuList = [] if crossRef: allPackages = crossRef.getAllPackages() allHl7s = [] allProtocols = [] for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] allProtocols.append(dataEntry) fields = dataEntry.fields if '4' in fields: if fields['4'].value == 'menu': allProtoMenuList.append(dataEntry) for package in allPackages.itervalues(): if package.hl7: self._generateHL7ListByPackage(package.hl7, package.getName(), fileNoOutDir) allHl7s.extend(package.hl7) if package.protocol: self._generateProtocolListByPackage( package.protocol, package.getName(), fileNoOutDir) if allHl7s: self._generateHL7ListByPackage(allHl7s, "All", fileNoOutDir) if allProtocols: self._generateProtocolListByPackage( allProtocols, "All", fileNoOutDir) self._generateMenuDependency(allProtoMenuList, allProtocols, menuOutDir) elif fileNo == '779.2': if crossRef: allPackages = crossRef.getAllPackages() allHLOs = [] for package in allPackages.itervalues(): if package.hlo: self._generateHLOListByPackage(package.hlo, package.getName(), gblDataParser, fileNoOutDir) allHLOs.extend(package.hlo) if allHLOs: self._generateHLOListByPackage(allHLOs, "All", gblDataParser, fileNoOutDir) elif fileNo == '19': allOptionList = [] allMenuList = [] serverMenuList = [] outJSON = {} menuOutDir = os.path.join(self.outDir, "menus", "19") if not os.path.exists(menuOutDir): os.makedirs(menuOutDir) for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] allOptionList.append(dataEntry) fields = dataEntry.fields if '4' in fields: if fields['4'].value == 'menu': allMenuList.append(dataEntry) # Seperate list for the "server" OPTIONS elif fields['4'].value == 'server': serverMenuList.append(dataEntry) else: logger.error("ien: %s of file 19 does not have a type" % ien) self._generateDataListByPackage(allOptionList, "All", option_list_fields, "Option", [x[0] for x in option_list_fields], ["Name", "Lock"], fileNoOutDir) self._generateDataListByPackage(allMenuList, "All", menu_list_fields, "menus", [x[0] for x in menu_list_fields], ["Name", "Menu Text", "Lock"], fileNoOutDir) self._generateServerMenu(allMenuList, allOptionList, serverMenuList) self._generateMenuDependency(allMenuList, allOptionList, menuOutDir) allObjectsList = [] outJSON = {} for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] outJSON[ien] = dataEntry.fields allObjectsList.append(dataEntry) with open(os.path.join(self.outDir, "dox", "%s.json" % fileNoPathSafe), 'w') as output: json.dump(outJSON, output, ensure_ascii=False, cls=OSEHRAEncoder) self._generateDataTableHtml(fileManData, fileNo, fileNoOutDir) self._convertFileManDataToHtml(fileManData)
def outputFileManDataAsHtml(self, gblDataParser): """ This is the entry pointer to generate Html output format based on FileMan Data object @TODO: integrate with FileManFileOutputFormat.py """ outDir = self.outDir crossRef = self.crossRef fileManDataMap = gblDataParser.outFileManData self.dataMap = gblDataParser for fileNo in getKeys(fileManDataMap.iterkeys(), float): fileManData = fileManDataMap[fileNo] if fileNo == '8994': if not os.path.exists(outDir + "/8994"): os.mkdir(outDir + "/8994") if crossRef: allPackages = crossRef.getAllPackages() allRpcs = [] for package in allPackages.itervalues(): if package.rpcs: logging.info( "generating RPC list for package: %s" % package.getName()) self._generateRPCListHtml(package.rpcs, package.getName(), fileNo) allRpcs.extend(package.rpcs) if allRpcs: self._generateRPCListHtml(allRpcs, "All", fileNo) elif fileNo == '101': if not os.path.exists(outDir + "/101"): os.mkdir(outDir + "/101") if crossRef: allPackages = crossRef.getAllPackages() allHl7s = [] allProtocols = [] for package in allPackages.itervalues(): if package.hl7: logging.info( "generating HL7 list for package: %s" % package.getName()) self._generateHL7ListByPackage( package.hl7, package.getName(), fileNo) allHl7s.extend(package.hl7) if package.protocol: logging.info( "generating Protocol list for package: %s" % package.getName()) self._generateProtocolListByPackage( package.protocol, package.getName(), fileNo) allProtocols.extend(package.protocol) if allHl7s: self._generateHL7ListByPackage(allHl7s, "All", fileNo) if allProtocols: self._generateProtocolListByPackage( allProtocols, "All", fileNo) elif fileNo == '779.2': if not os.path.exists(outDir + "/779_2"): os.mkdir(outDir + "/779_2") if crossRef: allPackages = crossRef.getAllPackages() allHLOs = [] for package in allPackages.itervalues(): if package.hlo: logging.info( "generating HLO list for package: %s" % package.getName()) self._generateHLOListByPackage( package.hlo, package.getName(), gblDataParser, fileNo) allHLOs.extend(package.hlo) if allHLOs: self._generateHLOListByPackage(allHLOs, "All", gblDataParser, fileNo) elif fileNo == '19': """ generate all option list """ if not os.path.exists(outDir + "/19"): os.mkdir(outDir + "/19") if not os.path.exists(outDir + "/Menus"): os.mkdir(outDir + "/Menus") allOptionList = [] allMenuList = [] serverMenuList = [] outJSON = {} for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] allOptionList.append(dataEntry) if '4' in dataEntry.fields: if dataEntry.fields['4'].value == 'menu': allMenuList.append(dataEntry) # Separate list for the "server" OPTIONS elif (dataEntry.fields['4'].value == 'server'): serverMenuList.append(dataEntry) else: logging.error( "ien: %s of file 19 does not have a type" % ien) self._generateDataListByPackage( allOptionList, "All", option_list_fields, "Option", [x[0] for x in option_list_fields], ["Name", "Lock"], fileNo) self._generateDataListByPackage( allMenuList, "All", menu_list_fields, "menus", [x[0] for x in menu_list_fields], ["Name", "Menu Text", "Lock"], fileNo) self._generateServerMenu(allMenuList, allOptionList, serverMenuList) self._generateMenuDependency(allMenuList, allOptionList) if not os.path.exists(self.outDir + "/%s" % fileNo.replace('.', '_')): os.mkdir(self.outDir + "/%s" % fileNo.replace('.', '_')) allObjectsList = [] outJSON = {} for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] outJSON[ien] = dataEntry.fields allObjectsList.append(dataEntry) self._generateDataListByPackage(allObjectsList, "All", option_list_fields, "Function", [x[0] for x in option_list_fields], ["Name", "Lock"], fileNo) with open( os.path.join(self.outDir, "dox", "%s.json" % fileNo.replace('.', '_')), 'w') as output: logging.info("Generate File: %s" % output.name) json.dump(outJSON, output, ensure_ascii=False, cls=OSEHRAEncoder) self._generateDataTableHtml(fileManData, fileNo) self._convertFileManDataToHtml(fileManData)
def _convertFileManSubFileDataToHtml(self, output, fileManData): output.write ("<ol>\n") for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] self._fileManDataEntryToHtml(output, dataEntry, False) output.write ("</ol>\n")
def outputAllFileManDataAsHtml(self, gblDataParser): """ This is the entry pointer to generate Html output format based on FileMan Data object @TODO: integrate with FileManFileOutputFormat.py """ crossRef = self.crossRef fileManDataMap = gblDataParser.outFileManData self.dataMap = gblDataParser for fileNo in getKeys(fileManDataMap.iterkeys(), float): fileManData = fileManDataMap[fileNo] fileNoPathSafe = fileNo.replace('.','_') fileNoOutDir = os.path.join(self.outDir, fileNoPathSafe) if not os.path.exists(fileNoOutDir): os.mkdir(fileNoOutDir) if fileNo == '8994': if crossRef: allPackages = crossRef.getAllPackages() allRpcs = [] for package in allPackages.itervalues(): if package.rpcs: self._generateRPCListHtml(package.rpcs, package.getName(), fileNoOutDir) allRpcs.extend(package.rpcs) if allRpcs: self._generateRPCListHtml(allRpcs, "All", fileNoOutDir) elif fileNo == '101': menuOutDir = os.path.join(self.outDir, "menus", "101") if not os.path.exists(menuOutDir): os.makedirs(menuOutDir) allProtoMenuList = [] if crossRef: allPackages = crossRef.getAllPackages() allHl7s = [] allProtocols = [] for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] allProtocols.append(dataEntry) fields = dataEntry.fields if '4' in fields: if fields['4'].value == 'menu': allProtoMenuList.append(dataEntry) for package in allPackages.itervalues(): if package.hl7: self._generateHL7ListByPackage(package.hl7, package.getName(), fileNoOutDir) allHl7s.extend(package.hl7) if package.protocol: self._generateProtocolListByPackage(package.protocol, package.getName(), fileNoOutDir) if allHl7s: self._generateHL7ListByPackage(allHl7s, "All", fileNoOutDir) if allProtocols: self._generateProtocolListByPackage(allProtocols, "All", fileNoOutDir) self._generateMenuDependency(allProtoMenuList, allProtocols,menuOutDir) elif fileNo == '779.2': if crossRef: allPackages = crossRef.getAllPackages() allHLOs = [] for package in allPackages.itervalues(): if package.hlo: self._generateHLOListByPackage(package.hlo, package.getName(), gblDataParser, fileNoOutDir) allHLOs.extend(package.hlo) if allHLOs: self._generateHLOListByPackage(allHLOs, "All", gblDataParser, fileNoOutDir) elif fileNo == '19': allOptionList = [] allMenuList = [] serverMenuList = [] outJSON = {} menuOutDir = os.path.join(self.outDir, "menus", "19") if not os.path.exists(menuOutDir): os.makedirs(menuOutDir) for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] allOptionList.append(dataEntry) fields = dataEntry.fields if '4' in fields: if fields['4'].value == 'menu': allMenuList.append(dataEntry) # Seperate list for the "server" OPTIONS elif fields['4'].value == 'server': serverMenuList.append(dataEntry); else: logger.error("ien: %s of file 19 does not have a type" % ien) self._generateDataListByPackage(allOptionList, "All", option_list_fields, "Option", [x[0] for x in option_list_fields], ["Name", "Lock"], fileNoOutDir) self._generateDataListByPackage(allMenuList, "All", menu_list_fields, "menus", [x[0] for x in menu_list_fields], ["Name", "Menu Text", "Lock"], fileNoOutDir) self._generateServerMenu(allMenuList, allOptionList, serverMenuList) self._generateMenuDependency(allMenuList, allOptionList,menuOutDir) allObjectsList = [] outJSON = {} for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] outJSON[ien] = dataEntry.fields allObjectsList.append(dataEntry) self._generateDataListByPackage(allObjectsList, "All", option_list_fields, "Function", [x[0] for x in option_list_fields], ["Name", "Lock"], fileNoOutDir) with open(os.path.join(self.outDir, "dox", "%s.json" % fileNoPathSafe), 'w') as output: json.dump(outJSON, output, ensure_ascii=False, cls=OSEHRAEncoder) self._generateDataTableHtml(fileManData, fileNo, fileNoOutDir) self._convertFileManDataToHtml(fileManData)
def testGlobalParser(crosRef=None): parser = createArgParser() result = parser.parse_args() print result from InitCrossReferenceGenerator import parseCrossRefGeneratorWithArgs from FileManDataToHtml import FileManDataToHtml crossRef = parseCrossRefGeneratorWithArgs(result) glbDataParser = FileManGlobalDataParser(crossRef) #glbDataParser.parseAllZWRGlobaFilesBySchema(result.MRepositDir, allSchemaDict) allFiles = glbDataParser.getAllFileManZWRFiles( os.path.join(result.MRepositDir, 'Packages'), "*/Globals/*.zwr") assert '0' in allFiles and '1' in allFiles and set( result.fileNos).issubset(allFiles) schemaParser = FileManSchemaParser() allSchemaDict = schemaParser.parseSchemaDDFileV2(allFiles['0']['path']) isolatedFiles = schemaParser.isolatedFiles glbDataParser.parseZWRGlobalFileBySchemaV2(allFiles['1']['path'], allSchemaDict, '1', '^DIC(') glbDataParser._allFiles = allFiles glbDataParser._allSchemaDict = allSchemaDict for fileNo in result.fileNos: assert fileNo in glbDataParser.globalLocationMap if result.outdir: glbDataParser.outDir = result.outdir if result.patchRepositDir: glbDataParser.patchDir = result.patchRepositDir htmlGen = FileManDataToHtml(crossRef, result.outdir) if not result.all or set(result.fileNos).issubset(isolatedFiles): for fileNo in result.fileNos: gdFile = allFiles[fileNo]['path'] logging.info("Parsing file: %s at %s" % (fileNo, gdFile)) glbDataParser.parseZWRGlobalFileBySchemaV2(gdFile, allSchemaDict, fileNo) if result.outdir: htmlGen.outputFileManDataAsHtml(glbDataParser) else: fileManDataMap = glbDataParser.outFileManData for file in getKeys(fileManDataMap.iterkeys(), float): printFileManFileData(fileManDataMap[file]) del glbDataParser.outFileManData[fileNo] glbDataParser.outRtnReferenceDict() return """ Also generate all required files as well """ sccSet = schemaParser.sccSet fileSet = set(result.fileNos) for idx, value in enumerate(sccSet): fileSet.difference_update(value) if not fileSet: break for i in xrange(0, idx + 1): fileSet = sccSet[i] fileSet &= set(allFiles.keys()) fileSet -= isolatedFiles fileSet.discard('757') if len(fileSet) > 1: for file in fileSet: zwrFile = allFiles[file]['path'] globalSub = allFiles[file]['name'] logging.info("Generate file key index for: %s at %s" % (file, zwrFile)) glbDataParser.generateFileIndex(zwrFile, allSchemaDict, file) for file in fileSet: zwrFile = allFiles[file]['path'] globalSub = allFiles[file]['name'] logging.info("Parsing file: %s at %s" % (file, zwrFile)) glbDataParser.parseZWRGlobalFileBySchemaV2(zwrFile, allSchemaDict, file) if result.outdir: htmlGen.outputFileManDataAsHtml(glbDataParser) del glbDataParser.outFileManData[file]
def _convertFileManSubFileDataToHtml(self, output, fileManData): output.write("<ol>\n") for ien in getKeys(fileManData.dataEntries.keys(), float): dataEntry = fileManData.dataEntries[ien] self._fileManDataEntryToHtml(output, dataEntry, False) output.write("</ol>\n")