51
51
)
52
52
):
53
53
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
54
58
DRIVER_DIR = os .path .dirname (os .path .realpath (drivers .__file__ ))
55
59
LOCAL_PATH = "/usr/local/bin/" # On Mac and Linux systems
56
60
DEFAULT_CHROMEDRIVER_VERSION = "72.0.3626.69" # (If can't find LATEST_STABLE)
@@ -249,7 +253,7 @@ def main(override=None, intel_for_uc=None):
249
253
file_name = "chromedriver_mac64.zip"
250
254
elif "linux" in sys_plat :
251
255
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 :
253
257
file_name = "chromedriver_win32.zip" # Works for win32 / win_x64
254
258
if not get_latest and not get_v_latest and num_args < 4 :
255
259
get_latest = True
@@ -348,7 +352,7 @@ def main(override=None, intel_for_uc=None):
348
352
file_name = "geckodriver-%s-linux64.tar.gz" % use_version
349
353
else :
350
354
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 :
352
356
file_name = "geckodriver-%s-win64.zip" % use_version
353
357
else :
354
358
raise Exception (
@@ -546,6 +550,9 @@ def main(override=None, intel_for_uc=None):
546
550
if not os .path .exists (downloads_folder ):
547
551
os .makedirs (downloads_folder )
548
552
553
+ driver_name = None # The name of the driver executable
554
+ driver_contents = [] # The contents of the driver zip file
555
+
549
556
if headless_ie_exists :
550
557
headless_ie_file_path = os .path .join (
551
558
downloads_folder , headless_ie_file_name
@@ -641,10 +648,20 @@ def main(override=None, intel_for_uc=None):
641
648
zip_file_path = file_path
642
649
zip_ref = zipfile .ZipFile (zip_file_path , "r" )
643
650
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
+ ):
647
655
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 ]
648
665
# Remove existing version if exists
649
666
new_file = os .path .join (downloads_folder , str (f_name ))
650
667
if (
@@ -658,6 +675,8 @@ def main(override=None, intel_for_uc=None):
658
675
if "Driver" in new_file or "driver" in new_file :
659
676
if os .path .exists (new_file ):
660
677
os .remove (new_file ) # Technically the old file now
678
+ if driver_contents :
679
+ contents = driver_contents
661
680
print ("Extracting %s from %s ..." % (contents , file_name ))
662
681
if intel_for_uc and IS_ARM_MAC :
663
682
f_name = "uc_driver"
@@ -670,12 +689,30 @@ def main(override=None, intel_for_uc=None):
670
689
zipinfo .filename = "uc_driver"
671
690
zip_ref .extract (zipinfo , downloads_folder )
672
691
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
673
705
else :
674
706
zip_ref .extractall (downloads_folder )
675
707
zip_ref .close ()
676
708
os .remove (zip_file_path )
677
709
print ("%sUnzip Complete!%s\n " % (c2 , cr ))
678
710
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"
679
716
new_file = os .path .join (downloads_folder , str (f_name ))
680
717
pr_file = c3 + new_file + cr
681
718
print ("The file [%s] was saved to:\n %s\n " % (f_name , pr_file ))
0 commit comments