# Copyright 2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{12..14} )
PYTHON_REQ_USE="readline(+)"
DISTUTILS_USE_PEP517=setuptools

inherit distutils-r1

DESCRIPTION="An open-source exploitation framework dedicated to embedded devices"
HOMEPAGE="https://github.com/threat9/routersploit/wiki"

if [[ ${PV} == *9999 ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/threat9/routersploit"
else
	SRC_URI="https://github.com/threat9/routersploit/archive/v${PV}.tar.gz -> ${P}.tar.gz"
	KEYWORDS="~amd64 ~arm64 ~x86"
fi

LICENSE="BSD"
SLOT="0"
IUSE="doc"

RDEPEND="${PYTHON_DEPS}
	dev-python/requests[${PYTHON_USEDEP}]
	dev-python/paramiko[${PYTHON_USEDEP}]
	dev-python/pysnmp[${PYTHON_USEDEP}]
	dev-python/pycryptodome[${PYTHON_USEDEP}]
	dev-python/bluepy[${PYTHON_USEDEP}]"

DEPEND="${RDEPEND}"
#BDEPEND="test? (
#	dev-python/pytest[${PYTHON_USEDEP}]
#	dev-python/pytest-forked[${PYTHON_USEDEP}]
#	dev-python/pytest-xdist[${PYTHON_USEDEP}]
#	dev-python/flake8[${PYTHON_USEDEP}]
#	dev-python/threat9-test-bed[${PYTHON_USEDEP}]
#)"

# These tests are actual exploits/payloads and may required a vulnerable target
RESTRICT="test"

#EPYTEST_PLUGINS=( pytest-forked pytest-xdist )
#distutils_enable_tests pytest

src_prepare() {
	# These tests are actual exploits/payloads and may required a vulnerable target
	rm -rf tests || die

	# use normal oldstyle names of exec files
	mv rsf.py rsf && sed -i \
		-e "s/scripts=('rsf.py',),/scripts=('rsf',),/" \
		setup.py || die

	eapply_user
}

#python_test() {
#	epytest -n16 tests/core/ tests/test_exploit_scenarios.py tests/test_module_info.py
#	epytest -n16 tests/exploits/ tests/creds/ tests/encoders/ tests/generic/ tests/payloads/
#}
