From bc77b4a8f8446a1939d7d55024206a02edd1fd33 Mon Sep 17 00:00:00 2001 From: thijs snijder <snijder@astron.nl> Date: Tue, 12 Apr 2022 11:11:38 +0200 Subject: [PATCH] updated README, cleaned up code, added ability to add multiple sources including web addresses --- .../toolkit/mib_compiler/README.md | 17 +++++++++++++++-- .../toolkit/mib_compiler/mib_compiler.py | 12 ++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/README.md b/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/README.md index 839697102..d99a55af6 100644 --- a/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/README.md +++ b/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/README.md @@ -1,15 +1,28 @@ #MIB Compiler The MIB compiler script 'compiles' .mib files to a custom python representation that pysnmp can load immediately. + In order to compile scripts there must be a valid mib file in the source directory as well as any potential imported files. -You can find out which mib files need to be imported by opening the file and looking at the `IMPORTS` section, where imported mib files are listed. These mibs may also have subsequent mib files that need to be imported. Alternatively these imports may also be found in the verbose debug log. +You can find out which mib files need to be imported by opening the file and looking at the `IMPORTS` section, where imported mib files are listed. +These mibs may also have subsequent mib files that need to be imported. Alternatively these imports may also be found in the verbose debug log. + +This script will also generate pymib files for all the imported mib files. `--mibs`: A list of mib files that need to be compiled. `--destination`: The output folder for the compiled mibs. This argument is optional. The default destination folder is `~/output_pymibs` -`--source`: The source folder from where the mib files are sourced. This argument is optional. The default source folder is `~/mibs` +`--source`: A list of source folders and addresses from where the mib files are sourced. This argument is optional. The default source folder is `~/mibs` +It can be useful to also list a web address as source, as there exist various sites that host mib files. `--debug`: enable verbose debugging. Useful for figuring out errors. +example usage: +To source the mib TEST-MIB from the default `/mibs` location +`python3 mib_compiler.py --mibs TEST-MIB` + +To source the mib TEST-MIB from the default `/mibs` location but to a custom output folder +`python3 mib_compiler.py --mibs TEST-MIB --destination home/user/output` +To source te mib TEST-MIB and all its imports from the path `home/user/mibs` and web address `http://www.net-snmp.org/docs/mibs/` +`python3 mib_compiler.py --mibs TEST-MIB --source home/user/mibs http://www.net-snmp.org/docs/mibs/` diff --git a/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py b/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py index 95b060442..eb8b1f530 100644 --- a/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py +++ b/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py @@ -13,14 +13,10 @@ def mib_compile(mib_list : list, src, dst): fpath = str(Path().absolute()).replace("\\", "/") - # "file://" prefix required for local files - src = "file://" + src - mibBuilder = builder.MibBuilder() - # set the path for the input .mib files - # f'file://{fpath}/mibs' - compiler.addMibCompiler(mibBuilder, sources=[src, ], destination=dst) + # set the compiler, the source path and set the www.net-snmp.org site as mib source as well. + compiler.addMibCompiler(mibBuilder, sources=src, destination=dst) for i in mib_list: # compile it @@ -46,8 +42,8 @@ if __name__ == "__main__": help='sets the output directory for the compiled mibs. (default: ' '%(default)s)') parser.add_argument( - '-s', '--source', type=str, required=False, default=in_path, - help='sets the input directory to read the .mib files from (default: ' + '-s', '--source', type=str, required=False, nargs='+', default=in_path, + help='sets the input paths or addresses to read the .mib files from (default: ' '%(default)s)') parser.add_argument( '-v', '--debug', dest='debug', action='store_true', default=False, -- GitLab