Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _line0_says_object(line0, filename):
line0 = line0.strip()
for test in BAD_OBJECT_TESTS:
if test(line0):
return False
if line0.startswith('Archive :'):
# nothing to do for static libs
return False
if not line0.startswith(filename + ':'):
raise InstallNameError('Unexpected first line: ' + line0)
further_report = line0[len(filename) + 1:]
if further_report == '':
return True
raise InstallNameError(
'Too ignorant to know what "{0}" means'.format(further_report))
def _line0_says_object(line0, filename):
line0 = line0.strip()
for test in BAD_OBJECT_TESTS:
if test(line0):
return False
if line0.startswith('Archive :'):
# nothing to do for static libs
return False
if not line0.startswith(filename + ':'):
raise InstallNameError('Unexpected first line: ' + line0)
further_report = line0[len(filename) + 1:]
if further_report == '':
return True
raise InstallNameError(
'Too ignorant to know what "{0}" means'.format(further_report))
----------
filename : str
filename of library
Returns
-------
install_id : str
install id of library `filename`, or None if no install id
"""
lines = _cmd_out_err(['otool', '-D', filename])
if not _line0_says_object(lines[0], filename):
return None
if len(lines) == 1:
return None
if len(lines) != 2:
raise InstallNameError('Unexpected otool output ' + '\n'.join(lines))
return lines[1].strip()
def set_install_id(filename, install_id):
""" Set install id for library named in `filename`
Parameters
----------
filename : str
filename of library
install_id : str
install id for library `filename`
Raises
------
RuntimeError if `filename` has not install id
"""
if get_install_id(filename) is None:
raise InstallNameError('{0} has no install id'.format(filename))
back_tick(['install_name_tool', '-id', install_id, filename])