Skip to content

Commit

Permalink
see version 1.8.0 changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
stasvinokur committed Apr 26, 2021
1 parent d9d4de9 commit fe4e3c5
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 316 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ selenium_driver_updater/__pycache__/*.pyc
selenium_driver_updater/test/__pycache__/*.pyc
.DS_Store
selenium_driver_updater/*.log
selenium_driver_updater/util/__pycache__/*.pyc
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[1.8.0] 26/04/2021
This version provides minor fixes.
This code was written and tested on Python 3.9.4

# Improvements

- Improved functions decomposition.

[1.7.1] 26/04/2021
This version provides minor fixes.
This code was written and tested on Python 3.9.4
Expand Down
95 changes: 30 additions & 65 deletions selenium_driver_updater/chromeDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import traceback
import logging
import zipfile
import time
import stat
import os
Expand All @@ -23,9 +22,7 @@
from selenium.common.exceptions import SessionNotCreatedException
from selenium.common.exceptions import WebDriverException

from shutil import copyfile

import shutil
from util.extractor import Extractor

class ChromeDriver():

Expand Down Expand Up @@ -73,6 +70,8 @@ def __init__(self, path : str, upgrade : bool, chmod : bool, check_driver_is_up_

self.version = version

self.extractor = Extractor

def __get_latest_version_chrome_driver(self) -> Tuple[bool, str, str]:
"""Gets latest chromedriver version
Expand Down Expand Up @@ -182,14 +181,24 @@ def __get_latest_chromedriver_for_current_os(self, latest_version : str) -> Tupl
time.sleep(2)

if not self.filename:

with zipfile.ZipFile(file_name, 'r') as zip_ref:
zip_ref.extractall(self.path)

archive_path = file_name
out_path = self.path
result, message = self.extractor.extract_all_zip_archive(archive_path=archive_path, out_path=out_path)
if not result:
logging.error(message)
return result, message, file_name

else:

result, message = self.__rename_driver(file_name=file_name)
archive_path = file_name
out_path = self.path
filename = setting['ChromeDriver']['LastReleasePlatform']
filename_replace = self.filename
result, message = self.extractor.extract_all_zip_archive_with_specific_name(archive_path=archive_path,
out_path=out_path, filename=filename, filename_replace=filename_replace)
if not result:
logging.error(message)
return result, message, file_name

time.sleep(3)
Expand All @@ -205,7 +214,6 @@ def __get_latest_chromedriver_for_current_os(self, latest_version : str) -> Tupl
result_run = True

except:

message_run = f'Unexcepted error: {str(traceback.format_exc())}'
logging.error(message_run)

Expand Down Expand Up @@ -388,59 +396,6 @@ def __compare_current_version_and_latest_version(self) -> Tuple[bool, str, bool,

return result_run, message_run, is_driver_up_to_date, current_version, latest_version

def __rename_driver(self, file_name : str) -> Tuple[bool, str]:
"""Renames chromedriver if it was given
Args:
file_name (str) : Path to the chromedriver
Returns:
Tuple of bool, str and bool
result_run (bool) : True if function passed correctly, False otherwise.
message_run (str) : Empty string if function passed correctly, non-empty string if error.
Raises:
Except: If unexpected error raised.
"""
result_run : bool = False
message_run : str = ''
renamed_driver_path : str = ''

try:

driver_folder_path = self.path + ChromeDriver._tmp_folder_path
logging.info(f'Created new directory for replacing name for chromedriver path: {driver_folder_path}')

if os.path.exists(driver_folder_path):
shutil.rmtree(driver_folder_path)

with zipfile.ZipFile(file_name, 'r') as zip_ref:
zip_ref.extractall(driver_folder_path)

old_chromedriver_path = driver_folder_path + os.path.sep + setting['ChromeDriver']['LastReleasePlatform']
new_chromedriver_path = driver_folder_path + os.path.sep + self.filename

os.rename(old_chromedriver_path, new_chromedriver_path)

renamed_driver_path = self.path + self.filename
if os.path.exists(renamed_driver_path):
os.remove(renamed_driver_path)

copyfile(new_chromedriver_path, renamed_driver_path)

if os.path.exists(driver_folder_path):
shutil.rmtree(driver_folder_path)

result_run = True

except:
message_run = f'Unexcepted error: {str(traceback.format_exc())}'
logging.error(message_run)

return result_run, message_run

def __chmod_driver(self) -> Tuple[bool, str]:
"""Tries to give chromedriver needed permissions
Expand Down Expand Up @@ -617,13 +572,23 @@ def __get_specific_version_chromedriver_for_current_os(self, version : str) -> T

if not self.filename:

with zipfile.ZipFile(file_name, 'r') as zip_ref:
zip_ref.extractall(self.path)
archive_path = file_name
out_path = self.path
result, message = self.extractor.extract_all_zip_archive(archive_path=archive_path, out_path=out_path)
if not result:
logging.error(message)
return result, message, file_name

else:

result, message = self.__rename_driver(file_name=file_name)
archive_path = file_name
out_path = self.path
filename = setting['ChromeDriver']['LastReleasePlatform']
filename_replace = self.filename
result, message = self.extractor.extract_all_zip_archive_with_specific_name(archive_path=archive_path,
out_path=out_path, filename=filename, filename_replace=filename_replace)
if not result:
logging.error(message)
return result, message, file_name

time.sleep(3)
Expand Down
94 changes: 32 additions & 62 deletions selenium_driver_updater/edgeDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@

import stat

import zipfile

from shutil import copyfile
from util.extractor import Extractor

class EdgeDriver():

Expand Down Expand Up @@ -76,6 +74,8 @@ def __init__(self, path : str, upgrade : bool, chmod : bool, check_driver_is_up_

self.version = version

self.extractor = Extractor

def __get_current_version_edgedriver_selenium(self) -> Tuple[bool, str, str]:
"""Gets current edgedriver version
Expand Down Expand Up @@ -258,13 +258,25 @@ def __get_latest_edgedriver_for_current_os(self, latest_version : str) -> Tuple[

if not self.filename:

with zipfile.ZipFile(file_name, 'r') as zip_ref:
zip_ref.extractall(self.path)
archive_path = file_name
out_path = self.path

result, message = self.extractor.extract_all_zip_archive(archive_path=archive_path, out_path=out_path)
if not result:
logging.error(message)
return result, message, file_name

else:

result, message = self.__rename_driver(file_name=file_name)
archive_path = file_name
out_path = self.path
filename = setting['EdgeDriver']['LastReleasePlatform']
filename_replace = self.filename

result, message = self.extractor.extract_all_zip_archive_with_specific_name(archive_path=archive_path,
out_path=out_path, filename=filename, filename_replace=filename_replace)
if not result:
logging.error(message)
return result, message, file_name

time.sleep(3)
Expand Down Expand Up @@ -405,59 +417,6 @@ def __compare_current_version_and_latest_version(self) -> Tuple[bool, str, bool,

return result_run, message_run, is_driver_up_to_date, current_version, latest_version

def __rename_driver(self, file_name : str) -> Tuple[bool, str]:
"""Renames edgedriver if it was given
Args:
file_name (str) : Path to the edgedriver
Returns:
Tuple of bool, str and bool
result_run (bool) : True if function passed correctly, False otherwise.
message_run (str) : Empty string if function passed correctly, non-empty string if error.
Raises:
Except: If unexpected error raised.
"""
result_run : bool = False
message_run : str = ''
renamed_driver_path : str = ''

try:

driver_folder_path = self.path + EdgeDriver._tmp_folder_path
logging.info(f'Created new directory for replacing name for edgedriver path: {driver_folder_path}')

if os.path.exists(driver_folder_path):
shutil.rmtree(driver_folder_path)

with zipfile.ZipFile(file_name, 'r') as zip_ref:
zip_ref.extractall(driver_folder_path)

old_edgedriver_path = driver_folder_path + os.path.sep + setting['EdgeDriver']['LastReleasePlatform']
new_edgedriver_path = driver_folder_path + os.path.sep + self.filename

os.rename(old_edgedriver_path, new_edgedriver_path)

renamed_driver_path = self.path + self.filename
if os.path.exists(renamed_driver_path):
os.remove(renamed_driver_path)

copyfile(new_edgedriver_path, renamed_driver_path)

if os.path.exists(driver_folder_path):
shutil.rmtree(driver_folder_path)

result_run = True

except:
message_run = f'Unexcepted error: {str(traceback.format_exc())}'
logging.error(message_run)

return result_run, message_run

def __chmod_driver(self) -> Tuple[bool, str]:
"""Tries to give edgedriver needed permissions
Expand Down Expand Up @@ -629,13 +588,24 @@ def __get_specific_version_edgedriver_for_current_os(self, version : str) -> Tup

if not self.filename:

with zipfile.ZipFile(file_name, 'r') as zip_ref:
zip_ref.extractall(self.path)
archive_path = file_name
out_path = self.path
result, message = self.extractor.extract_all_zip_archive(archive_path=archive_path, out_path=out_path)
if not result:
logging.error(message)
return result, message, file_name

else:

result, message = self.__rename_driver(file_name=file_name)
archive_path = file_name
out_path = self.path
filename = setting['EdgeDriver']['LastReleasePlatform']
filename_replace = self.filename

result, message = self.extractor.extract_all_zip_archive_with_specific_name(archive_path=archive_path,
out_path=out_path, filename=filename, filename_replace=filename_replace)
if not result:
logging.error(message)
return result, message, file_name

time.sleep(3)
Expand Down
Loading

0 comments on commit fe4e3c5

Please sign in to comment.