|
10 | 10 | from urllib.request import Request, urlopen
|
11 | 11 | from warnings import catch_warnings
|
12 | 12 |
|
| 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 | + |
13 | 35 | # Get the github ref
|
14 | 36 | GIT_TAG = None
|
15 | 37 | GIT_REF = os.environ.get("GITHUB_REF") # Github Tag / Version info
|
@@ -155,14 +177,14 @@ def download(url):
|
155 | 177 |
|
156 | 178 |
|
157 | 179 | 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"] |
159 | 181 | if outputDir:
|
160 | 182 | args.append("-o" + outputDir)
|
161 | 183 |
|
162 | 184 | call(args)
|
163 | 185 |
|
164 | 186 | 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"] |
166 | 188 |
|
167 | 189 | call(args)
|
168 | 190 |
|
@@ -255,6 +277,11 @@ def save(self):
|
255 | 277 | if not (sys.version_info < (3, 11)):
|
256 | 278 | 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.")
|
257 | 279 |
|
| 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 | + |
258 | 285 | lastModifiedManager = LastModifiedManager()
|
259 | 286 |
|
260 | 287 | # Parse command line arguments
|
|
0 commit comments