Skip to content

Commit

Permalink
281 bug unable to import ezexceptions with ezsnmp v200b0 (#285)
Browse files Browse the repository at this point in the history
* Exceptions

- created the exceptions.i interface file
- updated other interface files to use the exceptions.i file
- added the c+ code for the custom exception classes for EzSnmp. More can be added as needed.

* exceptions.i

- fixed and improvements to the new interface file. Not working yet, but getting closer.

* Compiles

- this version compiles. yay.
- the exceptions interface file is now generated properly.

* Custom Exceptions

- starting to replace run_time errors with errors defined in `exceptions.h`.

* Docs and Except

- updated the docs with the new exception types
- updated rest of runtime_errors

* Tests, Docs, Fixes

- attempted to use new exceptions in tests, that didn't work. I'll need to follow what I did for session.py and sessionbase.py
- added GenericException to the interface
- few doc fixes in development doc.

* Compiles and new ExceptionBase

- added an exceptionbase layer
- the python3 wrapper adds the Exception python class and then sets up the rest of the custom errors.

* Added Base To Name

- added Base to the name of c++ errors
- still working on the python wrapper. getting closer.

* Closer

- this get's us closer. I now see ` _exceptions.GenericErrorBase: sysDescripto.0: Unknown Object Identifier (Sub-id not found: (top) -> sysDescripto)`

* Path Forward

- current solution is to create a wrapper around netsnmp to catch exceptions from lower level calls and map them to simple names that don't have base in the name.

* netsnmpbas

- making the new netsnmpbase
- making the new netsnmp wrapper python3 code around netsnmpbase

* Black and clang

- ran black
- ran clang
- organize alphabetically

* Docs

- working on docs, need to rerun doxygen and sphinx

* test_netsnmp

- test netsnmp tests, great start for POC.

* Docs

- saving doc work

* Tests

Results (101.34s (0:01:41)):
      35 passed
      60 failed

* _handle_errror

- forgot to commit the new handle_error common function.

* Returns

- forgot to add returns to the function calls.

* test_session

- the test_session tests now pass on their own.

* tests/test_cache_v3.py

- pass now 100 percent

* tests/test_netsnmp.py

- 100 percent pass now.

* Sphinx Docs

- updating the Docs to work again. Getting close.

* Sphinx Docs

- updated the index.rst with an example that works.
- updated docs again.
  • Loading branch information
carlkidcrypto authored Jan 30, 2025
1 parent a2bf88e commit 711a2e0
Show file tree
Hide file tree
Showing 104 changed files with 45,108 additions and 11,569 deletions.
Binary file modified docs/doctrees/datatypes_interface.doctree
Binary file not shown.
Binary file modified docs/doctrees/development.doctree
Binary file not shown.
Binary file modified docs/doctrees/environment.pickle
Binary file not shown.
Binary file added docs/doctrees/exceptions_python.doctree
Binary file not shown.
Binary file added docs/doctrees/exceptionsbase_cpp.doctree
Binary file not shown.
Binary file added docs/doctrees/exceptionsbase_interface.doctree
Binary file not shown.
Binary file modified docs/doctrees/index.doctree
Binary file not shown.
Binary file modified docs/doctrees/modules.doctree
Binary file not shown.
Binary file not shown.
Binary file modified docs/doctrees/session_python.doctree
Binary file not shown.
Binary file modified docs/doctrees/sessionbase_cpp.doctree
Binary file not shown.
Binary file modified docs/doctrees/sessionbase_interface.doctree
Binary file not shown.
Binary file modified docs/doctrees/snmpbulkget_interface.doctree
Binary file not shown.
Binary file modified docs/doctrees/snmpbulkwalk_interface.doctree
Binary file not shown.
Binary file modified docs/doctrees/snmpget_interface.doctree
Binary file not shown.
Binary file modified docs/doctrees/snmpgetnext_interface.doctree
Binary file not shown.
Binary file modified docs/doctrees/snmpset_interface.doctree
Binary file not shown.
Binary file modified docs/doctrees/snmptrap_interface.doctree
Binary file not shown.
Binary file modified docs/doctrees/snmpwalk_interface.doctree
Binary file not shown.
Binary file modified docs/doctrees/swig_interface_files.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
config: a7e07f5498711547e40528d7fc68b4d7
config: 23dc4f4eaa1626595159615d23355193
tags: 645f666f9bcd5a90fca523b33c5a78b7
11 changes: 6 additions & 5 deletions docs/html/_sources/development.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ Four run the command below to generate the wrap file.

.. code-block:: bash
swig -c++ -python -builtin -threads -doxygen -std=c++17 -outdir ezsnmp/. -o ezsnmp/src/ezsnmp_netsnmp.cpp ezsnmp/interface/netsnmp.i &&
swig -c++ -python -builtin -threads -doxygen -std=c++17 -outdir ezsnmp/. -o ezsnmp/src/ezsnmp_netsnmpbase.cpp ezsnmp/interface/netsnmpbase.i &&
swig -c++ -python -builtin -threads -doxygen -std=c++17 -outdir ezsnmp/. -o ezsnmp/src/ezsnmp_sessionbase.cpp ezsnmp/interface/sessionbase.i &&
swig -c++ -python -builtin -threads -doxygen -std=c++17 -outdir ezsnmp/. -o ezsnmp/src/ezsnmp_datatypes.cpp ezsnmp/interface/datatypes.i
swig -c++ -python -builtin -threads -doxygen -std=c++17 -outdir ezsnmp/. -o ezsnmp/src/ezsnmp_datatypes.cpp ezsnmp/interface/datatypes.i &&
swig -c++ -python -builtin -threads -doxygen -std=c++17 -outdir ezsnmp/. -o ezsnmp/src/ezsnmp_exceptionsbase.cpp ezsnmp/interface/exceptionsbase.i
* `-c++` to force generation of a `.cpp` file
Expand Down Expand Up @@ -86,7 +87,7 @@ them with the following on Linux:
echo 'mibs +ALL' > ~/.snmp/snmp.conf;
sudo systemctl start snmpd;
rm -drf build/ dist/ ezsnmp.egg-info;
python3 -m pip install -r requirements.txt;
python3 -m pip install -r tests/requirements.txt;
python3 -m pip install . && pytest tests/;
# Bottom one for debug. Replace the top one with it if needed.
# python3 -m pip install . && gdb -ex run -ex bt -ex quit --args python3 -m pytest .;
Expand All @@ -107,7 +108,7 @@ On MacOS
sudo launchctl unload /System/Library/LaunchDaemons/org.net-snmp.snmpd.plist;
sudo launchctl load -w /System/Library/LaunchDaemons/org.net-snmp.snmpd.plist;
rm -drf build/ dist/ ezsnmp.egg-info;
python3 -m pip install -r requirements.txt;
python3 -m pip install -r tests/requirements.txt;
python3 -m pip install . && pytest tests/;
Expand All @@ -131,7 +132,7 @@ For MacOS builds on a MacOS machine
Formatting
----------

For c++ code:
For c++ code using clang-format 20+:

.. code:: bash
Expand Down
67 changes: 67 additions & 0 deletions docs/html/_sources/exceptions_python.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Exceptions Python Module
========================

.. automodule:: ezsnmp.exceptions
:no-index:

.. autoclass:: ezsnmp.exceptions.ConnectionError
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

.. autoclass:: ezsnmp.exceptions.GenericError
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

.. autoclass:: ezsnmp.exceptions.NoSuchInstanceError
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

.. autoclass:: ezsnmp.exceptions.NoSuchNameError
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

.. autoclass:: ezsnmp.exceptions.NoSuchObjectError
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

.. autoclass:: ezsnmp.exceptions.PacketError
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

.. autoclass:: ezsnmp.exceptions.ParseError
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

.. autoclass:: ezsnmp.exceptions.TimeoutError
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

.. autoclass:: ezsnmp.exceptions.UndeterminedTypeError
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

.. autoclass:: ezsnmp.exceptions.UnknownObjectIDError
:members:
:undoc-members:
:show-inheritance:
:special-members: __init__

.. autofunction:: ezsnmp.exceptions._handle_error
72 changes: 72 additions & 0 deletions docs/html/_sources/exceptionsbase_cpp.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Exceptions C++ Module
=====================

.. doxygenclass:: ConnectionErrorBase
:project: EzSnmp
:members:
:private-members:
:undoc-members:
:protected-members:

.. doxygenclass:: GenericErrorBase
:project: EzSnmp
:members:
:private-members:
:undoc-members:
:protected-members:

.. doxygenclass:: NoSuchInstanceErrorBase
:project: EzSnmp
:members:
:private-members:
:undoc-members:
:protected-members:

.. doxygenclass:: NoSuchNameErrorBase
:project: EzSnmp
:members:
:private-members:
:undoc-members:
:protected-members:

.. doxygenclass:: NoSuchObjectErrorBase
:project: EzSnmp
:members:
:private-members:
:undoc-members:
:protected-members:

.. doxygenclass:: PacketErrorBase
:project: EzSnmp
:members:
:private-members:
:undoc-members:
:protected-members:

.. doxygenclass:: ParseErrorBase
:project: EzSnmp
:members:
:private-members:
:undoc-members:
:protected-members:

.. doxygenclass:: TimeoutErrorBase
:project: EzSnmp
:members:
:private-members:
:undoc-members:
:protected-members:

.. doxygenclass:: UndeterminedTypeErrorBase
:project: EzSnmp
:members:
:private-members:
:undoc-members:
:protected-members:

.. doxygenclass:: UnknownObjectIDErrorBase
:project: EzSnmp
:members:
:private-members:
:undoc-members:
:protected-members:
5 changes: 5 additions & 0 deletions docs/html/_sources/exceptionsbase_interface.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exceptionsbase.i
================

.. literalinclude:: ../../ezsnmp/interface/exceptionsbase.i
:language: c++
22 changes: 22 additions & 0 deletions docs/html/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ Example Session Kargs
# Do stuff with res
print(res)
EzSnmp Exception Handling
-------------------------

EzSnmp provides custom exception classes contained in `exceptions` to handle errors that may occur during SNMP operations.
This allows you to catch and manage exceptions specific to EzSnmp more effectively.

Here's an example of how to use one of the exceptions classes.:

.. code-block:: python
from ezsnmp import Session, exceptions
try:
session = Session(hostname='localhost', community='public', version=2)
result = session.get('sysDescr.0')
print(result)
except exceptions.GenericError as e:
print(f"An error occurred: {e}")
By catching exceptions, you can handle errors such as connection issues, authentication failures, or invalid OIDs in a more granular way, providing better control over your SNMP operations.

.. toctree::
:maxdepth: 2
:caption: Contents:
Expand Down
6 changes: 4 additions & 2 deletions docs/html/_sources/modules.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
:maxdepth: 8

datatypes_cpp
development
exceptions_python
exceptionsbase_cpp
session_python
sessionbase_cpp
swig_interface_files
development
swig_interface_files
5 changes: 0 additions & 5 deletions docs/html/_sources/netsnmp_interface.rst.txt

This file was deleted.

5 changes: 5 additions & 0 deletions docs/html/_sources/netsnmpbase_interface.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
netsnmpbase.i
=============

.. literalinclude:: ../../ezsnmp/interface/netsnmpbase.i
:language: c++
2 changes: 1 addition & 1 deletion docs/html/_sources/session_python.rst.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Python Session Module
Session Python Module
=====================

.. automodule:: ezsnmp.session
Expand Down
3 changes: 2 additions & 1 deletion docs/html/_sources/swig_interface_files.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ For more information on the SWIG interface files, see the `SWIG documentation <h
:maxdepth: 10

datatypes_interface
netsnmp_interface
exceptionsbase_interface
netsnmpbase_interface
sessionbase_interface
snmpbulkget_interface
snmpbulkwalk_interface
Expand Down
2 changes: 1 addition & 1 deletion docs/html/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const DOCUMENTATION_OPTIONS = {
VERSION: 'V2.0.0b0',
VERSION: 'V2.0.0b1',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
23 changes: 13 additions & 10 deletions docs/html/datatypes_cpp.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<head><meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="Python Session Module" href="session_python.html" /><link rel="prev" title="&lt;no title&gt;" href="modules.html" />
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="Development Guide" href="development.html" /><link rel="prev" title="&lt;no title&gt;" href="modules.html" />

<!-- Generated with Sphinx 8.1.3 and Furo 2024.08.06 -->
<title>Datatypes C++ Module - EzSnmp V2.0.0b0 documentation</title>
<title>Datatypes C++ Module - EzSnmp V2.0.0b1 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=8f2a1f02" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=354aac6f" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=302659d7" />
Expand Down Expand Up @@ -166,7 +166,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">EzSnmp V2.0.0b0 documentation</div></a>
<a href="index.html"><div class="brand">EzSnmp V2.0.0b1 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
Expand All @@ -190,7 +190,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">


<span class="sidebar-brand-text">EzSnmp V2.0.0b0 documentation</span>
<span class="sidebar-brand-text">EzSnmp V2.0.0b1 documentation</span>

</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
Expand All @@ -201,11 +201,15 @@
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1 current current-page"><a class="current reference internal" href="#">Datatypes C++ Module</a></li>
<li class="toctree-l1"><a class="reference internal" href="session_python.html">Python Session Module</a></li>
<li class="toctree-l1"><a class="reference internal" href="development.html">Development Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="exceptions_python.html">Exceptions Python Module</a></li>
<li class="toctree-l1"><a class="reference internal" href="exceptionsbase_cpp.html">Exceptions C++ Module</a></li>
<li class="toctree-l1"><a class="reference internal" href="session_python.html">Session Python Module</a></li>
<li class="toctree-l1"><a class="reference internal" href="sessionbase_cpp.html">SessionBase C++ Module</a></li>
<li class="toctree-l1 has-children"><a class="reference internal" href="swig_interface_files.html">Swig Interface File(s)</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle navigation of Swig Interface File(s)</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="datatypes_interface.html">datatypes.i</a></li>
<li class="toctree-l2"><a class="reference internal" href="netsnmp_interface.html">netsnmp.i</a></li>
<li class="toctree-l2"><a class="reference internal" href="exceptionsbase_interface.html">exceptionsbase.i</a></li>
<li class="toctree-l2"><a class="reference internal" href="netsnmpbase_interface.html">netsnmpbase.i</a></li>
<li class="toctree-l2"><a class="reference internal" href="sessionbase_interface.html">sessionbase.i</a></li>
<li class="toctree-l2"><a class="reference internal" href="snmpbulkget_interface.html">snmpbulkget.i</a></li>
<li class="toctree-l2"><a class="reference internal" href="snmpbulkwalk_interface.html">snmpbulkwalk.i</a></li>
Expand All @@ -216,7 +220,6 @@
<li class="toctree-l2"><a class="reference internal" href="snmpwalk_interface.html">snmpwalk.i</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="development.html">Development Guide</a></li>
</ul>

</div>
Expand Down Expand Up @@ -315,12 +318,12 @@ <h1>Datatypes C++ Module<a class="headerlink" href="#datatypes-c-module" title="
<footer>

<div class="related-pages">
<a class="next-page" href="session_python.html">
<a class="next-page" href="development.html">
<div class="page-info">
<div class="context">
<span>Next</span>
</div>
<div class="title">Python Session Module</div>
<div class="title">Development Guide</div>
</div>
<svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
</a>
Expand Down Expand Up @@ -385,7 +388,7 @@ <h1>Datatypes C++ Module<a class="headerlink" href="#datatypes-c-module" title="

</aside>
</div>
</div><script src="_static/documentation_options.js?v=26a2042e"></script>
</div><script src="_static/documentation_options.js?v=82da8037"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/scripts/furo.js?v=5fa4622c"></script>
Expand Down
Loading

0 comments on commit 711a2e0

Please sign in to comment.