5151 )
5252):
5353 IS_ARM_MAC = True
54+ PLAT = sys .platform
55+ IS_WINDOWS = False
56+ if "win32" in PLAT or "win64" in PLAT or "x64" in PLAT or "x86" in PLAT :
57+ IS_WINDOWS = True
5458DRIVER_DIR = os .path .dirname (os .path .realpath (drivers .__file__ ))
5559LOCAL_PATH = "/usr/local/bin/" # On Mac and Linux systems
5660DEFAULT_CHROMEDRIVER_VERSION = "72.0.3626.69" # (If can't find LATEST_STABLE)
@@ -249,7 +253,7 @@ def main(override=None, intel_for_uc=None):
249253 file_name = "chromedriver_mac64.zip"
250254 elif "linux" in sys_plat :
251255 file_name = "chromedriver_linux64.zip"
252- elif "win32" in sys_plat or "win64" in sys_plat or "x64" in sys_plat :
256+ elif IS_WINDOWS :
253257 file_name = "chromedriver_win32.zip" # Works for win32 / win_x64
254258 if not get_latest and not get_v_latest and num_args < 4 :
255259 get_latest = True
@@ -348,7 +352,7 @@ def main(override=None, intel_for_uc=None):
348352 file_name = "geckodriver-%s-linux64.tar.gz" % use_version
349353 else :
350354 file_name = "geckodriver-%s-linux32.tar.gz" % use_version
351- elif "win32" in sys_plat or "win64" in sys_plat or "x64" in sys_plat :
355+ elif IS_WINDOWS :
352356 file_name = "geckodriver-%s-win64.zip" % use_version
353357 else :
354358 raise Exception (
@@ -546,6 +550,9 @@ def main(override=None, intel_for_uc=None):
546550 if not os .path .exists (downloads_folder ):
547551 os .makedirs (downloads_folder )
548552
553+ driver_name = None # The name of the driver executable
554+ driver_contents = [] # The contents of the driver zip file
555+
549556 if headless_ie_exists :
550557 headless_ie_file_path = os .path .join (
551558 downloads_folder , headless_ie_file_name
@@ -641,10 +648,20 @@ def main(override=None, intel_for_uc=None):
641648 zip_file_path = file_path
642649 zip_ref = zipfile .ZipFile (zip_file_path , "r" )
643650 contents = zip_ref .namelist ()
644- if len (contents ) == 1 :
645- if name == "operadriver" :
646- raise Exception ("Zip file for OperaDriver is missing content!" )
651+ if (
652+ len (contents ) >= 1
653+ and name in ["chromedriver" , "uc_driver" ]
654+ ):
647655 for f_name in contents :
656+ if (
657+ name == "chromedriver"
658+ and (
659+ f_name == "chromedriver"
660+ or f_name == "chromedriver.exe"
661+ )
662+ ):
663+ driver_name = f_name
664+ driver_contents = [driver_name ]
648665 # Remove existing version if exists
649666 new_file = os .path .join (downloads_folder , str (f_name ))
650667 if (
@@ -658,6 +675,8 @@ def main(override=None, intel_for_uc=None):
658675 if "Driver" in new_file or "driver" in new_file :
659676 if os .path .exists (new_file ):
660677 os .remove (new_file ) # Technically the old file now
678+ if driver_contents :
679+ contents = driver_contents
661680 print ("Extracting %s from %s ..." % (contents , file_name ))
662681 if intel_for_uc and IS_ARM_MAC :
663682 f_name = "uc_driver"
@@ -670,12 +689,30 @@ def main(override=None, intel_for_uc=None):
670689 zipinfo .filename = "uc_driver"
671690 zip_ref .extract (zipinfo , downloads_folder )
672691 contents = zip_ref .namelist ()
692+ if driver_contents :
693+ contents = driver_contents
694+ elif name == "chromedriver" :
695+ zipinfos = zip_ref .infolist ()
696+ for zipinfo in zipinfos :
697+ if (
698+ zipinfo .filename == "chromedriver"
699+ or zipinfo .filename == "chromedriver.exe"
700+ ):
701+ zip_ref .extract (zipinfo , downloads_folder )
702+ contents = zip_ref .namelist ()
703+ if driver_contents :
704+ contents = driver_contents
673705 else :
674706 zip_ref .extractall (downloads_folder )
675707 zip_ref .close ()
676708 os .remove (zip_file_path )
677709 print ("%sUnzip Complete!%s\n " % (c2 , cr ))
678710 for f_name in contents :
711+ if intel_for_uc :
712+ if IS_WINDOWS :
713+ f_name = "uc_driver.exe"
714+ else :
715+ f_name = "uc_driver"
679716 new_file = os .path .join (downloads_folder , str (f_name ))
680717 pr_file = c3 + new_file + cr
681718 print ("The file [%s] was saved to:\n %s\n " % (f_name , pr_file ))
0 commit comments