def parseWithoutValidation(modelName, modelPath): xmlParser = etree.XMLParser(remove_comments=True) try: xmlRootElem = etree.parse(modelPath, xmlParser) except Exception as e: debug.dump("ERROR", "Parsing of {0} failed.".format(modelPath)) debug.dump("DEBUG", "Error: {0}".format(e)) raise RuntimeError, "Failed to parse XML" return xmlRootElem
def parseWithoutValidation(modelName, modelPath) : xmlParser = etree.XMLParser(remove_comments=True) try : xmlRootElem = etree.parse(modelPath, xmlParser) except Exception as e : debug.dump("ERROR", "Parsing of {0} failed.".format(modelPath)) debug.dump("DEBUG", "Error: {0}".format(e)) raise RuntimeError, "Failed to parse XML" return xmlRootElem
def ifPathsAreValid(paths): ''' Verify if path exists and are readable. ''' if paths: for p in paths: if not paths[p]: continue for path in paths[p]: if not path: continue if os.path.isfile(path): pass else: debug.printDebug( "ERROR", "Filepath {0} does not exists".format(path)) return False # check if file is readable if not os.access(path, os.R_OK): debug.dump("ERROR", "File {0} is not readable".format(path)) return False return True
def parseXMLs(commandLineArgs, validate=False) : xmlRootElemDict = collections.defaultdict(list) models = vars(commandLineArgs) for model in models : if models[model] : for modelPath in models[model] : debug.dump("INFO", "Parsing {0}".format(models[model])) if validate : # parse model and valid it with schama modelXMLRootElem = parseAndValidateWithSchema(model, modelPath) else : # Simple parse the model without validating it with schema. modelXMLRootElem = parseWithoutValidation(model, modelPath) if modelXMLRootElem : xmlRootElemDict[model].append((modelXMLRootElem, modelPath)) assert len(xmlRootElemDict) > 0 return xmlRootElemDict
def ifPathsAreValid(paths) : ''' Verify if path exists and are readable. ''' if paths : for p in paths : if not paths[p] : continue for path in paths[p] : if not path : continue if os.path.isfile(path) : pass else : debug.printDebug("ERROR" , "Filepath {0} does not exists".format(path)) return False # check if file is readable if not os.access(path, os.R_OK) : debug.dump("ERROR", "File {0} is not readable".format(path)) return False return True
def parseXMLs(commandLineArgs, validate=False): xmlRootElemDict = collections.defaultdict(list) models = vars(commandLineArgs) for model in models: if models[model]: for modelPath in models[model]: debug.dump("INFO", "Parsing {0}".format(models[model])) if validate: # parse model and valid it with schama modelXMLRootElem = parseAndValidateWithSchema( model, modelPath) else: # Simple parse the model without validating it with schema. modelXMLRootElem = parseWithoutValidation(model, modelPath) if modelXMLRootElem: xmlRootElemDict[model].append( (modelXMLRootElem, modelPath)) assert len(xmlRootElemDict) > 0 return xmlRootElemDict
def parseAndValidateWithSchema(modelName, modelPath) : prefixPath = '' if modelName == 'xml' : schemaPath = os.path.join(prefixPath, 'schema/moose/moose.xsd') if not os.path.isfile(schemaPath) : debug.dump("WARN", "Schema {0} does not exists..".format(schemaPath)) try : schemaH = open(schemaPath, "r") schemaText = schemaH.read() schemaH.close() except Exception as e : debug.dump("WARN", "Error reading schema for validation."+ " Falling back to validation-disabled parser." + " Failed with error {0}".format(e)) return parseWithoutValidation(modelName, modelPath) # Now we have the schema text schema = etree.XMLSchema(etree.XML(schemaText)) xmlParser = etree.XMLParser(schema=schema, remove_comments=True) with open(modelPath, "r") as xmlTextFile : return etree.parse(xmlTextFile, xmlParser)
def parseAndValidateWithSchema(modelName, modelPath): prefixPath = '' if modelName == 'xml': schemaPath = os.path.join(prefixPath, 'schema/moose/moose.xsd') if not os.path.isfile(schemaPath): debug.dump("WARN", "Schema {0} does not exists..".format(schemaPath)) try: schemaH = open(schemaPath, "r") schemaText = schemaH.read() schemaH.close() except Exception as e: debug.dump( "WARN", "Error reading schema for validation." + " Falling back to validation-disabled parser." + " Failed with error {0}".format(e)) return parseWithoutValidation(modelName, modelPath) # Now we have the schema text schema = etree.XMLSchema(etree.XML(schemaText)) xmlParser = etree.XMLParser(schema=schema, remove_comments=True) with open(modelPath, "r") as xmlTextFile: return etree.parse(xmlTextFile, xmlParser)
def exit(chip8, profile): if profile["debugging"] == "True": debug.dump(chip8) pygame.quit() sys.exit()
def main(stdscr): global width global height global xOffset global yOffset width = curses.COLS height = curses.LINES curses.start_color() curses.use_default_colors() # Initialize terminal colors and save them for faster lookup later for i in range(0, curses.COLORS): curses.init_pair(i + 1, i, -1) #termColorsList[i] = curses.color_pair(i) termColorsList.append(curses.color_pair(i)) #movementSpeed = scale / width / 10 # Initial setup of the land, temp, biome, and TODO precip storage. for i in range(height): for j in range(width): x = xOffset + ((j - width / 2) / scale) y = yOffset + ((i - height / 2) / scale / ratio) index = (i * width) + j #landStorage.append(helper.heightLookup(x, y)) landStorage.append(helper.floraLookup(x, y)) tempStorage.append(helper.tempLookup(x, y)) biomeStorage.append(helper.biomeLookupByTP(tempStorage[index], 0)) # First time drawing to screen. simpleRedraw(stdscr) # todo: eventually move to a library that supports key pressed/released # events to support multiple keys at once working properly start_time = 0 while True: # Record any debugging information before waiting. # This is the last possible moment of the previous frame. elapsed_time = time.time() - start_time if DEBUG == True: debug.dump(stdscr, {"total_time": elapsed_time}) debug.addInfoString("FPS: " + str(1.0 / elapsed_time)) #stdscr.addstr(10, 0, "Time taken: " + str(elapsed_time)) keyPressed = stdscr.getkey() start_time = time.time() if keyPressed == "w": move(stdscr, 0, -1) elif keyPressed == "s": move(stdscr, 0, 1) elif keyPressed == "a": move(stdscr, -2, 0) elif keyPressed == "d": move(stdscr, 2, 0) elif keyPressed == "=": zoom(stdscr, 2.0) elif keyPressed == "-": zoom(stdscr, 0.5) elif keyPressed == "q": break