def _compare_current_version_and_latest_version_chrome_browser( self) -> Tuple[bool, str, str]: """Compares current version of chrome browser to latest version Returns: Tuple of bool, str and str is_browser_up_to_date (bool) : It true the browser is up to date. Defaults to False. current_version (str) : Current version of the browser. latest_version (str) : Latest version of the browser. """ is_browser_up_to_date: bool = False current_version: str = '' latest_version: str = '' current_version = self._get_current_version_chrome_browser_selenium() if not current_version: return is_browser_up_to_date, current_version, latest_version latest_version = self._get_latest_version_chrome_browser() if current_version == latest_version: is_browser_up_to_date = True message = f"Your existing chrome browser is up to date. current_version: {current_version} latest_version: {latest_version}" logger.info(message) return is_browser_up_to_date, current_version, latest_version
def _get_latest_version_safaridriver(self) -> str: """Gets latest safaridriver version Returns: str latest_version (str) : Latest version of safaridriver. """ latest_version: str = '' url = self.setting["SafariDriver"]["LinkLastRelease"] json_data = self.requests_getter.get_result_by_request(url=url) soup = BeautifulSoup(json_data, 'html.parser') for release in soup.findAll('td'): if 'safari' in release.text.lower(): latest_version = release.text.lower().split('safari ')[1] if not '.' in latest_version: latest_version = str(float(latest_version)) break if not latest_version: message = 'Could not determine latest version of safaridriver, maybe the site was changed' raise ValueError(message) logger.info(f'Latest version of safaridriver: {latest_version}') return latest_version
def _get_latest_previous_version_chromedriver_via_requests(self) -> str: """Gets previous latest chromedriver version Returns: str latest_version_previous (str) : Latest previous version of chromedriver. """ latest_version_previous: str = '' url = self.setting["ChromeDriver"]["LinkLastRelease"] json_data = self.requests_getter.get_result_by_request(url=url) latest_version = str(json_data) latest_version_main = latest_version.split(".", maxsplit=1)[0] latest_version_main_previous = int(latest_version_main) - 1 url = self.setting["ChromeDriver"][ "LinkLatestReleaseSpecificVersion"].format( latest_version_main_previous) json_data = self.requests_getter.get_result_by_request(url=url) latest_version_previous = str(json_data) logger.info( f'Latest previous version of chromedriver: {latest_version_previous}' ) return latest_version_previous
def _get_latest_previous_version_edgedriver_via_requests(self) -> str: """Gets previous latest edgedriver version Returns: str latest_version_previous (str) : Latest previous version of edgedriver. """ latest_previous_version: str = '' latest_version = super()._get_latest_version_driver() latest_version_main = int(latest_version.split('.', maxsplit=1)[0]) latest_previous_version_main = str(latest_version_main - 1) url = self.setting["EdgeDriver"]["LinkLatestReleaseSpecificVersion"] json_data = self.requests_getter.get_result_by_request(url=url) latest_previous_version = [ version for version in re.findall( self.setting["Program"]["wedriverVersionPattern"], json_data) if version.startswith(latest_previous_version_main) ][-1] logger.info( f'Latest previous version of edgedriver: {latest_previous_version}' ) return latest_previous_version
def _compare_current_version_and_latest_version_github( self) -> Tuple[bool, str, str]: """Compares current version of driver to latest version Returns: Tuple of bool, str and str is_driver_up_to_date (bool) : It true the driver is up to date. Defaults to False. current_version (str) : Current version of the driver. latest_version (str) : Latest version of the driver. """ is_driver_up_to_date: bool = False current_version: str = '' latest_version: str = '' current_version = self._get_current_version_driver() if not current_version: return is_driver_up_to_date, current_version, latest_version latest_version = self._get_latest_version_driver_github() if current_version == latest_version: is_driver_up_to_date = True message = ( f'Your existing {self.driver_name} is up to date.' f'current_version: {current_version} latest_version: {latest_version}' ) logger.info(message) return is_driver_up_to_date, current_version, latest_version
def _check_if_chrome_browser_is_up_to_date(self) -> None: """Сhecks for the latest version of chrome browser""" try: if platform.system() not in ['Darwin']: message = 'Chrome browser checking/updating is currently disabled for your OS. Please wait for the new releases.' logger.error(message) return is_browser_up_to_date, current_version, latest_version = self._compare_current_version_and_latest_version_chrome_browser( ) if not is_browser_up_to_date: self._get_latest_chrome_browser_for_current_os() is_browser_up_to_date, current_version, latest_version = self._compare_current_version_and_latest_version_chrome_browser( ) if not is_browser_up_to_date: message = f'Problem with updating chrome browser current_version: {current_version} latest_version: {latest_version}' logger.info(message) except (ValueError, FileNotFoundError): pass
def _get_latest_version_firefox_browser(self) -> str: """Gets latest firefox browser version Returns: str latest_version (str) : Latest version of firefox browser. Raises: Except: If unexpected error raised. """ latest_version : str = '' url = self.setting["FirefoxBrowser"]["LinkAllLatestReleases"] json_data = self.requests_getter.get_result_by_request(url=url) soup = BeautifulSoup(json_data, 'html.parser') latest_version = soup.findAll('html')[0].attrs.get('data-latest-firefox') logger.info(f'Latest version of firefox browser: {latest_version}') return latest_version
def _get_current_version_chrome_browser_selenium_via_terminal(self) -> str: """Gets current chrome browser version via command in terminal Returns: str browser_version (str) : Current chrome browser version. """ browser_version: str = '' browser_version_terminal: str = '' chromebrowser_path = self.setting["ChromeBrowser"]["Path"] if chromebrowser_path: logger.info( 'Trying to get current version of chrome browser via terminal') if platform.system() == 'Windows': for command in chromebrowser_path: with subprocess.Popen(command, stdout=subprocess.PIPE) as process: browser_version_terminal = process.communicate( )[0].decode('UTF-8') if 'invalid' not in browser_version_terminal.lower(): break elif platform.system() == 'Linux': with subprocess.Popen([chromebrowser_path, '--version'], stdout=subprocess.PIPE) as process: browser_version_terminal = process.communicate()[0].decode( 'UTF-8') elif platform.system() == 'Darwin': for path in chromebrowser_path: with subprocess.Popen([path, '--version'], stdout=subprocess.PIPE) as process: browser_version_terminal = process.communicate( )[0].decode('UTF-8') if 'no such file or directory' not in browser_version_terminal.lower( ): break find_string = re.findall( self.setting["Program"]["wedriverVersionPattern"], browser_version_terminal) browser_version = find_string[0] if len(find_string) > 0 else '' return browser_version
def _delete_current_driver_for_current_os(self) -> None: """Deletes specific driver from folder if parameter "upgrade" is True""" if Path(self.driver_path).exists(): logger.info( f'Deleted existing {self.driver_name} {self.driver_name}_path: {self.driver_path}' ) Path(self.driver_path).unlink()
def _get_latest_version_chrome_browser(self, no_messages: bool = False) -> str: """Gets latest chrome browser version Returns: str latest_version (str) : Latest version of chrome browser. """ latest_version: str = '' latest_stable_version_element: Any = '' url = self.setting["ChromeBrowser"]["LinkAllLatestRelease"] json_data = self.requests_getter.get_result_by_request(url=url) soup = BeautifulSoup(json_data, 'html.parser') elements_news = soup.findAll('div', attrs={'class': 'post'}) stable_channel_header_text = 'Stable Channel Update for Desktop' for news in elements_news: if stable_channel_header_text in news.text: current_os = platform.system().replace('Darwin', 'Mac') if not current_os.lower() in news.text.lower(): continue latest_stable_version_element = news.text break if not latest_stable_version_element: message = f'Could not determine latest stable channel post of Chrome Browser. Maybe the text "{stable_channel_header_text}" is changed' logger.error(message) message = 'Trying to determine latest stable channel post of Chrome Browser without OS detection' logger.info(message) latest_stable_version_element = [ news.text for news in elements_news if stable_channel_header_text in news.text ][0] if not latest_stable_version_element: return latest_version latest_version = re.findall( self.setting["Program"]["wedriverVersionPattern"], latest_stable_version_element)[0] if not no_messages: logger.info(f'Latest version of chrome browser: {latest_version}') return latest_version
def extract_all_zip_archive_with_specific_name( archive_path: str, out_path: str, filename: str, filename_replace: str, delete_archive: bool = True) -> None: """Extract all zip archive and replaces name for one of member Args: archive_path (str) : Path to specific archive. out_path (str) : Out path, where all members of archive will be gathered. filename (str) : Archive member whose name will be changed. filename_replace (str) : Specific name for replacing. delete_archive (bool) : Delete archive after unzip or not. Defaults to True. """ driver_folder_path = out_path + 'tmp' message = ( 'Created new safety directory for replacing' f'filename: {filename} filename_replace: {filename_replace}') logger.info(message) if os.path.exists(driver_folder_path): shutil.rmtree(driver_folder_path) parameters = dict(archive_path=archive_path, out_path=driver_folder_path, delete_archive=delete_archive) if archive_path.endswith('.tar.gz'): Extractor.extract_all_tar_gz_archive(**parameters) elif archive_path.endswith('.zip'): Extractor.extract_all_zip_archive(**parameters) else: message = f'Unknown archive format was specified archive_path: {archive_path}' raise UnknownArchiveFormatException(message) old_path = driver_folder_path + os.path.sep + filename new_path = driver_folder_path + os.path.sep + filename_replace os.rename(old_path, new_path) renamed_driver_path = out_path + filename_replace if Path(renamed_driver_path).exists(): Path(renamed_driver_path).unlink() copyfile(new_path, renamed_driver_path) if Path(driver_folder_path).exists(): shutil.rmtree(driver_folder_path)
def __check_all_input_parameteres() -> None: """Private function for checking all input parameters""" if not Path(_info.path).exists() and _info.path.endswith(os.path.sep): message = f"The specified path does not exist current path is: {_info.path}, trying to create this directory" logger.error(message) Path(_info.path).mkdir() logger.info( f'Successfully created new directory at path: {_info.path}') if not Path(_info.path).is_dir(): message = f"The specified path is not a directory current path is: {_info.path}" raise NotADirectoryError(message) if isinstance(_info.driver_name, (list, str)): if _info.filename: DriverUpdater.__check_parameter_type_is_valid( _info.filename, type(_info.driver_name), 'filename') if _info.system_name: DriverUpdater.__check_parameter_type_is_valid( _info.system_name, type(_info.driver_name), 'system_name') if _info.version: DriverUpdater.__check_parameter_type_is_valid( _info.version, type(_info.driver_name), 'version') if isinstance(_info.driver_name, str): if _info.system_name: DriverUpdater.__check_system_name_is_valid( system_name=_info.system_name) elif isinstance(_info.driver_name, list): if _info.system_name: for os_system in _info.system_name: DriverUpdater.__check_system_name_is_valid( system_name=os_system) else: message = f'The type of "driver_name" must be a list or str current type is: {type(_info.driver_name)}' raise ValueError(message)
def _get_current_version_opera_browser_selenium_via_terminal(self) -> str: """Gets current opera browser version via command in terminal Returns: str browser_version (str) : Current opera browser version. Raises: Except: If unexpected error raised. """ browser_version: str = '' browser_version_terminal: str = '' operabrowser_path = self.setting["OperaBrowser"]["Path"] if operabrowser_path: logger.info( 'Trying to get current version of opera browser via terminal') if platform.system() == 'Windows': with subprocess.Popen(operabrowser_path, stdout=subprocess.PIPE) as process: browser_version_terminal = process.communicate()[0].decode( 'UTF-8') find_string_terminal = re.findall("Opera.*", browser_version_terminal) browser_version_terminal = find_string_terminal[0] if len( find_string_terminal) > 0 else '' elif platform.system() == 'Darwin': with subprocess.Popen([operabrowser_path, '--version'], stdout=subprocess.PIPE) as process: browser_version_terminal = process.communicate()[0].decode( 'UTF-8') find_string = re.findall( self.setting["Program"]["wedriverVersionPattern"], browser_version_terminal) browser_version = find_string[0] if len(find_string) > 0 else '' return browser_version
def _chmod_driver(self) -> None: """Tries to give specific driver needed permissions""" if Path(self.driver_path).exists(): logger.info( f'Trying to give {self.driver_name} needed permissions') file_st = os.stat(self.driver_path) os.chmod(self.driver_path, file_st.st_mode | stat.S_IEXEC) logger.info( f'Needed rights for {self.driver_name} were successfully issued' )
def _get_latest_version_opera_browser(self) -> str: """Gets latest opera browser version Returns: str latest_version (str) : Latest version of opera browser. Raises: Except: If unexpected error raised. """ latest_version: str = '' version: str = '' url = self.setting["OperaBrowser"]["LinkAllLatestRelease"] json_data = self.requests_getter.get_result_by_request(url=url) soup = BeautifulSoup(json_data, 'html.parser') system_name = platform.system() system_name = system_name.replace('Darwin', 'mac') system_name = system_name.replace('Windows', 'win') self.system_name = system_name.lower( ) + '/' #mac -> mac/ or Linux -> linux/ elements = soup.findAll('a') for i, _ in enumerate(elements, 1): version = elements[-i].attrs.get('href') self.url_release = url + version json_data = self.requests_getter.get_result_by_request( url=self.url_release) if not self.system_name in json_data: continue else: break latest_version = version.replace('/', '') logger.info(f'Latest version of opera browser: {latest_version}') return latest_version
def _get_current_version_chrome_browser_selenium(self) -> str: """Gets current chrome browser version Returns: str browser_version (str) : Current chrome browser version. Raises: SessionNotCreatedException: Occurs when current chromedriver could not start. WebDriverException: Occurs when current chromedriver could not start or critical error occured. Except: If unexpected error raised. """ browser_version: str = '' try: browser_version = self._get_current_version_chrome_browser_selenium_via_terminal( ) if not browser_version: message = 'Trying to get current version of chrome browser via chromedriver' logger.info(message) if Path(self.chromedriver_path).exists() and not browser_version: chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--headless') with webdriver.Chrome(executable_path=self.chromedriver_path, options=chrome_options) as driver: browser_version = str( driver.capabilities['browserVersion']) logger.info( f'Current version of chrome browser: {browser_version}') except (WebDriverException, SessionNotCreatedException, OSError): pass #[Errno 86] Bad CPU type in executable: return browser_version
def _get_current_version_opera_browser_selenium(self) -> str: """Gets current opera browser version Returns: str browser_version (str) : Current opera browser version. Raises: SessionNotCreatedException: Occurs when current operadriver could not start. WebDriverException: Occurs when current operadriver could not start or critical error occured. """ browser_version: str = '' try: browser_version = self._get_current_version_opera_browser_selenium_via_terminal( ) if not browser_version: message = 'Trying to get current version of opera browser via operadriver' logger.info(message) if Path(self.operadriver_path).exists() and not browser_version: with webdriver.Opera( executable_path=self.operadriver_path) as driver: browser_version = driver.execute_script( "return navigator.userAgent") find_string = re.findall( 'OPR/' + self.setting["Program"]["wedriverVersionPattern"], browser_version) browser_version = find_string[0] if len( find_string) > 0 else '' logger.info(f'Current version of opera browser: {browser_version}') except (WebDriverException, SessionNotCreatedException, OSError): pass #[Errno 86] Bad CPU type in executable: return browser_version
def _get_current_version_firefox_browser_selenium_via_terminal(self) -> str: """Gets current firefox browser version via command in terminal Returns: str browser_version (str) : Current firefox browser version. Raises: Except: If unexpected error raised. """ browser_version : str = '' browser_version_terminal : str = '' firefox_path = self.setting["FirefoxBrowser"]["Path"] if firefox_path: logger.info('Trying to get current version of firefox browser via terminal') if platform.system() == 'Windows': for command in firefox_path: with subprocess.Popen(command, stdout=subprocess.PIPE) as process: browser_version_terminal = process.communicate()[0].decode('UTF-8') if 'invalid' not in browser_version_terminal.lower() or 'cannot find path' not in browser_version_terminal.lower(): break elif platform.system() == 'Darwin': with subprocess.Popen([firefox_path, '--version'], stdout=subprocess.PIPE) as process: browser_version_terminal = process.communicate()[0].decode('UTF-8') find_string = re.findall(self.setting["Program"]["wedriverVersionPattern"], browser_version_terminal) browser_version = find_string[0] if len(find_string) > 0 else '' return browser_version
def _compare_current_version_and_latest_version_safaridriver(self) -> None: """Compares current version of safaridriver to latest version""" current_version = super()._get_current_version_driver() latest_version = self._get_latest_version_safaridriver() if current_version == latest_version: message = ( 'Your existing safaridriver is up to date.' f'current_version: {current_version} latest_version: {latest_version}' ) logger.info(message) else: message = ( f'Your current version of safaridriver is not equal to latest verison. current_version: {current_version} latest_version: {latest_version}\n' 'Please update your browser.') logger.info(message)
def _get_latest_version_driver_github(self) -> str: """Gets latest driver version via github api / site Returns: str latest_version (str) : Latest version of driver """ latest_version: str = '' latest_version = self.github_viewer.get_release_version_by_repo_name( repo_name=self.repo_name) logger.info(f'Latest version of {self.driver_name}: {latest_version}') return latest_version
def _get_latest_version_phantomjs(self) -> str: """Gets latest phantomjs version Returns: str latest_version (str) : Latest version of phantomjs. """ latest_version: str = '' repo_name = PhantomJS._repo_name latest_version = self.github_viewer.get_latest_release_tag_by_repo_name( repo_name=repo_name) logger.info(f'Latest version of phantomjs: {latest_version}') return latest_version
def _check_if_chromedriver_is_up_to_date(self) -> str: """Сhecks for the latest version, downloads or updates chromedriver binary Returns: str driver_path (str) : Path where chromedriver was downloaded or updated. """ driver_path: str = '' if self.check_driver_is_up_to_date and not self.system_name: is_driver_up_to_date, current_version, latest_version = super( )._compare_current_version_and_latest_version() if is_driver_up_to_date: return self.chromedriver_path driver_path = self._download_driver() if self.check_driver_is_up_to_date and not self.system_name: is_driver_up_to_date, current_version, latest_version = super( )._compare_current_version_and_latest_version() if not is_driver_up_to_date: message = ( f'Problem with updating chromedriver' f'current_version: {current_version} latest_version: {latest_version}' ) logger.error(message) message = 'Trying to download previous latest version of chromedriver' logger.info(message) driver_path = self._download_driver(previous_version=True) return driver_path
def _get_latest_previous_version_operadriver_via_requests(self) -> str: """Gets previous latest operadriver version Returns: str latest_version_previous (str) : Latest previous version of operadriver. """ latest_previous_version: str = '' repo_name = OperaDriver._repo_name latest_previous_version = self.github_viewer.get_release_version_by_repo_name( repo_name=repo_name, index=1) logger.info( f'Latest previous version of operadriver: {latest_previous_version}' ) return latest_previous_version
def _get_current_version_firefox_browser_selenium(self) -> str: """Gets current firefox browser version Returns: str browser_version (str) : Current firefox browser version. Raises: SessionNotCreatedException: Occurs when current geckodriver could not start. WebDriverException: Occurs when current geckodriver could not start or critical error occured. """ browser_version : str = '' try: browser_version = self._get_current_version_firefox_browser_selenium_via_terminal() if not browser_version: message = 'Trying to get current version of firefox browser via geckodriver' logger.info(message) if Path(self.geckodriver_path).exists() and not browser_version: options = FirefoxOptions() options.add_argument("--headless") with webdriver.Firefox(executable_path = self.geckodriver_path, options=options) as driver: browser_version = str(driver.capabilities['browserVersion']) logger.info(f'Current version of firefox browser: {browser_version}') except (WebDriverException, SessionNotCreatedException, OSError): pass #[Errno 86] Bad CPU type in executable: return browser_version
def _get_current_version_driver(self) -> str: """Gets current driver version via command in terminal Returns: str driver_version (str) : Current driver version. Raises: OSError: Occurs when driver made for another CPU type """ driver_version: str = '' driver_version_terminal: str = '' try: if Path(self.driver_path).exists(): with subprocess.Popen([self.driver_path, '--version'], stdout=subprocess.PIPE) as process: driver_version_terminal = process.communicate()[0].decode( 'UTF-8') find_string = re.findall( self.setting["Program"]["wedriverVersionPattern"], driver_version_terminal) driver_version = find_string[0] if len(find_string) > 0 else '' logger.info( f'Current version of {self.driver_name}: {driver_version}') except OSError: pass #[Errno 86] Bad CPU type in executable: return driver_version
def _get_latest_version_driver(self, no_messages: bool = False) -> str: """Gets latest driver version Returns: str latest_version (str) : Latest version of specific driver. """ latest_version: str = '' url = self.setting[self.driver_name_setting]["LinkLastRelease"] json_data = self.requests_getter.get_result_by_request(url=url) latest_version = str(json_data).strip() if not no_messages: logger.info( f'Latest version of {self.driver_name}: {latest_version}') return latest_version
def _get_latest_previous_version_phantomjs_via_requests(self) -> str: """Gets previous latest phantomjs version Returns: str latest_version_previous (str) : Latest previous version of phantomjs. """ latest_previous_version: str = '' all_versions = [] url = self.setting["PhantomJS"]["LinkAllReleases"] json_data = self.requests_getter.get_result_by_request(url=url, is_json=True) values = json_data.get('values') for value in values: value_name = value.get('name') if not 'beta' in value_name: find_string = re.findall( self.setting["Program"]["wedriverVersionPattern"], value_name) version = find_string[0] if len(find_string) > 0 else '' all_versions.append(version) all_versions = list(set(all_versions)) all_versions.sort(key=lambda s: list(map(int, s.split('.')))) latest_previous_version = all_versions[len(all_versions) - 2] logger.info( f'Latest previous version of phantomjs: {latest_previous_version}') return latest_previous_version
def __check_library_is_up_to_date() -> None: """Private function for comparing latest version and current version of program""" url: str = str(setting["PyPi"]["urlProjectJson"]) if 'b' not in str(setting["Program"]["version"]).lower(): json_data = RequestsGetter.get_result_by_request(url=url, is_json=True) current_version = str(setting["Program"]["version"]) latest_version = json_data.get('info').get('version') current_version_tuple = tuple( map(int, (current_version.split(".")))) latest_version_tuple = tuple(map(int, (latest_version.split(".")))) if latest_version_tuple > current_version_tuple: message = ( 'Your selenium-driver-updater library is out of date,' 'please update it via "pip install selenium-driver-updater --upgrade" ' f'current_version: {current_version} latest_version: {latest_version} ' ) logger.warning(message) elif latest_version_tuple == current_version_tuple: message = 'Your selenium-driver-updater library is up to date.' logger.info(message) else: message = 'Unable to compare the latest version and the current version of the library.' logger.error(message) else: message = ( 'Thanks for participating in beta releases for selenium-driver-updater library,' f'you are using the beta version {str(setting["Program"]["version"])}' ) logger.info(message) message = 'Note that beta version does not guarantee errors avoiding. If something goes wrong - please create an issue on github repository' logger.info(message) message = 'Github repository link: https://github.com/Svinokur/selenium_driver_updater' logger.info(message)
def _download_driver(self, version: str = '', previous_version: bool = False) -> str: """Function to download, delete or upgrade current chromedriver Args: version (str) : Specific chromedriver version to download. Defaults to empty string. previous_version (boll) : If true, chromedriver latest previous version will be downloaded. Defaults to False. Returns: str driver_path (str) : Path to unzipped driver. """ url: str = '' latest_previous_version: str = '' latest_version: str = '' driver_path: str = '' if self.upgrade: super()._delete_current_driver_for_current_os() if version: url = self.setting["ChromeDriver"]["LinkLastReleaseFile"].format( version) logger.info( f'Started download chromedriver specific_version: {version}') elif previous_version: latest_previous_version = self._get_latest_previous_version_chromedriver_via_requests( ) url = self.setting["ChromeDriver"]["LinkLastReleaseFile"].format( latest_previous_version) logger.info( f'Started download chromedriver latest_previous_version: {latest_previous_version}' ) else: latest_version = super()._get_latest_version_driver() url = self.setting["ChromeDriver"]["LinkLastReleaseFile"].format( latest_version) logger.info( f'Started download chromedriver latest_version: {latest_version}' ) if self.system_name: url = url.replace(url.split("/")[-1], '') url = url + self.system_name logger.info( f'Started downloading chromedriver for specific system: {self.system_name}' ) if any([version, self.system_name, latest_previous_version]): super()._check_if_version_is_valid(url=url) archive_name = url.split("/")[-1] out_path = self.path + archive_name if Path(out_path).exists(): Path(out_path).unlink() logger.info(f'Started download chromedriver by url: {url}') if self.info_messages: archive_path = wget.download(url=url, out=out_path) else: archive_path = wget.download(url=url, out=out_path, bar=None) time.sleep(2) logger.info(f'Chromedriver was downloaded to path: {archive_path}') out_path: str = self.path parameters = dict(archive_path=archive_path, out_path=out_path) if not self.filename: self.extractor.extract_and_detect_archive_format(**parameters) else: filename = self.setting['ChromeDriver']['LastReleasePlatform'] parameters.update( dict(filename=filename, filename_replace=self.filename)) self.extractor.extract_all_zip_archive_with_specific_name( **parameters) if Path(archive_path).exists(): Path(archive_path).unlink() driver_path = self.chromedriver_path logger.info( f'Chromedriver was successfully unpacked by path: {driver_path}') if self.chmod: super()._chmod_driver() return driver_path
def _download_driver(self, version: str = '', previous_version: bool = False) -> str: """Function to download, delete or upgrade current operadriver Args: version (str) : Specific operadriver version to download. Defaults to empty string. previous_version (boll) : If true, operadriver latest previous version will be downloaded. Defaults to False. Returns: str driver_path (str) : Path to unzipped driver. """ url: str = '' latest_version: str = '' latest_previous_version: str = '' driver_path: str = '' if self.upgrade: super()._delete_current_driver_for_current_os() if version: url = self.setting["OperaDriver"][ "LinkLastReleasePlatform"].format(version, version) logger.info( f'Started download operadriver specific_version: {version}') elif previous_version: latest_previous_version = self._get_latest_previous_version_operadriver_via_requests( ) url = self.setting["OperaDriver"][ "LinkLastReleasePlatform"].format(latest_previous_version, latest_previous_version) logger.info( f'Started download operadriver latest_previous_version: {latest_previous_version}' ) else: latest_version = super()._get_latest_version_driver_github() url = self.setting["OperaDriver"][ "LinkLastReleasePlatform"].format(latest_version, latest_version) logger.info( f'Started download operadriver latest_version: {latest_version}' ) if self.system_name: url = url.replace(url.split("/")[-1], '') url = url + self.system_name logger.info( f'Started downloading operadriver for specific system: {self.system_name}' ) if any([version, self.system_name, latest_previous_version]): self._check_if_version_is_valid(url=url) archive_name = url.split("/")[-1] out_path = self.path + archive_name if Path(out_path).exists(): Path(out_path).unlink() logger.info(f'Started download operadriver by url: {url}') if self.info_messages: archive_path = wget.download(url=url, out=out_path) else: archive_path = wget.download(url=url, out=out_path, bar=None) logger.info(f'Operadriver was downloaded to path: {archive_path}') time.sleep(2) out_path = self.path self.extractor.extract_and_detect_archive_format( archive_path=archive_path, out_path=out_path) platform: str = self.setting['OperaDriver']['LastReleasePlatform'] archive_folder_path = self.path + Path(archive_path).stem + os.path.sep archive_operadriver_path = archive_folder_path + platform if not self.filename: copyfile(archive_operadriver_path, self.path + platform) else: self.__rename_driver( archive_folder_path=archive_folder_path, archive_operadriver_path=archive_operadriver_path) if Path(archive_path).exists(): Path(archive_path).unlink() if Path(archive_folder_path).exists(): shutil.rmtree(archive_folder_path) driver_path = self.operadriver_path logger.info( f'Operadriver was successfully unpacked by path: {driver_path}') if self.chmod: super()._chmod_driver() return driver_path