summaryrefslogtreecommitdiff
blob: 437140f599994670afacee9738ab77b263481ae9 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=6

if [[ ${PV} = 9999* ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/python-diamond/Diamond.git"
	S=${WORKDIR}/diamond-${PV}
else
	GHASH=73207d04e0739a4ce92bc201b36681c42d9fa7e7  # python3 branch
	SRC_URI="https://github.com/python-diamond/Diamond/archive/${GHASH}.tar.gz -> python-diamond-${PV}.tar.gz"
	KEYWORDS="amd64 x86 ~amd64-linux ~ppc-macos ~x64-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
	S=${WORKDIR}/Diamond-${GHASH}
fi

PYTHON_COMPAT=( python3_{7,8} )

inherit distutils-r1 prefix

DESCRIPTION="Python daemon that collects and publishes system metrics"
HOMEPAGE="https://github.com/python-diamond/Diamond"

LICENSE="MIT"
SLOT="0"
IUSE="test mongo mysql snmp redis"
RESTRICT="!test? ( test )"

RDEPEND="dev-python/configobj
	dev-python/setproctitle
	mongo? ( dev-python/pymongo )
	mysql? ( dev-python/mysqlclient )
	snmp? ( dev-python/pysnmp )
	redis? ( dev-python/redis-py )
	!kernel_linux? ( >=dev-python/psutil-3 )"
DEPEND="${RDEPEND}
	test? (
		dev-python/mock
		dev-python/pysnmp
	)"

src_prepare() {
	# adjust for Prefix
	hprefixify bin/diamond*

	# fix the version (not set in GitHub archive)
	sed -i -e "s/__VERSIONTOKENHERE__/${PV}/" src/diamond/version.py.tmpl || die
	echo "${PV}" > version.txt || die
	# fix psutil usage
	sed -i -e 's/psutil\.network_io_counters/psutil.net_io_counters/' \
		src/collectors/network/network.py || die
	# fix symlink out of place
	rm README.md || die
	cp docs/index.md README.md || die

	# this module isn't Python3 yet (lambda), if you use this and have a
	# fix, let me know
	rm src/diamond/handler/rrdtool.py || die

	# forgotten conversion
	sed -i \
		-e 's/import Queue/import queue/' \
		-e 's/Queue\.Full/queue.Full/' \
		src/diamond/handler/queue.py || die
	# fix usage of map as list
	sed -i \
		-e '/paths = map(str.strip, paths)/d' \
		src/diamond/utils/classes.py || die
	# send data as bytes
	sed -i \
		-e '/self.socket.sendall/s/data/str.encode(data)/' \
		src/diamond/handler/graphite.py || die

	distutils-r1_src_prepare
}

python_test() {
	# don't want to depend on docker for just this
	mv src/collectors/docker_collector/test/{test,no}docker_collector.py || die
	# fails on binding ports
	mv src/collectors/portstat/tests/{test,no}_portstat.py || die
	"${PYTHON}" ./test.py || die "Tests fail with ${PYTHON}"
}

python_install() {
	export VIRTUAL_ENV=1
	distutils-r1_python_install
	python_optimize
	mv "${ED}"/usr/etc "${ED}"/ || die
	rm "${ED}"/etc/diamond/*.windows  # won't need these
	sed -i \
		-e '/pid_file =/s:/var/run:/run:' \
		"${ED}"/etc/diamond/diamond.conf.example || die
	hprefixify "${ED}"/etc/diamond/diamond.conf.example
}

src_install() {
	distutils-r1_src_install
	newinitd "${FILESDIR}"/${PN}.initd ${PN}
	newconfd "${FILESDIR}"/${PN}.confd ${PN}
	keepdir /var/log/diamond
}