Abort if Chromedriver patch fails

This commit is contained in:
Asthowen 2024-07-18 00:52:22 +02:00
parent 009e38185f
commit dbca4946c6
No known key found for this signature in database
GPG Key ID: CE65EDE6BA443255
2 changed files with 15 additions and 9 deletions

View File

@ -256,7 +256,9 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
user_multi_procs=user_multi_procs, user_multi_procs=user_multi_procs,
) )
# self.patcher.auto(user_multiprocess = user_multi_num_procs) # self.patcher.auto(user_multiprocess = user_multi_num_procs)
self.patcher.auto() if not self.patcher.auto():
logging.error("Unable to patch chromedriver.")
sys.exit(1)
# self.patcher = patcher # self.patcher = patcher
if not options: if not options:

View File

@ -182,19 +182,19 @@ class Patcher(object):
if not chromedriver_path or not os.path.isfile(chromedriver_path): if not chromedriver_path or not os.path.isfile(chromedriver_path):
logging.error("Chromedriver not installed!") logging.error("Chromedriver not installed!")
return return False
if not os.access(chromedriver_path, os.X_OK): if not os.access(chromedriver_path, os.X_OK):
logging.error( logging.error(
f"Execution permissions are not granted for the file {chromedriver_path}.", f"Execution permissions are not granted for the file {chromedriver_path}.",
) )
return return False
destination_path = os.path.dirname(self.executable_path) destination_path = os.path.dirname(self.executable_path)
if not os.access(destination_path, os.R_OK | os.W_OK | os.X_OK): if not os.access(destination_path, os.R_OK | os.W_OK | os.X_OK):
logging.error( logging.error(
f"Read/write/execution permissions are not granted for the folder {destination_path}.", f"Read/write/execution permissions are not granted for the folder {destination_path}.",
) )
return return False
try: try:
process = os.popen(f'"{chromedriver_path}" --version') process = os.popen(f'"{chromedriver_path}" --version')
@ -202,18 +202,22 @@ class Patcher(object):
process.close() process.close()
except Exception as e: except Exception as e:
logging.error(f"Failed to retrieve chromedriver version: {str(e)}") logging.error(f"Failed to retrieve chromedriver version: {str(e)}")
return return False
version_path = os.path.join(destination_path, "version.txt") version_path = os.path.join(destination_path, "version.txt")
current_version = None current_version = None
if os.path.isfile(version_path): if os.path.isfile(version_path) and os.path.isfile(self.executable_path):
if not os.access(version_path, os.W_OK): if not os.access(version_path, os.R_OK | os.W_OK):
logging.error(f"Write permissions are not granted for the file {version_path}.") logging.error(f"Read/write permissions are not granted for the file {version_path}.")
return return False
with open(version_path, 'r') as f: with open(version_path, 'r') as f:
current_version = f.read() current_version = f.read()
if current_version == chromedriver_version: if current_version == chromedriver_version:
if not os.access(self.executable_path, os.R_OK | os.W_OK | os.X_OK):
logging.error(f"Read/write/execution permissions are not granted for the file {self.executable_path}.")
return False
logging.info(f"The patched version of chromedriver in {destination_path} is the latest version on the system ({current_version}).") logging.info(f"The patched version of chromedriver in {destination_path} is the latest version on the system ({current_version}).")
if self.is_binary_patched(): if self.is_binary_patched():
return True return True