def compile_module(modname, preload=None, all=False): if preload: for pm in preload: SMI.load_module(pm) smimodule = SMI.get_module(modname) if not smimodule: print "Could not load module", modname return if all: for dep in _get_dependents(smimodule): _compile_module(SMI.get_module(dep)) _compile_module(smimodule)
def compile_everything(all=False): count = 0 paths = SMI.get_path().split(":") for dir in paths: print "Looking in", dir for modname in os.listdir(dir): modpath = os.path.join(dir, modname) if os.path.isfile(modpath): print "Found module", modname, "compiling..." try: compile_module(modname, None, all) except SmiError, err: print "***[", err, "]***" count += 1 SMI.clear() # clear out mememory SMI.init()
def _get_dependents(module, hash=None): h = hash or {} for imp in module.get_imports(): h[imp.module] = True _get_dependents(SMI.get_module(imp.module), h) return h.keys()
return h.keys() def compile_everything(all=False): count = 0 paths = SMI.get_path().split(":") for dir in paths: print "Looking in", dir for modname in os.listdir(dir): modpath = os.path.join(dir, modname) if os.path.isfile(modpath): print "Found module", modname, "compiling..." try: compile_module(modname, None, all) except SmiError, err: print "***[", err, "]***" count += 1 SMI.clear() # clear out mememory SMI.init() print "Found and compiled %d MIBS." % (count, ) if __name__ == "__main__": import sys SMI.load_module("SNMPv2-SMI") mod = SMI.get_module("RMON2-MIB") #gen = ObjectSourceGenerator(sys.stdout, sys.stdout, mod) #gen.genAll() #print _get_dependents(mod)