forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
21 lines (18 loc) · 678 Bytes
/
Copy pathutils.py
File metadata and controls
21 lines (18 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from pyroute2 import NSPopen
from distutils.spawn import find_executable
def has_executable(name):
path = find_executable(name)
if path is None:
raise Exception(name + ": command not found")
return path
class NSPopenWithCheck(NSPopen):
"""
A wrapper for NSPopen that additionally checks if the program
to be executed is available from the system path or not.
If found, it proceeds with the usual NSPopen() call.
Otherwise, it raises an exception.
"""
def __init__(self, nsname, *argv, **kwarg):
name = list(argv)[0][0]
has_executable(name)
super(NSPopenWithCheck, self).__init__(nsname, *argv, **kwarg)