def addMibCompiler(mibBuilder, **kwargs): if kwargs.get('ifNotAdded') and mibBuilder.getMibCompiler(): return compiler = MibCompiler( parserFactory(**smiV1Relaxed)(), PySnmpCodeGen(), PyFileWriter(kwargs.get('destination') or defaultDest) ) compiler.addSources(*getReadersFromUrls(*kwargs.get('sources') or defaultSources)) compiler.addSearchers( StubSearcher(*baseMibs) # XXX ) compiler.addSearchers( *[ PyPackageSearcher(x.fullPath()) for x in mibBuilder.getMibSources() ] ) compiler.addBorrowers( *[ PyFileBorrower(x, genTexts=mibBuilder.loadTexts) for x in getReadersFromUrls(*kwargs.get('borrowers') or defaultBorrowers, **dict(lowcaseMatching=False)) ] ) mibBuilder.setMibCompiler( compiler, kwargs.get('destination') or defaultDest )
inputMibs = ['BORROWED-MIB'] httpSources = [('mibs.snmplabs.com', 80, '/asn1/@mib@')] httpBorrowers = [('mibs.snmplabs.com', 80, '/pysnmp/notexts/@mib@')] dstDirectory = '.pysnmp-mibs' # Initialize compiler infrastructure mibCompiler = MibCompiler( parserFactory(**smiV1Relaxed)(), PySnmpCodeGen(), PyFileWriter(dstDirectory)) # search for source MIBs at Web sites mibCompiler.addSources(*[HttpReader(*x) for x in httpSources]) # never recompile MIBs with MACROs mibCompiler.addSearchers(StubSearcher(*baseMibs)) # check compiled/borrowed MIBs in our own productions mibCompiler.addSearchers(PyFileSearcher(dstDirectory)) # search for compiled MIBs at Web sites if source is not available or broken mibCompiler.addBorrowers(*[ PyFileBorrower(HttpReader(*x)).setOptions(genTexts=False) for x in httpBorrowers ]) # run non-recursive MIB compilation results = mibCompiler.compile(*inputMibs) print('Results: %s' % ', '.join(['%s:%s' % (x, results[x]) for x in results]))
from pysmi.borrower.pyfile import PyFileBorrower from pysmi.writer.pyfile import PyFileWriter from pysmi.parser.null import NullParser from pysmi.codegen.null import NullCodeGen from pysmi.compiler import MibCompiler from pysmi import debug #debug.setLogger(debug.Debug('compiler')) inputMibs = ['BORROWED-MIB'] httpBorrowers = [('mibs.snmplabs.com', 80, '/pysnmp/notexts/@mib@')] dstDirectory = '.pysnmp-mibs' # Initialize compiler infrastructure mibCompiler = MibCompiler(NullParser(), NullCodeGen(), PyFileWriter(dstDirectory)) # check compiled/borrowed MIBs in our own productions mibCompiler.addSearchers(PyFileSearcher(dstDirectory)) # search for precompiled MIBs at Web sites mibCompiler.addBorrowers( *[PyFileBorrower(HttpReader(*x)) for x in httpBorrowers]) # run MIB compilation results = mibCompiler.compile(*inputMibs) print('Results: %s' % ', '.join(['%s:%s' % (x, results[x]) for x in results]))
PyFileWriter(dstDirectory).setOptions( pyCompile=pyCompileFlag, pyOptimizationLevel=pyOptimizationLevel)) try: mibCompiler.addSources(*getReadersFromUrls( *mibSources, **dict(fuzzyMatching=doFuzzyMatchingFlag))) mibCompiler.addSearchers(PyFileSearcher(dstDirectory)) for mibSearcher in mibSearchers: mibCompiler.addSearchers(PyPackageSearcher(mibSearcher)) mibCompiler.addSearchers(StubSearcher(*mibStubs)) mibCompiler.addBorrowers(*[ PyFileBorrower(x[1], genTexts=mibBorrowers[x[0]][1]) for x in enumerate( getReadersFromUrls(*[m[0] for m in mibBorrowers], **dict(lowcaseMatching=False))) ]) processed = mibCompiler.compile( *inputMibs, **dict(noDeps=nodepsFlag, rebuild=rebuildFlag, dryRun=dryrunFlag, genTexts=genMibTextsFlag, ignoreErrors=ignoreErrorsFlag)) if buildIndexFlag: mibCompiler.buildIndex(processed,
NetSnmpCodeGen(writer,**dict(mappingFile=mappingFile, clangFormatPath=clangFormatPath, jsonTables=jsonTables,scalarMapping=scalarMapping)), writer) try: mibCompiler.addSources(*getReadersFromUrls(*mibSources, **dict(fuzzyMatching=doFuzzyMatchingFlag))) mibCompiler.addSearchers(PyFileSearcher(dstDirectory)) for mibSearcher in mibSearchers: mibCompiler.addSearchers(PyPackageSearcher(mibSearcher)) mibCompiler.addSearchers(StubSearcher(*mibStubs)) mibCompiler.addBorrowers(*[ PyFileBorrower(x[1], genTexts=mibBorrowers[x[0]][1]) for x in enumerate(getReadersFromUrls(*[m[0] for m in mibBorrowers], **dict(lowcaseMatching=False))) ]) processed = mibCompiler.compile(*inputMibs, **dict(noDeps=nodepsFlag, rebuild=rebuildFlag, dryRun=dryrunFlag, genTexts=genMibTextsFlag, ignoreErrors=ignoreErrorsFlag)) if buildIndexFlag: mibCompiler.buildIndex(processed, dryRun=dryrunFlag, ignoreErrors=ignoreErrorsFlag) except error.PySmiError: sys.stderr.write('ERROR: %s\r\n' % sys.exc_info()[1])