def test_get_base_dirs(self): root_dir = self.get_test_loc('command/bin', copy=True) for _os_arch, _os_noarch, _noarch in self.os_arches_test_matrix: bds = command.get_base_dirs(root_dir, _os_arch, _os_noarch, _noarch) assert bds for bd in bds: assert os.path.exists(bd)
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())
from os import fsencode except ImportError: from backports.os import fsencode """ magic2 is minimal and specialized wrapper around a vendored libmagic file identification library. This is NOT thread-safe. It is based on python-magic by Adam Hup and adapted to the specific needs of ScanCode. """ data_dir = os.path.join(os.path.dirname(__file__), 'data') bin_dir = os.path.join(os.path.dirname(__file__), 'bin') # path to vendored magic DB, possibly OS-specific basemag = os.path.join(data_dir, 'magic') # keep the first which is the most specific directory magdir = command.get_base_dirs(basemag)[0] magic_db = os.path.join(magdir, 'magic.mgc') # # Cached detectors # detectors = {} # libmagic flags MAGIC_NONE = 0 MAGIC_MIME = 16 MAGIC_MIME_ENCODING = 1024 MAGIC_NO_CHECK_ELF = 65536 MAGIC_NO_CHECK_TEXT = 131072 MAGIC_NO_CHECK_CDF = 262144
""" magic2 is minimal and specialized wrapper around a vendored libmagic file identification library. This is NOT thread-safe. It is based on python-magic by Adam Hup and adapted to the specific needs of ScanCode. """ data_dir = os.path.join(os.path.dirname(__file__), 'data') bin_dir = os.path.join(os.path.dirname(__file__), 'bin') # path to vendored magic DB, possibly OS-specific basemag = os.path.join(data_dir, 'magic') # keep the first which is the most specific directory magdir = command.get_base_dirs(basemag)[0] magic_db = os.path.join(magdir, 'magic.mgc') # # Cached detectors # detectors = {} # libmagic flags MAGIC_NONE = 0 MAGIC_MIME = 16 MAGIC_MIME_ENCODING = 1024 MAGIC_NO_CHECK_ELF = 65536 MAGIC_NO_CHECK_TEXT = 131072 MAGIC_NO_CHECK_CDF = 262144