Update MakeInstall.py: Search for 7zip on all drives

Fixes Issue #77

Signed-off-by: Jake Staehle <jacob@staehle.us>
This commit is contained in:
Jake Staehle 2020-04-09 11:34:19 -05:00
parent 26fda46c01
commit 516d31d6b1

View file

@ -1,5 +1,5 @@
from Scripts import utils, diskwin, downloader, run from Scripts import utils, diskwin, downloader, run
import os, sys, tempfile, shutil, zipfile, platform, json, time import os, sys, tempfile, shutil, zipfile, platform, json, time, string
class WinUSB: class WinUSB:
@ -36,8 +36,6 @@ class WinUSB:
self.diskpart = os.path.join(os.environ['SYSTEMDRIVE'] + "\\", "Windows", "System32", "diskpart.exe") self.diskpart = os.path.join(os.environ['SYSTEMDRIVE'] + "\\", "Windows", "System32", "diskpart.exe")
# From Tim Sutton's brigadier: https://github.com/timsutton/brigadier/blob/master/brigadier # From Tim Sutton's brigadier: https://github.com/timsutton/brigadier/blob/master/brigadier
self.z_path = None self.z_path = None
self.z_path64 = os.path.join(os.environ['SYSTEMDRIVE'] + "\\", "Program Files", "7-Zip", "7z.exe")
self.z_path32 = os.path.join(os.environ['SYSTEMDRIVE'] + "\\", "Program Files (x86)", "7-Zip", "7z.exe")
self.recovery_suffixes = ( self.recovery_suffixes = (
"recoveryhdupdate.pkg", "recoveryhdupdate.pkg",
"recoveryhdmetadmg.pkg" "recoveryhdmetadmg.pkg"
@ -108,7 +106,11 @@ class WinUSB:
return os.path.exists(os.path.join(self.s_path, self.dd_name)) return os.path.exists(os.path.join(self.s_path, self.dd_name))
def check_7z(self): def check_7z(self):
self.z_path = self.z_path64 if os.path.exists(self.z_path64) else self.z_path32 if os.path.exists(self.z_path32) else None all_drives = ["{}:".format(d) for d in string.ascii_uppercase if os.path.exists("{}:".format(d))]
for drive in all_drives:
z_path64 = os.path.join(drive + "\\", "Program Files", "7-Zip", "7z.exe")
z_path32 = os.path.join(drive + "\\", "Program Files (x86)", "7-Zip", "7z.exe")
self.z_path = z_path64 if os.path.exists(z_path64) else z_path32 if os.path.exists(z_path32) else None
if self.z_path: if self.z_path:
return True return True
print("Didn't locate {} - downloading...".format(self.z_name)) print("Didn't locate {} - downloading...".format(self.z_name))
@ -128,6 +130,7 @@ class WinUSB:
temp = tempfile.mkdtemp() temp = tempfile.mkdtemp()
dl_file = self.dl.stream_to_file(dl_url, os.path.join(temp, self.z_name)) dl_file = self.dl.stream_to_file(dl_url, os.path.join(temp, self.z_name))
if not dl_file: # Didn't download right if not dl_file: # Didn't download right
print("Error downloading 7zip...")
shutil.rmtree(temp,ignore_errors=True) shutil.rmtree(temp,ignore_errors=True)
return False return False
print("") print("")
@ -141,7 +144,12 @@ class WinUSB:
self.u.grab("Press [enter] to exit...") self.u.grab("Press [enter] to exit...")
exit(1) exit(1)
print("") print("")
self.z_path = self.z_path64 if os.path.exists(self.z_path64) else self.z_path32 if os.path.exists(self.z_path32) else None for drive in all_drives:
z_path64 = os.path.join(drive + "\\", "Program Files", "7-Zip", "7z.exe")
z_path32 = os.path.join(drive + "\\", "Program Files (x86)", "7-Zip", "7z.exe")
self.z_path = z_path64 if os.path.exists(z_path64) else z_path32 if os.path.exists(z_path32) else None
if self.z_path:
return True
return self.z_path and os.path.exists(self.z_path) return self.z_path and os.path.exists(self.z_path)
def check_bi(self): def check_bi(self):