Esempio n. 1
0
    def addMibCompiler(mibBuilder, **kwargs):
        if kwargs.get('ifNotAdded') and mibBuilder.getMibCompiler():
            return

        compiler = MibCompiler(
            parserFactory(**smiV1Relaxed)(),
            PySnmpCodeGen(),
            PyFileWriter(kwargs.get('destination') or DEFAULT_DEST))

        compiler.addSources(
            *getReadersFromUrls(*kwargs.get('sources') or DEFAULT_SOURCES))

        compiler.addSearchers(
            StubSearcher(*baseMibs))

        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 DEFAULT_BORROWERS,
                    lowcaseMatching=False)])

        mibBuilder.setMibCompiler(
            compiler, kwargs.get('destination') or DEFAULT_DEST)
Esempio n. 2
0
    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
        )
Esempio n. 3
0
def _compile_mib_to_json(mib, source_mib_directories, destination_directory,
                         source, compiled_mibs_path):
    from pysmi.borrower import AnyFileBorrower
    from pysmi.codegen import JsonCodeGen
    from pysmi.compiler import MibCompiler
    from pysmi.parser import SmiV1CompatParser
    from pysmi.reader import getReadersFromUrls
    from pysmi.searcher import AnyFileSearcher, StubSearcher
    from pysmi.writer import FileWriter

    mib_stubs = JsonCodeGen.baseMibs

    compile_documentation = True

    # Compiler infrastructure

    code_generator = JsonCodeGen()

    file_writer = FileWriter(destination_directory).setOptions(suffix='.json')

    mib_compiler = MibCompiler(SmiV1CompatParser(tempdir=''), code_generator,
                               file_writer)

    # use source_mib_directories as mibs source
    sources = [source]
    sources.extend(source_mib_directories)
    mib_compiler.addSources(
        *getReadersFromUrls(*sources, **dict(fuzzyMatching=True)))

    searchers = [
        AnyFileSearcher(destination_directory).setOptions(exts=['.json']),
        StubSearcher(*mib_stubs)
    ]
    mib_compiler.addSearchers(*searchers)

    # borrowers, aka compiled mibs source
    borrowers = [
        AnyFileBorrower(borrower_reader,
                        genTexts=True).setOptions(exts=['.json'])
        for borrower_reader in getReadersFromUrls(
            *[compiled_mibs_path], **dict(lowcaseMatching=False))
    ]
    mib_compiler.addBorrowers(borrowers)

    processed = mib_compiler.compile(
        mib,
        **dict(
            noDeps=False,
            rebuild=False,
            dryRun=False,
            dstTemplate=None,
            genTexts=compile_documentation,
            textFilter=False and (lambda symbol, text: text) or None,
            writeMibs=True,
            ignoreErrors=False,
        ))

    return processed
Esempio n. 4
0
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]))
mibCompiler = MibCompiler(
    SmiV1CompatParser(tempdir=cacheDirectory),
    codeGenerator,
    fileWriter
)

try:
    mibCompiler.addSources(
        *getReadersFromUrls(
            *mibSources, **dict(fuzzyMatching=doFuzzyMatchingFlag)
        )
    )

    mibCompiler.addSearchers(*searchers)

    mibCompiler.addBorrowers(*borrowers)

    processed = mibCompiler.compile(
        *inputMibs, **dict(noDeps=nodepsFlag,
                           rebuild=rebuildFlag,
                           dryRun=dryrunFlag,
                           genTexts=genMibTextsFlag,
                           textFilter=keepTextsLayout and (lambda symbol, text: text) or None,
                           writeMibs=writeMibsFlag,
                           ignoreErrors=ignoreErrorsFlag)
    )

    if buildIndexFlag:
        mibCompiler.buildIndex(
            processed,
            dryRun=dryrunFlag,
Esempio n. 6
0
        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,
                               dryRun=dryrunFlag,
                               ignoreErrors=ignoreErrorsFlag)
Esempio n. 7
0
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]))
Esempio n. 8
0
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
        )
from pysmi.reader.httpclient import HttpReader
from pysmi.searcher.pyfile import PyFileSearcher
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]))
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]))
Esempio n. 11
0
mibCompiler = MibCompiler(
    SmiV1CompatParser(tempdir=cacheDirectory),
    codeGenerator,
    fileWriter
)

try:
    mibCompiler.addSources(
        *getReadersFromUrls(
            *mibSources, **dict(fuzzyMatching=doFuzzyMatchingFlag)
        )
    )

    mibCompiler.addSearchers(*searchers)

    mibCompiler.addBorrowers(*borrowers)

    processed = mibCompiler.compile(
        *inputMibs, **dict(noDeps=nodepsFlag,
                           rebuild=rebuildFlag,
                           dryRun=dryrunFlag,
                           dstTemplate=dstTemplate,
                           genTexts=genMibTextsFlag,
                           textFilter=keepTextsLayout and (lambda symbol, text: text) or None,
                           writeMibs=writeMibsFlag,
                           ignoreErrors=ignoreErrorsFlag)
    )

    if buildIndexFlag:
        mibCompiler.buildIndex(
            processed,