def __outputGlobal__(self, Global): outputDict = self._outputDict outputDict["name"] = Global.getName() outputDict["package"] = Global.getPackage().getName() outputDict[ "accessed_by_routines"] = self.__outputAccessByRoutineList__( Global)
def __outputGlobal__(self, Global): outputDict = self._outputDict outputDict["name"] = Global.getName() outputDict["package"] = Global.getPackage().getName() outputDict["accessed_by_routines"] = self.__outputAccessByRoutineList__(Global)
def findGlobalsBySourceV2(self, dirName, pattern): searchFiles = glob.glob(os.path.join(dirName, pattern)) logger.info("Total Search Files are %d " % len(searchFiles)) crossReference = self.crossRef allGlobals = crossReference.getAllGlobals() allPackages = crossReference.getAllPackages() skipFile = [] fileNoSet = set() for file in searchFiles: packageName = os.path.dirname(file) packageName = packageName[packageName.index("Packages") + 9:packageName.index("Globals") - 1] if not crossReference.hasPackage(packageName): crossReference.addPackageByName(packageName) package = allPackages.get(packageName) zwrFile = codecs.open(file, 'r', encoding='utf-8', errors='ignore') lineNo = 0 fileName = os.path.basename(file) result = ZWR_FILENO_REGEX.search(fileName) if result: fileNo = result.group('fileNo') if fileNo.startswith('0'): fileNo = fileNo[1:] globalDes = result.group('des') else: result = ZWR_NAMESPACE_REGEX.search(fileName) if result: namespace = result.group('namespace') # package.addGlobalNamespace(namespace) continue else: continue globalName = "" # find out the global name by parsing the global file logger.debug("Parsing file: %s" % file) for line in zwrFile: if lineNo == 0: globalDes = line.strip() # Removing the extra text in the header of the ZWR file # to tell if it needs to be added or skipped globalDes = globalDes.replace("OSEHRA ZGO Export: ", '') if globalDes.startswith("^"): logger.info("No Description: Skip this file: %s" % file) skipFile.append(file) namespace = globalDes[1:] package.addGlobalNamespace(namespace) break if lineNo >= 2: info = line.strip().split('=') globalName = info[0] detail = info[1].strip("\"") if globalName.find(',') > 0: result = globalName.split(',') if len(result) == 2 and result[1] == "0)": globalName = result[0] break elif globalName.endswith("(0)"): globalName = globalName.split('(')[0] break else: continue lineNo = lineNo + 1 if not fileNo: if file not in skipFile: logger.warn("Warning: No FileNo found for file %s" % file) continue globalVar = Global(globalName, fileNo, globalDes, allPackages.get(packageName)) try: fileNum = float(globalVar.getFileNo()) except ValueError as es: logger.error("error: %s, globalVar:%s file %s" % (es, globalVar, file)) continue # crossReference.addGlobalToPackage(globalVar, packageName) # only add to allGlobals dict as we have to change the package later on if globalVar.getName() not in allGlobals: allGlobals[globalVar.getName()] = globalVar if fileNo not in fileNoSet: fileNoSet.add(fileNo) else: logger.error( "Duplicated file No [%s,%s,%s,%s] file:%s " % (fileNo, globalName, globalDes, packageName, file)) zwrFile.close() logger.info( "Total # of Packages is %d and Total # of Globals is %d, Total Skip File %d, total FileNo is %d" % (len(allPackages), len(allGlobals), len(skipFile), len(fileNoSet))) sortedKeyList = sorted( list(allGlobals.keys()), key=lambda item: float(allGlobals[item].getFileNo())) for key in sortedKeyList: globalVar = allGlobals[key] # fix the uncategoried item if globalVar.getFileNo() in fileNoPackageMappingDict: globalVar.setPackage(allPackages[fileNoPackageMappingDict[ globalVar.getFileNo()]]) crossReference.addGlobalToPackage(globalVar, globalVar.getPackage().getName())