#!/usr/bin/python import os, os.path, re universe = {} meta = {} todo = [ ( "", os.path.join( os.getcwd(), "mudpy.conf" ) ) ] while todo: anchor, datafile = todo.pop() datadir = os.path.dirname(datafile) if os.access(datafile, os.R_OK): data = file(datafile) for line in data: subanchor = "" if not ( re.match("^\w*#", line) or re.match("^\w*$", line) ): key, value = [ x.strip() for x in line.split("=", 1) ] value = eval( value, { "__builtins__": { "False": False, "True": True } } ) if key.startswith("!"): addkey = ".".join( [ ".file:"+datafile, key ] ) meta[addkey] = value if key.startswith("!load."): subanchor = key.replace("!load", anchor, 1) elif key == "!load": subanchor = anchor if subanchor: for item in value: if item.startswith("file:"): addfile = item.replace("file:", "", 1) if not addfile.startswith(os.path.sep): addfile = os.path.join( datadir, addfile ) if not ( subanchor, addfile ) in todo: todo = [ ( subanchor, addfile ) ] + todo else: if not key.startswith("."): key = ".".join( [ anchor, key ] ) universe[key] = value if key.startswith(".mudpy.data"): if key.startswith(".mudpy.data:"): subanchor = key.replace(".mudpy.data:", ".", 1) elif key == ".mudpy.data": subanchor = "." if subanchor and value.startswith("file:"): addfile = value.replace("file:", "", 1) if not addfile.startswith(os.path.sep): addfile = os.path.join( datadir, addfile ) if not ( subanchor, addfile ) in todo: todo = [ ( subanchor, addfile ) ] + todo data.close() else: print("WARNING: Cannot open " + datafile + " for reading.") for key, value in universe.items(): facet_name = key.split(".")[-1].split(":")[0] if facet_name == "facet": facet_def = ".mudpy.facet" else: facet_def = ".mudpy.facet:" + facet_name facet_type = str( type(value) ) if facet_def not in universe: print("WARNING: No strict typing for "+facet_name+" data, assuming "+facet_type+".") else: facet_check = "" if facet_type != facet_check: print("WARNING: Facet "+facet_name+" is "+facet_type+" but should be "+facet_check+".") keylist = meta.keys() keylist.sort() print("meta = {") for key in keylist: print(" " + key + " = " + repr(meta[key]) + ",") print(" }\n") keylist = universe.keys() keylist.sort() print("universe = {") for key in keylist: print(" " + key + " = " + repr(universe[key]) + ",") print(" }\n")