inexio / snmpsim

SNMP Simulator
https://snmplabs.thola.io/snmpsim/
BSD 2-Clause "Simplified" License
54 stars 13 forks source link

Wrapping commands into py2exe package #15

Open curunoir opened 2 years ago

curunoir commented 2 years ago

Hello guys,

first thanks for the work !

I have the need to embed this package and particularly the snmp-record-command into a portable Windows executable so I have digged into py2exe and did some tests. I also noticed in the setup.py file some references of py2exe so I guess that what I want is doable.

I have managed to do some things with this py2exe setup.py:

from distutils.core import setup
import py2exe

setup(console=['snmp-record-command.py'])

and in snmp-record-command.py

import subprocess
import sys

sys.argv.pop(0)
return_code = subprocess.call(['snmpsim-record-commands'] + sys.argv)
print("Output of snmpsim-record-commands call() : ", return_code)

And this is working if I'm using the executable done

snmp-record-command.exe --agent-udpv4-endpoint=24.x.x.x --...

But my approach is not good because the subprocess.call(['snmpsim-record-commands'] + sys.argv) needs to have python + snmpsim already installed in the system which is not what I really wand because I need the executable to be standalone.

The problem is I don't understand how I could make. Can someone here points me to the good direction ? Thanks

curunoir commented 2 years ago

After some work i have found that this approach is getting better results but still don't work

setup(
    console=['snmpsim/commands/cmd2rec.py'],
    packages= setuptools.find_packages(),
    include_package_data=True,
    )

Which gaves me this output process terminated: No module SNMP-FRAMEWORK-MIB loaded at <pysnmp.smi.builder.MibBuilder object at 0x00000173C47D68E0>Traceback (most recent call last):; File "cmd2rec.py", line 740, in ; File "cmd2rec.py", line 361, in main; File "pysnmp\entity\engine.pyc", line 90, in init; File "pysnmp\smi\builder.pyc", line 443, in importSymbols;pysnmp.smi.error.MibNotFoundError: No module SNMP-FRAMEWORK-MIB loaded at <pysnmp.smi.builder.MibBuilder object at 0x00000173C47D68E0>; PS C:\Users\curun\source\repos\snmpsim-master\dist> .\cmd2rec.exe --agent-udpv4-en

The lacking No module __SNMP-FRAMEWORK-MIB looks like to be a folder from pysnmp which is not included into the library.zip.