+class otool(object):
+ """Gather information from an object file using otool"""
+ def __init__(self, object_path):
+ self.otool = "/usr/bin/otool"
+ self.object_path = object_path
+ if not os.path.exists(self.object_path):
+ raise RuntimeError("path not found")
+
+ def __run_command(self, option):
+ p = Popen([self.otool, option, self.object_path],
+ bufsize=1, stdin=PIPE, stdout=PIPE, close_fds=True)
+ os.waitpid(p.pid, 0)
+ return p
+
+ def _is_object(self):
+ """"Check to see if object_path is an object-file"""
+ p = self.__run_command("-h")
+ header = p.stdout.read()
+ if re.search("Mach header", header):
+ return True
+ else:
+ return False
+ isObject = property(_is_object)
+
+ def _get_shared_libraries(self):
+ """Return list of shared libraries"""
+ if not self.isObject:
+ raise RuntimeError("Not object")
+ p = self.__run_command("-L")
+ libraries = []
+ output_lines = p.stdout.readlines()
+ # ignore the header, or perhaps we should test it
+ # to see if it matches self.object_path
+ for line in output_lines[1:]:
+ if len(line) > 0:
+ libraries.append(line.split()[0].strip())
+ return libraries
+ SharedLibraries = property(_get_shared_libraries)