Skip to content

Commit

Permalink
see version 7.0.0 changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Svinokur committed Aug 14, 2024
1 parent 6b6637f commit edc42a9
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 125 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
## [7.0.0] - xx/08/2024
## [7.0.0] - 14/08/2024
This version was written and tested on Python 3.11.1

#### Added

- Added new command assosiation "selupd" for easier use
- Added automatic pypi release
- Added deleting of .tmp files when downloading is manually stopped (KeyboardInterrupt)
- Added driver-version argument to command line

#### Reworked

- Reworked the version parameter: It now accepts the channel version (beta, dev, canary) for chromedriver and edgedriver instead of a specific driver version.

#### Improvements

Expand All @@ -20,6 +25,7 @@ This version was written and tested on Python 3.11.1
- Fixed an issue with incorrect extracting of tar.gz archives when specific filename is present
- Fixed an issue with incorrect extracting of chromedriver with third_party_notice file
- Fixed an issues with browsers versions checking
- Fixed issues with system_name not working

#### Removed

Expand Down
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,46 @@ pip install selenium-driver-updater
```

## Usage in code
This example shows how you can use this library to download chromedriver binary and use it immediately.
This example shows how you can use this library to download chromedriver binary and use it immediately. The chromedriver will be downloaded to base directory.
```python
from selenium_driver_updater import DriverUpdater
from selenium import webdriver

filename = DriverUpdater.install(DriverUpdater.chromedriver)

driver = webdriver.Chrome(filename)
driver.get('https://google.com')

```

Or you can specify a path where you want to download a chromedriver to
```python
from selenium_driver_updater import DriverUpdater
from selenium import webdriver
import os

base_dir = os.path.dirname(os.path.abspath(__file__))

filename = DriverUpdater.install(path=base_dir, driver_name=DriverUpdater.chromedriver, upgrade=True, check_driver_is_up_to_date=True)
filename = DriverUpdater.install(path=base_dir, driver_name=DriverUpdater.chromedriver)

driver = webdriver.Chrome(filename)
driver.get('https://google.com')

```

Or you can use library to download and update chromedriver and geckodriver binaries at the same time.
You can also specify the version type (beta, dev, canary) you want to download.
```python
from selenium_driver_updater import DriverUpdater
from selenium import webdriver

filename = DriverUpdater.install(driver_name=DriverUpdater.chromedriver, version=DriverUpdater.chromedriver_beta)

driver = webdriver.Chrome(filename)
driver.get('https://google.com')

```

You can also use library to download and update chromedriver and geckodriver binaries at the same time.
```python
from selenium_driver_updater import DriverUpdater
from selenium import webdriver
Expand All @@ -43,7 +67,7 @@ import os
base_dir = os.path.dirname(os.path.abspath(__file__))
list_drivers = [DriverUpdater.chromedriver, DriverUpdater.geckodriver]

filenames = DriverUpdater.install(path=base_dir, driver_name=list_drivers, upgrade=True, check_driver_is_up_to_date=True)
filenames = DriverUpdater.install(path=base_dir, driver_name=list_drivers)
print(filenames)

driver_chrome = webdriver.Chrome(filename[0])
Expand All @@ -61,6 +85,12 @@ selenium-driver-updater --help
```
To see all available arguments and commands

Or you can use alias
```bash
selupd --help
```
for easier use

This example shows how you can use this console updater to download chromedriver to current dir
```bash
selenium-driver-updater -d chromedriver
Expand All @@ -76,7 +106,7 @@ selenium-driver-updater -d chromedriver,geckodriver
### ``Chromedriver``
#### ``DriverUpdater.chromedriver``

For installing or updating [chromedriver binary](https://chromedriver.chromium.org)
For installing or updating [chromedriver binary](https://developer.chrome.com/docs/chromedriver/)

All supported OS for this driver are:

Expand Down
58 changes: 20 additions & 38 deletions selenium_driver_updater/_chromeDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self, **kwargs):
specific_system = specific_system.replace('mac64_m1', 'mac-arm64')
specific_system = specific_system.replace('mac64', 'mac-x64')
if specific_system:
self.system_name = f"chromedriver_{specific_system}.zip"
self.system_name = f"chromedriver-{specific_system}.zip"
self.specific_system = specific_system

self.chromedriver_path = self.driver_path

Expand Down Expand Up @@ -70,39 +71,32 @@ def main(self) -> str:
driver_path = self._download_driver(previous_version=True)

else:

try:
if version.parse(self.version) < version.parse('115'):
message = 'Versions below 115 are not supported - aborting operation'
logger.error(message)
raise DriverVersionInvalidException(message)
except Exception:
raise DriverVersionInvalidException('Invalid version was provided, please check it')

driver_path = self._download_driver(version=self.version)

return driver_path

def _get_latest_version_driver(self, no_messages : bool = False) -> str:
"""Gets latest driver version
def _get_latest_version_driver(self, no_messages: bool = False) -> str:
"""Gets the latest driver version based on the specified channel.
Returns:
str
str: Latest version of the specific driver.
"""

latest_version (str) : Latest version of specific driver.
latest_version: str = ''

"""
channel_suffix = self.version.split('_')[1] if '_' in self.version else 'stable'

latest_version : str = ''
channel = channel_suffix.capitalize() # 'Beta', 'Dev', 'Canary'

url = self.setting["ChromeDriver"]["LinkLastRelease"]

url = self.setting[self.driver_name_setting]["LinkLastRelease"]
json_data = self.requests_getter.get_result_by_request(url=url, is_json=True)

latest_version = json_data.get('channels').get('Stable').get('version')
latest_version = json_data.get('channels', {}).get(channel, {}).get('version', '')

if not no_messages:

logger.info(f'Latest version of {self.driver_name}: {latest_version}')
logger.info(f'Latest version of chromedriver {self.version}: {latest_version}')

return latest_version

Expand Down Expand Up @@ -203,12 +197,7 @@ def _download_driver(self, version : str = '', previous_version : bool = False)

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:
if previous_version:

latest_previous_version = self._get_latest_previous_version_chromedriver_via_requests()

Expand All @@ -220,24 +209,17 @@ def _download_driver(self, version : str = '', previous_version : bool = False)
latest_version = self._get_latest_version_driver()

url = self.setting["ChromeDriver"]["LinkLastReleaseFile"].format(latest_version)
logger.info(f'Started download chromedriver latest_version: {latest_version}')
channel = 'stable' if '_' not in self.version else self.version.split('_')[1]
logger.info(f'Started download chromedriver {channel} latest_version: {latest_version}')

if self.system_name:
url = url.replace(url.split("/")[-1], '')
url = url + self.system_name

url = url.replace(url.split("/")[-1], self.system_name)
url = url.replace(url.split("/")[-2], self.specific_system)
logger.info(f'Started downloading chromedriver for specific system: {self.system_name}')

if any([version, self.system_name ,latest_previous_version]):
if 'mac_arm64' in url:
try:
super()._check_if_version_is_valid(url=url)
except Exception:
logger.warning('Could not find binary with mac_arm64 name, trying to check version using different name')
url = url.replace('mac_arm64', 'mac64_m1')
super()._check_if_version_is_valid(url=url)
else:
super()._check_if_version_is_valid(url=url)
super()._check_if_version_is_valid(url=url)

archive_name = url.split("/")[-1]
out_path = self.path + archive_name
Expand Down
13 changes: 6 additions & 7 deletions selenium_driver_updater/_edgeDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,23 @@ def _download_driver(self, version : str = '', previous_version : bool = False)

super()._delete_current_driver_for_current_os()

if version:

url = str(self.setting["EdgeDriver"]["LinkLastReleaseFile"]).format(version)
logger.info(f'Started download edgedriver specific_version: {version}')

elif previous_version:
if previous_version:

latest_previous_version = self._get_latest_previous_version_edgedriver_via_requests()

url = str(self.setting["EdgeDriver"]["LinkLastReleaseFile"]).format(latest_previous_version)
logger.info(f'Started download edgedriver latest_previous_version: {latest_previous_version}')

else:

if self.version:
self.setting["EdgeDriver"]["LinkLastRelease"] = self.setting["EdgeDriver"]["LinkLastRelease"].replace('STABLE', self.version.split('_')[1].upper())

latest_version = super()._get_latest_version_driver()

url = str(self.setting["EdgeDriver"]["LinkLastReleaseFile"]).format(latest_version)
logger.info(f'Started download edgedriver latest_version: {latest_version}')
channel = '' if '_' not in self.version else self.version.split('_')[1]
logger.info(f'Started download edgedriver {channel} latest_version: {latest_version}')

if self.system_name:
url = url.replace(url.split("/")[-1], '')
Expand Down
95 changes: 52 additions & 43 deletions selenium_driver_updater/consoleUpdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,68 @@ def parse_command_line():
description=description_text, formatter_class=argparse.RawTextHelpFormatter
)
parser.add_argument(
"--driver_name",
"-d",
type=ConsoleUpdater.comma_separated_string,
action="store",
dest="driver_name",
metavar="DRIVER_NAME",
help="Specified driver name/names which will be downloaded or updated, if you want to specify multiple drivers, use commas",
default='',
required=True,
"--driver_name",
"-d",
type=ConsoleUpdater.comma_separated_string,
action="store",
dest="driver_name",
metavar="DRIVER_NAME",
help="Specified driver name/names which will be downloaded or updated, if you want to specify multiple drivers, use commas",
default='',
required=True,
)
parser.add_argument(
"--path",
"-p",
action="store",
dest="path",
metavar="DIR",
help="Specified path which will used for downloading or updating Selenium driver binary. Must be folder path",
default='',
"--path",
"-p",
action="store",
dest="path",
metavar="DIR",
help="Specified path which will used for downloading or updating Selenium driver binary. Must be folder path",
default='',
)
parser.add_argument(
"--info_messages",
"-im",
action="store",
dest="info_messages",
metavar="BOOLEAN",
help="If false, it will disable all info messages",
default=True,
"--info_messages",
"-im",
action="store",
dest="info_messages",
metavar="BOOLEAN",
help="If false, it will disable all info messages",
default=True,
)
parser.add_argument(
"--filename",
type=ConsoleUpdater.comma_separated_string,
action="store",
dest="filename",
metavar="FILENAME",
help="Specific name for driver. If given, it will replace name for driver",
default='',
"--filename",
type=ConsoleUpdater.comma_separated_string,
action="store",
dest="filename",
metavar="FILENAME",
help="Specific name for driver. If given, it will replace name for driver",
default='',
)
parser.add_argument(
"--check_browser",
"-cb",
action="store",
dest="check_browser",
metavar="BOOLEAN",
help="If true, it will check browser version before specific driver update or upgrade",
default=False,
"--check_browser",
"-cb",
action="store",
dest="check_browser",
metavar="BOOLEAN",
help="If true, it will check browser version before specific driver update or upgrade",
default=False,
)
parser.add_argument(
"--system_name",
action="store",
dest="system_name",
metavar="SYSTEM_NAME",
help="Specific OS for driver",
default='',
"--system_name",
action="store",
dest="system_name",
metavar="SYSTEM_NAME",
help="Specific OS for driver",
default='',
)
parser.add_argument(
"--driver-version",
"-dv",
action="store",
dest="version",
metavar="DRIVER_VERSION",
help="Specific version for driver",
default='',
)
parser.add_argument("--version", action="version", version=str(setting["Program"]["version"]))
return parser.parse_args()
Expand Down
Loading

0 comments on commit edc42a9

Please sign in to comment.