@cryptotaxi247 / netdata-1 / commits / df0fef443

python UrlService class: add find_binary method which uses PATH env var

Ilya committed Jan 31, 2017 at 12:23 UTC df0fef4435b6be6d0751341f73c47224d444aed2
1 file changed +17
python.d/python_modules/base.py
+17
@@ -32,6 +32,11 @@ from subprocess import Popen, PIPE
32 import threading
33 import msg
34
35 +try:
36 + PATH = os.getenv('PATH').split(':')
37 +except NameError:
38 + PATH = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'.split(':')
39 +
40
41 # class BaseService(threading.Thread):
42 class SimpleService(threading.Thread):
@@ -431,6 +436,18 @@ class SimpleService(threading.Thread):
436
437 return updated
438
439 + def find_binary(self, binary):
440 + try:
441 + if isinstance(binary, str):
442 + binary = os.path.basename(binary)
443 + return next(('/'.join([p, binary]) for p in PATH
444 + if os.path.isfile('/'.join([p, binary]))
445 + and os.access('/'.join([p, binary]), os.X_OK)))
446 + else:
447 + return None
448 + except StopIteration:
449 + return None
450 +
451
452 class UrlService(SimpleService):
453 # TODO add support for https connections