From 19542299d3f4095acda802b73b8a71a2f208cdf2 Mon Sep 17 00:00:00 2001 From: Paul Vinciguerra Date: Sun, 17 Mar 2019 17:34:46 -0700 Subject: vpp_papi: remove dependency on environment var. VPP_API_DIR. Change-Id: I9e3af8674e8aae27079fd03f6286f165d777814f Signed-off-by: Paul Vinciguerra --- src/vpp-api/python/vpp_papi/vpp_papi.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/vpp-api') diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py index 9849d2e487c..8dcd63a0c55 100644 --- a/src/vpp-api/python/vpp_papi/vpp_papi.py +++ b/src/vpp-api/python/vpp_papi/vpp_papi.py @@ -121,7 +121,7 @@ class VPPValueError(ValueError): pass -class VPP(object): +class VPPApiClient(object): """VPP interface. This class provides the APIs to VPP. The APIs are loaded @@ -133,6 +133,7 @@ class VPP(object): provides a means to register a callback function to receive these messages in a background thread. """ + apidir = None VPPApiError = VPPApiError VPPRuntimeError = VPPRuntimeError VPPValueError = VPPValueError @@ -211,6 +212,9 @@ class VPP(object): loglevel, if supplied, is the log level this logger is set to report at (from the loglevels in the logging module). """ + if apifiles is None and self.__class__.apidir is None: + raise ValueError("Either apifiles or apidir must be specified.") + if logger is None: logger = logging.getLogger(__name__) if loglevel is not None: @@ -288,10 +292,7 @@ class VPP(object): :returns: A single directory name, or None if no such directory could be found. """ - dirs = [] - - if 'VPP_API_DIR' in os.environ: - dirs.append(os.environ['VPP_API_DIR']) + dirs = [cls.apidir] # perhaps we're in the 'src/scripts' or 'src/vpp-api/python' dir; # in which case, plot a course to likely places in the src tree @@ -353,7 +354,7 @@ class VPP(object): # finally, try the location system packages typically install into dirs.append(os.path.sep.join(('', 'usr', 'share', 'vpp', 'api'))) - # check the directories for existance; first one wins + # check the directories for existence; first one wins for dir in dirs: if os.path.isdir(dir): return dir @@ -713,5 +714,7 @@ class VPP(object): if self.event_callback: self.event_callback(msgname, r) +# Provide the old name for backward compatibility. +VPP = VPPApiClient # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 -- cgit 1.2.3-korg