diff --git a/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py b/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py index 946baf742aac165a1daff3bf642668e22de131a4..95b060442221bee44847813d9059e91b157846da 100644 --- a/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py +++ b/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py @@ -4,44 +4,38 @@ from pysnmp.smi import builder, compiler from pathlib import Path import argparse -# import logging -# logging.basicConfig(level=logging.DEBUG, format = '%(asctime)s:%(levelname)s: %(message)s') -# logger = logging.getLogger("pymib") - - from pysmi import debug -debug.setLogger(debug.Debug('compiler')) +import logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger("mib_compiler") -def mib_compile(mib_list : list, src=None, dst=None): +def mib_compile(mib_list : list, src, dst): fpath = str(Path().absolute()).replace("\\", "/") - - if src is None: - src = f"{fpath}/mibs" - # "file://" prefix required for local files src = "file://" + src - if dst is None: - dst = f"{fpath}/output_pymibs" - - print(src, dst) mibBuilder = builder.MibBuilder() # set the path for the input .mib files # f'file://{fpath}/mibs' compiler.addMibCompiler(mibBuilder, sources=[src, ], destination=dst) - for i in mib_list: # compile it + try: + mibBuilder.loadModules(i) + logger.debug(f"loaded {i}") + except Exception as e: + raise Exception(f"Something went wrong, try checking whether all the mib fills imported by the provided mib files are present (To do this enable debug options and scroll up) ") from e + - mibBuilder.loadModules(i) - # logger.debug(f"Compiled \"{i}\"") if __name__ == "__main__": - out_path = f"{Path().absolute()}/output_pymibs" + abs_path = str(Path().absolute()).replace("\\", "/") + out_path = f"{abs_path}/output_pymibs" + in_path = f"{abs_path}/mibs" parser = argparse.ArgumentParser( description='Compiles .mib files in to the easy to load pysnmp format') @@ -52,9 +46,12 @@ if __name__ == "__main__": help='sets the output directory for the compiled mibs. (default: ' '%(default)s)') parser.add_argument( - '-s', '--source', type=str, required=False, + '-s', '--source', type=str, required=False, default=in_path, help='sets the input directory to read the .mib files from (default: ' '%(default)s)') + parser.add_argument( + '-v', '--debug', dest='debug', action='store_true', default=False, + help='increase log output') args = parser.parse_args() @@ -62,6 +59,10 @@ if __name__ == "__main__": mibs = args.mibs destination = args.destination source = args.source + debug_option = args.debug + + if debug_option: + debug.setLogger(debug.Debug('all')) + mib_compile(mib_list=mibs, src=source, dst=destination) - mib_compile(["TEST-MIB"], src=source, dst=destination)