def test_get_bin_lib_dirs(self): root_dir = self.get_test_loc('command/bin', copy=True) for os_arch, paths in self.os_arches_files_test_matrix.items(): base_dir = os.path.join(root_dir, os_arch) bin_dir, lib_dir = command.get_bin_lib_dirs(base_dir) expected_bin, expected_lib, expected_bin_files, expected_lib_files = paths def norm(p): return os.path.abspath(os.path.normpath(p)) if expected_bin: assert os.path.exists(bin_dir) assert os.path.isdir(bin_dir) pbd = fileutils.as_posixpath(bin_dir) assert pbd.endswith(expected_bin.replace('command/', '')) if expected_bin_files: assert all(f in expected_bin_files for f in os.listdir(bin_dir)) == True else: assert expected_bin == bin_dir if expected_lib: assert os.path.exists(lib_dir) assert os.path.isdir(lib_dir) pld = fileutils.as_posixpath(lib_dir) assert pld.endswith(expected_lib.replace('command/', '')) if expected_lib_files: assert all(f in expected_lib_files for f in os.listdir(lib_dir)) == True else: assert expected_lib == lib_dir
def test_get_bin_lib_dirs(self): root_dir = self.get_test_loc('command/bin', copy=True) for os_arch, paths in self.os_arches_files_test_matrix.items(): base_dir = os.path.join(root_dir, os_arch) bin_dir, lib_dir = command.get_bin_lib_dirs(base_dir) expected_bin, expected_lib, expected_bin_files, expected_lib_files = paths def norm(p): return os.path.abspath(os.path.normpath(p)) if expected_bin: assert os.path.exists(bin_dir) assert os.path.isdir(bin_dir) pbd = fileutils.as_posixpath(bin_dir) assert pbd.endswith(expected_bin.replace('command/', b'')) if expected_bin_files: assert all(f in expected_bin_files for f in os.listdir(bin_dir)) == True else: assert expected_bin == bin_dir if expected_lib: assert os.path.exists(lib_dir) assert os.path.isdir(lib_dir) pld = fileutils.as_posixpath(lib_dir) assert pld.endswith(expected_lib.replace('command/', b'')) if expected_lib_files: assert all(f in expected_lib_files for f in os.listdir(lib_dir)) == True else: assert expected_lib == lib_dir
def load_lib(): """ Return the loaded libmagic shared library object from vendored paths. """ root_dir = command.get_base_dirs(typecode.bin_dir)[0] _bin_dir, lib_dir = command.get_bin_lib_dirs(root_dir) magic_so = os.path.join(lib_dir, 'libmagic' + system.lib_ext) # add lib path to the front of the PATH env var new_path = os.pathsep.join([lib_dir, os.environ['PATH']]) os.environ['PATH'] = new_path if os.path.exists(magic_so): lib = ctypes.CDLL(magic_so) if lib and lib._name: return lib raise ImportError('Failed to load libmagic from %(magic_so)r' % locals())
def load_lib(): """ Return the loaded libarchive shared library object from vendored paths. """ root_dir = command.get_base_dirs(extractcode.root_dir)[0] _bin_dir, lib_dir = command.get_bin_lib_dirs(root_dir) libarchive = os.path.join(lib_dir, 'libarchive' + system.lib_ext) # add lib path to the front of the PATH env var new_path = os.pathsep.join([lib_dir, os.environ['PATH']]) os.environ['PATH'] = new_path # os.environ['TZ'] = 'UTC' if os.path.exists(libarchive): lib = ctypes.CDLL(libarchive) if lib and lib._name: return lib raise ImportError('Failed to load libarchive: %(libarchive)r' % locals())
def load_lib(): """ Return the loaded libmagic shared library object from vendored paths. """ # FIXME: use command.load_lib instead root_dir = command.get_base_dirs(bin_dir)[0] _bin_dir, lib_dir = command.get_bin_lib_dirs(root_dir) magic_so = os.path.join(lib_dir, 'libmagic' + system.lib_ext) # add lib path to the front of the PATH env var command.update_path_environment(lib_dir) if os.path.exists(magic_so): if not isinstance(magic_so, bytes): # ensure that the path is not Unicode... magic_so = fsencode(magic_so) lib = ctypes.CDLL(magic_so) if lib and lib._name: return lib raise ImportError('Failed to load libmagic from %(magic_so)r' % locals())
def load_lib(): """ Return the loaded libarchive shared library object from default "vendored" paths. e.g. this assumes that libarchive is stored in a well known location under exttractcode/bin with subdirectories for each supported OS. """ root_dir = command.get_base_dirs(extractcode.root_dir)[0] _bin_dir, lib_dir = command.get_bin_lib_dirs(root_dir) libarchive = os.path.join(lib_dir, 'libarchive' + system.lib_ext) # add lib path to the front of the PATH env var if lib_dir not in os.environ['PATH'].split(os.pathsep): new_path = os.pathsep.join([lib_dir, os.environ['PATH']]) os.environ['PATH'] = new_path if os.path.exists(libarchive): lib = ctypes.CDLL(libarchive) if lib and lib._name: return lib raise ImportError('Failed to load libarchive: %(libarchive)r' % locals())
def load_lib(): """ Return the loaded libmagic shared library object from vendored paths. """ root_dir = command.get_base_dirs(bin_dir)[0] _bin_dir, lib_dir = command.get_bin_lib_dirs(root_dir) magic_so = os.path.join(lib_dir, 'libmagic' + system.lib_ext) # add lib path to the front of the PATH env var new_path = os.pathsep.join([lib_dir, os.environ['PATH']]) os.environ['PATH'] = new_path if os.path.exists(magic_so): if not isinstance(magic_so, bytes): # ensure that the path is not Unicode... magic_so = magic_so.encode(sys.getfilesystemencoding() or sys.getdefaultencoding()) lib = ctypes.CDLL(magic_so) if lib and lib._name: return lib raise ImportError('Failed to load libmagic from %(magic_so)r' % locals())
def load_lib(): """ Return the loaded libarchive shared library object from default "vendored" paths. e.g. this assumes that libarchive is stored in a well known location under exttractcode/bin with subdirectories for each supported OS. """ # FIXME: use command.load_lib instead root_dir = command.get_base_dirs(extractcode.root_dir)[0] _bin_dir, lib_dir = command.get_bin_lib_dirs(root_dir) libarchive = os.path.join(lib_dir, 'libarchive' + system.lib_ext) # add lib path to the front of the PATH env var command.update_path_environment(lib_dir) if os.path.exists(libarchive): if not isinstance(libarchive, bytes): # ensure that the path is not Unicode... libarchive = fsencode(libarchive) lib = ctypes.CDLL(libarchive) if lib and lib._name: return lib raise ImportError('Failed to load libarchive: %(libarchive)s' % locals())