Skip to content

Commit 15f5fd3

Browse files
committed
Allow 7z or 7za
1 parent 5adde5b commit 15f5fd3

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

build.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@
1010
from urllib.request import Request, urlopen
1111
from warnings import catch_warnings
1212

13+
class Globals:
14+
SEVEN_ZIP_EXECUTABLE = None
15+
16+
def findWorkingExecutablePath(executable_paths, flags):
17+
#type: (List[str], List[str]) -> str
18+
"""
19+
Try to execute each path in executable_paths to see which one can be called and returns exit code 0
20+
The 'flags' argument is any extra flags required to make the executable return 0 exit code
21+
:param executable_paths: a list [] of possible executable paths (eg. "./7za", "7z")
22+
:param flags: a list [] of any extra flags like "-h" required to make the executable have a 0 exit code
23+
:return: the path of the valid executable, or None if no valid executables found
24+
"""
25+
with open(os.devnull, 'w') as os_devnull:
26+
for path in executable_paths:
27+
try:
28+
if subprocess.call([path] + flags, stdout=os_devnull, stderr=os_devnull) == 0:
29+
return path
30+
except:
31+
pass
32+
33+
return None
34+
1335
# Get the github ref
1436
GIT_TAG = None
1537
GIT_REF = os.environ.get("GITHUB_REF") # Github Tag / Version info
@@ -155,14 +177,14 @@ def download(url):
155177

156178

157179
def seven_zip_extract(input_path, outputDir=None):
158-
args = ["7z", "x", input_path, "-y"]
180+
args = [Globals.SEVEN_ZIP_EXECUTABLE, "x", input_path, "-y"]
159181
if outputDir:
160182
args.append("-o" + outputDir)
161183

162184
call(args)
163185

164186
def seven_zip_compress(input_path, output_path):
165-
args = ["7z", "a", "-md=512m", output_path, input_path, "-y"]
187+
args = [Globals.SEVEN_ZIP_EXECUTABLE, "a", "-md=512m", output_path, input_path, "-y"]
166188

167189
call(args)
168190

@@ -255,6 +277,11 @@ def save(self):
255277
if not (sys.version_info < (3, 11)):
256278
print(">>>> WARNING: This script probably does not work on Python 3.11 because unitypack uses old version of decrunch which does not build. Use Python 3.10 or below if you have this error.")
257279

280+
Globals.SEVEN_ZIP_EXECUTABLE = findWorkingExecutablePath(["7za", "7z"], ['-h'])
281+
if Globals.SEVEN_ZIP_EXECUTABLE is None:
282+
print(">>>> ERROR: Can't find 7zip as '7z' or '7za'")
283+
exit(-1)
284+
258285
lastModifiedManager = LastModifiedManager()
259286

260287
# Parse command line arguments

0 commit comments

Comments
 (0)