-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsetup.py
More file actions
50 lines (37 loc) · 1.33 KB
/
setup.py
File metadata and controls
50 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
setup.py — MikrotikAPI-BF
==========================
Post-install hook: copies NSE scripts to Nmap's scripts directory
automatically after `pip install` or `pip install --upgrade`.
This file works alongside pyproject.toml (PEP 517/518).
The post-install hook is the primary reason this file exists.
"""
from setuptools import setup
from setuptools.command.install import install
from setuptools.command.develop import develop
class _PostInstallMixin:
"""Mixin that runs NSE installer after pip install or pip install -e."""
def _run_nse_install(self) -> None:
try:
from mikrotikapi_bf.nse_installer import install_nse
print("\n [mikrotikapi-bf] Installing NSE scripts to Nmap...")
install_nse(verbose=True)
except Exception as exc:
print(f" [mikrotikapi-bf] NSE auto-install skipped: {exc}")
print(" Run manually: mikrotikapi-install-nse")
class PostInstall(_PostInstallMixin, install):
"""pip install hook."""
def run(self) -> None:
install.run(self)
self._run_nse_install()
class PostDevelop(_PostInstallMixin, develop):
"""pip install -e hook."""
def run(self) -> None:
develop.run(self)
self._run_nse_install()
setup(
cmdclass={
"install": PostInstall,
"develop": PostDevelop,
},
)