@@ -97,26 +97,12 @@ def log_d(message):
97
97
print (message )
98
98
99
99
100
- def make_writable (file_path ):
101
- # Set permissions to: "If you can read it, you can write it."
102
- mode = os .stat (file_path ).st_mode
103
- mode |= (mode & 0o444 ) >> 1 # copy R bits to W
104
- os .chmod (file_path , mode )
105
-
106
-
107
- def make_executable (file_path ):
108
- # Set permissions to: "If you can read it, you can execute it."
109
- mode = os .stat (file_path ).st_mode
110
- mode |= (mode & 0o444 ) >> 2 # copy R bits to X
111
- os .chmod (file_path , mode )
112
-
113
-
114
100
def make_driver_executable_if_not (driver_path ):
115
101
# Verify driver has executable permissions. If not, add them.
116
102
permissions = oct (os .stat (driver_path )[0 ])[- 3 :]
117
103
if "4" in permissions or "6" in permissions :
118
104
# We want at least a '5' or '7' to make sure it's executable
119
- make_executable (driver_path )
105
+ shared_utils . make_executable (driver_path )
120
106
121
107
122
108
def extend_driver (driver ):
@@ -566,6 +552,10 @@ def uc_open_with_cdp_mode(driver, url=None):
566
552
for tab in driver .cdp_base .tabs [- 1 ::- 1 ]:
567
553
if "chrome-extension://" not in str (tab ):
568
554
with gui_lock :
555
+ with suppress (Exception ):
556
+ shared_utils .make_writable (
557
+ constants .MultiBrowser .PYAUTOGUILOCK
558
+ )
569
559
loop .run_until_complete (tab .activate ())
570
560
break
571
561
@@ -580,11 +570,17 @@ def uc_open_with_cdp_mode(driver, url=None):
580
570
if page_tab :
581
571
loop .run_until_complete (page_tab .aopen ())
582
572
with gui_lock :
573
+ with suppress (Exception ):
574
+ shared_utils .make_writable (
575
+ constants .MultiBrowser .PYAUTOGUILOCK
576
+ )
583
577
loop .run_until_complete (page_tab .activate ())
584
578
585
579
loop .run_until_complete (driver .cdp_base .update_targets ())
586
580
page = loop .run_until_complete (driver .cdp_base .get (url ))
587
581
with gui_lock :
582
+ with suppress (Exception ):
583
+ shared_utils .make_writable (constants .MultiBrowser .PYAUTOGUILOCK )
588
584
loop .run_until_complete (page .activate ())
589
585
loop .run_until_complete (page .wait ())
590
586
if not safe_url :
@@ -883,17 +879,12 @@ def install_pyautogui_if_missing(driver):
883
879
with pip_find_lock :
884
880
pass
885
881
except Exception :
886
- # Need write permissions
887
- with suppress (Exception ):
888
- make_writable (constants .PipInstall .FINDLOCK )
889
- try :
890
- with pip_find_lock :
891
- pass
892
- except Exception :
893
- # Since missing permissions, skip the locks
894
- __install_pyautogui_if_missing ()
895
- return
882
+ # Since missing permissions, skip the locks
883
+ __install_pyautogui_if_missing ()
884
+ return
896
885
with pip_find_lock : # Prevent issues with multiple processes
886
+ with suppress (Exception ):
887
+ shared_utils .make_writable (constants .PipInstall .FINDLOCK )
897
888
__install_pyautogui_if_missing ()
898
889
899
890
@@ -1789,6 +1780,8 @@ def _add_chrome_proxy_extension(
1789
1780
if zip_it :
1790
1781
proxy_zip_lock = fasteners .InterProcessLock (PROXY_ZIP_LOCK )
1791
1782
with proxy_zip_lock :
1783
+ with suppress (Exception ):
1784
+ shared_utils .make_writable (PROXY_ZIP_LOCK )
1792
1785
if multi_proxy :
1793
1786
_set_proxy_filenames ()
1794
1787
if not os .path .exists (proxy_helper .PROXY_ZIP_PATH ):
@@ -1800,6 +1793,8 @@ def _add_chrome_proxy_extension(
1800
1793
else :
1801
1794
proxy_dir_lock = fasteners .InterProcessLock (PROXY_DIR_LOCK )
1802
1795
with proxy_dir_lock :
1796
+ with suppress (Exception ):
1797
+ shared_utils .make_writable (PROXY_DIR_LOCK )
1803
1798
if multi_proxy :
1804
1799
_set_proxy_filenames ()
1805
1800
if not os .path .exists (proxy_helper .PROXY_DIR_PATH ):
@@ -1825,6 +1820,8 @@ def is_using_uc(undetectable, browser_name):
1825
1820
def _unzip_to_new_folder (zip_file , folder ):
1826
1821
proxy_dir_lock = fasteners .InterProcessLock (PROXY_DIR_LOCK )
1827
1822
with proxy_dir_lock :
1823
+ with suppress (Exception ):
1824
+ shared_utils .make_writable (PROXY_DIR_LOCK )
1828
1825
if not os .path .exists (folder ):
1829
1826
import zipfile
1830
1827
zip_ref = zipfile .ZipFile (zip_file , "r" )
@@ -2934,6 +2931,8 @@ def get_remote_driver(
2934
2931
constants .PipInstall .FINDLOCK
2935
2932
)
2936
2933
with pip_find_lock : # Prevent issues with multiple processes
2934
+ with suppress (Exception ):
2935
+ shared_utils .make_writable (constants .PipInstall .FINDLOCK )
2937
2936
try :
2938
2937
from seleniumwire import webdriver
2939
2938
import blinker
@@ -3371,6 +3370,8 @@ def get_local_driver(
3371
3370
constants .PipInstall .FINDLOCK
3372
3371
)
3373
3372
with pip_find_lock : # Prevent issues with multiple processes
3373
+ with suppress (Exception ):
3374
+ shared_utils .make_writable (constants .PipInstall .FINDLOCK )
3374
3375
try :
3375
3376
from seleniumwire import webdriver
3376
3377
import blinker
@@ -3434,6 +3435,10 @@ def get_local_driver(
3434
3435
constants .MultiBrowser .DRIVER_FIXING_LOCK
3435
3436
)
3436
3437
with geckodriver_fixing_lock :
3438
+ with suppress (Exception ):
3439
+ shared_utils .make_writable (
3440
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
3441
+ )
3437
3442
if not geckodriver_on_path ():
3438
3443
sys_args = sys .argv # Save a copy of sys args
3439
3444
log_d (
@@ -3736,6 +3741,10 @@ def get_local_driver(
3736
3741
constants .MultiBrowser .DRIVER_FIXING_LOCK
3737
3742
)
3738
3743
with edgedriver_fixing_lock :
3744
+ with suppress (Exception ):
3745
+ shared_utils .make_writable (
3746
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
3747
+ )
3739
3748
msg = "Microsoft Edge Driver not found."
3740
3749
if edgedriver_upgrade_needed :
3741
3750
msg = "Microsoft Edge Driver update needed."
@@ -4119,6 +4128,10 @@ def get_local_driver(
4119
4128
constants .MultiBrowser .DRIVER_FIXING_LOCK
4120
4129
)
4121
4130
with edgedriver_fixing_lock :
4131
+ with suppress (Exception ):
4132
+ shared_utils .make_writable (
4133
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
4134
+ )
4122
4135
with suppress (Exception ):
4123
4136
if not _was_driver_repaired ():
4124
4137
_repair_edgedriver (edge_version )
@@ -4501,6 +4514,10 @@ def get_local_driver(
4501
4514
constants .MultiBrowser .DRIVER_FIXING_LOCK
4502
4515
)
4503
4516
with chromedriver_fixing_lock :
4517
+ with suppress (Exception ):
4518
+ shared_utils .make_writable (
4519
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
4520
+ )
4504
4521
msg = "chromedriver update needed. Getting it now:"
4505
4522
if not path_chromedriver :
4506
4523
msg = "chromedriver not found. Getting it now:"
@@ -4592,6 +4609,10 @@ def get_local_driver(
4592
4609
constants .MultiBrowser .DRIVER_FIXING_LOCK
4593
4610
)
4594
4611
with uc_lock : # Avoid multithreaded issues
4612
+ with suppress (Exception ):
4613
+ shared_utils .make_writable (
4614
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
4615
+ )
4595
4616
if make_uc_driver_from_chromedriver :
4596
4617
if os .path .exists (LOCAL_CHROMEDRIVER ):
4597
4618
with suppress (Exception ):
@@ -4851,6 +4872,10 @@ def get_local_driver(
4851
4872
if not os .path .exists (cf_lock_path ):
4852
4873
# Avoid multithreaded issues
4853
4874
with cf_lock :
4875
+ with suppress (Exception ):
4876
+ shared_utils .make_writable (
4877
+ cf_lock_path
4878
+ )
4854
4879
# Install Python Certificates (MAC)
4855
4880
os .system (
4856
4881
r"bash /Applications/Python*/"
@@ -4994,6 +5019,10 @@ def get_local_driver(
4994
5019
constants .MultiBrowser .DRIVER_FIXING_LOCK
4995
5020
)
4996
5021
with chromedriver_fixing_lock :
5022
+ with suppress (Exception ):
5023
+ shared_utils .make_writable (
5024
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
5025
+ )
4997
5026
if not _was_driver_repaired ():
4998
5027
_repair_chromedriver (
4999
5028
chrome_options , headless_options , mcv
@@ -5192,7 +5221,10 @@ def get_local_driver(
5192
5221
chromedr_fixing_lock = fasteners .InterProcessLock (
5193
5222
constants .MultiBrowser .DRIVER_FIXING_LOCK
5194
5223
)
5224
+ D_F_L = constants .MultiBrowser .DRIVER_FIXING_LOCK
5195
5225
with chromedr_fixing_lock :
5226
+ with suppress (Exception ):
5227
+ shared_utils .make_writable (D_F_L )
5196
5228
if not _was_driver_repaired ():
5197
5229
with suppress (Exception ):
5198
5230
_repair_chromedriver (
0 commit comments