import os import sys import platform import re #Globals currOS = platform.platform() if currOS.find('Windows') == 0: LOCALBASE = 'C:/website/' else: LOCALBASE = '/ssd/home/sarge/prog/python/fron' CURRDIR = re.sub('\\\\+', '/', os.getcwd()) + '/' # TYPEFILE = CURRDIR + "types.tsv" TYPEFILE = 'E:/website/design/types.tsv' lsRec = [] # Get canonical name for type def find_canonical_type(typ, lsRec): typ = typ.strip() typ = typ.lower() for item in lsRec: if item[0] == typ: return item[1] return None #end find_canonical_type # Finds all types in a hierarchy below a given canonical type def add_subtypes(typ, lsRec): typOut = [typ] for t in lsRec: if len(t) >= 3: #only look at items that have higher types if typ == t[2]or typ == t[3] or typ == t[4]: newType = add_subtypes(t[1],lsRec) if newType: # No duplications allowed if not newType in typOut: typOut = typOut + newType return typOut # get subtypes def get_types(lsRec, typesIn): typelist = typesIn.split(',') typesOut = [] for typ in typelist: t = find_canonical_type(typ, lsRec) if t == None: print("Type %s not found." % typ) # Fronimo.print_error("Type %s not found." % typ) continue else: typesOut += add_subtypes(t, lsRec) return(typesOut) #end get_types def show_tuple(t): for item in t: print("%s, " % item, end = "") print("") # show_tuple # Prompt for comma separated list of types to search for # Return all types and sub-types def open_file(fl, mode): flName = open(fl, mode, encoding='latin1') return flName # end of openFile # Read in types list def main(): lsRec=[] flTypes = open_file(TYPEFILE, "r") if not flTypes: print("Cannot open TYPEFILE file.") exit(-1) stType = flTypes.read() lsIn = stType.split('\n') for line in lsIn: rec = line.split('\t') lsRec.append(rec) while True: typeList = input("Types requested:") if typeList == "": sys.exit(0) tpOut = get_types(lsRec, typeList) if tpOut: show_tuple(tpOut) # end main if __name__ == "__main__": main()