Commit 923daa841dce00c3c3011cfff343788523400f17

Authored by Austin Blanton
1 parent 480fa5d1

Check the LD_LIBRARY_PATH for libopenbr in init_brpy

Showing 1 changed file with 21 additions and 7 deletions
scripts/brpy/__init__.py
... ... @@ -21,13 +21,27 @@ def _handle_string_func(func):
21 21 return call_func
22 22  
23 23 def init_brpy(br_loc='/usr/local/lib'):
24   - """Takes the ctypes lib object for br and initializes all function inputs and outputs"""
25   - br_loc += '/libopenbr.%s'
26   - if os.path.exists(br_loc % 'dylib'):
27   - br = cdll.LoadLibrary(br_loc % 'dylib')
28   - elif os.path.exists(br_loc % 'so'):
29   - br = cdll.LoadLibrary(br_loc % 'so')
30   - else:
  24 + """Initializes all function inputs and outputs for the br ctypes lib object"""
  25 +
  26 + lib_path = os.environ.get('LD_LIBRARY_PATH')
  27 + paths = [br_loc]
  28 + if lib_path:
  29 + paths.extend(lib_path.split(':'))
  30 +
  31 + found = False
  32 + for p in paths:
  33 + dylib = '%s/%s.%s' % (p, 'libopenbr', 'dylib')
  34 + so = '%s/%s.%s' % (p, 'libopenbr', 'so')
  35 + if os.path.exists(dylib):
  36 + br = cdll.LoadLibrary(dylib)
  37 + found = True
  38 + break
  39 + elif os.path.exists(so):
  40 + br = cdll.LoadLibrary(so)
  41 + found = True
  42 + break
  43 +
  44 + if not found:
31 45 raise ValueError('Neither .so nor .dylib libopenbr found in %s' % br_loc)
32 46  
33 47 plot_args = _var_string_args(1) + [c_bool]
... ...