File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424import mmap
2525import os
2626
27+ import ctypes
2728from ctypes import c_char_p , c_wchar_p
2829from ctypes import c_int , c_longlong
2930from ctypes import c_size_t , c_ssize_t
8586# keys for plugin-provided locations
8687EXTRACTCODE_LIBARCHIVE_LIBDIR = 'extractcode.libarchive.libdir'
8788EXTRACTCODE_LIBARCHIVE_DLL = 'extractcode.libarchive.dll'
89+ _LIBRARY_NAME = "libarchive"
90+
91+ def load_lib_failover ():
92+ pass
8893
8994
9095def load_lib ():
@@ -96,11 +101,16 @@ def load_lib():
96101 dll = get_location (EXTRACTCODE_LIBARCHIVE_DLL )
97102 libdir = get_location (EXTRACTCODE_LIBARCHIVE_LIBDIR )
98103 if not (dll and libdir ) or not os .path .isfile (dll ) or not os .path .isdir (libdir ):
99- raise Exception (
100- 'CRITICAL: libarchive DLL is not installed. '
101- 'Unable to continue: you need to install a valid extractcode-libarchive '
102- 'plugin with a valid libarchive DLL available.'
103- )
104+ filepath = ctypes .util .find_library (_LIBRARY_NAME )
105+ libarchive = ctypes .cdll .LoadLibrary (filepath )
106+ if libarchive is None :
107+ raise ImportError (
108+ 'CRITICAL: libarchive DLL is not installed. '
109+ 'Unable to continue: you need to install a valid extractcode-libarchive '
110+ 'plugin with a valid libarchive DLL available '
111+ 'or to have "libarchive" library installed in your system.'
112+ )
113+ return libarchive
104114 return command .load_shared_library (dll , libdir )
105115
106116
Original file line number Diff line number Diff line change 2424import os
2525import pprint
2626import re
27+ from shutil import which
2728
2829import attr
2930
@@ -80,11 +81,15 @@ def get_bin_locations():
8081 cmd_loc = get_location (EXTRACTCODE_7ZIP_EXE )
8182 libdir = get_location (EXTRACTCODE_7ZIP_LIBDIR )
8283 if not (cmd_loc and libdir ) or not os .path .isfile (cmd_loc ) or not os .path .isdir (libdir ):
83- raise Exception (
84- 'CRITICAL: 7zip executable is not installed. '
85- 'Unable to continue: you need to install a valid extractcode-7z '
86- 'plugin with a valid executable available.'
87- )
84+ sevenzip = which ("7z" )
85+ if sevenzip is None :
86+ raise ImportError (
87+ 'CRITICAL: 7zip executable is not installed. '
88+ 'Unable to continue: you need to install a valid extractcode-7z '
89+ 'plugin with a valid executable available '
90+ 'or install p7zip in your system, so that a "7z" program is available on your PATH'
91+ )
92+ return "" , sevenzip
8893
8994 return libdir , cmd_loc
9095
You can’t perform that action at this time.
0 commit comments