get-chrome-driver 1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ __version__ = "1.4"
2
+
3
+ from get_chrome_driver.get_driver import GetChromeDriver
@@ -0,0 +1,241 @@
1
+ import typer
2
+
3
+ from get_chrome_driver import __version__
4
+ from get_chrome_driver.enums import Phase, OsPlatform
5
+ from get_chrome_driver.exceptions import GetChromeDriverError
6
+ from get_chrome_driver.get_driver import GetChromeDriver
7
+
8
+ app = typer.Typer(name="Get ChromeDriver", add_completion=False)
9
+
10
+
11
+ @app.command()
12
+ def main(
13
+ beta_version: bool = typer.Option(
14
+ default=False, help="Print the beta version", show_default=False
15
+ ),
16
+ stable_version: bool = typer.Option(
17
+ default=False, help="Print the stable version", show_default=False
18
+ ),
19
+ latest_urls: bool = typer.Option(
20
+ default=False,
21
+ help="print the beta and stable version download urls for all platforms",
22
+ show_default=False,
23
+ ),
24
+ version_url: str = typer.Option(
25
+ default=None, help="Print the version download url", show_default=False
26
+ ),
27
+ beta_url: bool = typer.Option(
28
+ default=False, help="Print the beta version download url", show_default=False
29
+ ),
30
+ stable_url: bool = typer.Option(
31
+ default=False, help="Print the stable version download url", show_default=False
32
+ ),
33
+ auto_download: bool = typer.Option(
34
+ default=False,
35
+ help="Download a ChromeDriver version for the installed Chrome Version",
36
+ show_default=False,
37
+ ),
38
+ download_beta: bool = typer.Option(
39
+ default=False, help="Download beta version", show_default=False
40
+ ),
41
+ download_stable: bool = typer.Option(
42
+ default=False, help="Download stable version", show_default=False
43
+ ),
44
+ download_version: str = typer.Option(
45
+ default=None, help="Download a specific version", show_default=False
46
+ ),
47
+ extract: bool = typer.Option(
48
+ default=False, help="Extract the compressed driver file", show_default=False
49
+ ),
50
+ version: bool = typer.Option(
51
+ default=False, help="Application version", show_default=False
52
+ ),
53
+ ):
54
+ """
55
+ Main.
56
+ """
57
+
58
+ if beta_version:
59
+ __print_latest_version(phase=Phase.beta)
60
+
61
+ elif stable_version:
62
+ __print_latest_version(phase=Phase.stable)
63
+
64
+ elif latest_urls:
65
+ __print_latest_urls()
66
+
67
+ elif version_url:
68
+ __print_version_url(version=version_url)
69
+
70
+ elif beta_url:
71
+ __print_latest_url(phase=Phase.beta)
72
+
73
+ elif stable_url:
74
+ __print_latest_url(phase=Phase.stable)
75
+
76
+ elif auto_download:
77
+ __auto_download(extract=extract)
78
+
79
+ elif download_beta:
80
+ __download_latest_version(phase=Phase.beta, extract=extract)
81
+
82
+ elif download_stable:
83
+ __download_latest_version(phase=Phase.stable, extract=extract)
84
+
85
+ elif download_version:
86
+ __download_version(version=download_version, extract=extract)
87
+
88
+ elif version:
89
+ print(f"v{__version__}")
90
+
91
+
92
+ def __print_latest_version(phase: Phase):
93
+ """
94
+ Print latest stable version or latest beta version.
95
+
96
+ :param phase: Stable or beta.
97
+ """
98
+
99
+ get_driver = GetChromeDriver()
100
+ error = "No latest version found"
101
+ if phase == Phase.beta:
102
+ try:
103
+ print(get_driver.beta_version())
104
+ except GetChromeDriverError:
105
+ print(error)
106
+ elif phase == Phase.stable:
107
+ try:
108
+ print(get_driver.stable_version())
109
+ except GetChromeDriverError:
110
+ print(error)
111
+ else:
112
+ print(error)
113
+
114
+
115
+ def __print_latest_urls():
116
+ """
117
+ Print the stable and beta url version for all platforms.
118
+ """
119
+
120
+ get_driver_win = GetChromeDriver(OsPlatform.win)
121
+ get_driver_linux = GetChromeDriver(OsPlatform.linux)
122
+ get_driver_mac = GetChromeDriver(OsPlatform.mac)
123
+ get_drivers = {
124
+ "Windows": get_driver_win,
125
+ "Linux": get_driver_linux,
126
+ "macOS": get_driver_mac,
127
+ }
128
+
129
+ result = ""
130
+ for index, (key, value) in enumerate(get_drivers.items()):
131
+ try:
132
+ result += f"Latest beta and stable version for {key}:\n"
133
+ result += f"stable : {value.stable_version_url()}\n"
134
+ result += f"beta : {value.beta_version_url()}"
135
+ if index < len(get_drivers) - 1:
136
+ result += "\n"
137
+ except GetChromeDriverError:
138
+ continue
139
+
140
+ print(result)
141
+
142
+
143
+ def __print_version_url(version: str):
144
+ """
145
+ Print the url of a version.
146
+
147
+ :param version: Chromedriver version.
148
+ """
149
+
150
+ get_driver = GetChromeDriver()
151
+
152
+ error = "Could not find version url"
153
+
154
+ try:
155
+ print(get_driver.version_url(version))
156
+ except GetChromeDriverError:
157
+ print(error)
158
+
159
+
160
+ def __print_latest_url(phase: Phase):
161
+ """
162
+ Print latest stable url or latest beta url.
163
+
164
+ :param phase: Stable or beta.
165
+ """
166
+
167
+ get_driver = GetChromeDriver()
168
+
169
+ error = "Could not find version url"
170
+
171
+ if phase == Phase.beta:
172
+ try:
173
+ print(get_driver.beta_version_url())
174
+ except GetChromeDriverError:
175
+ print(error)
176
+ elif phase == Phase.stable:
177
+ try:
178
+ print(get_driver.stable_version_url())
179
+ except GetChromeDriverError:
180
+ print(error)
181
+
182
+
183
+ def __auto_download(extract: bool):
184
+ """
185
+ Auto download driver.
186
+
187
+ :param extract: Extract the downloaded driver or not.
188
+ """
189
+
190
+ get_driver = GetChromeDriver()
191
+
192
+ try:
193
+ get_driver.auto_download(extract=extract)
194
+ print("Download finished")
195
+ except GetChromeDriverError:
196
+ print("An error occurred at downloading")
197
+
198
+
199
+ def __download_latest_version(phase: Phase, extract: bool):
200
+ """
201
+ Download the driver for the stable version or beta version.
202
+
203
+ :param phase: Stable or beta.
204
+ :param extract: Extract the downloaded driver or not.
205
+ """
206
+
207
+ get_driver = GetChromeDriver()
208
+
209
+ download_complete = "Download complete"
210
+ beta_error = "Could not download beta version"
211
+ stable_error = "Could not download stable version"
212
+
213
+ if phase == Phase.beta:
214
+ try:
215
+ get_driver.download_beta_version(extract=extract)
216
+ print(download_complete)
217
+ except GetChromeDriverError:
218
+ print(beta_error)
219
+ elif phase == Phase.stable:
220
+ try:
221
+ get_driver.download_stable_version(extract=extract)
222
+ print(download_complete)
223
+ except GetChromeDriverError:
224
+ print(stable_error)
225
+
226
+
227
+ def __download_version(version: str, extract: bool):
228
+ """
229
+ Download driver version.
230
+
231
+ :param version: Chromedriver version.
232
+ :param extract: Extract the downloaded driver or not.
233
+ """
234
+
235
+ get_driver = GetChromeDriver()
236
+
237
+ try:
238
+ get_driver.download_version(version=version, extract=extract)
239
+ print("Download finished")
240
+ except GetChromeDriverError:
241
+ print("Could not download version")
@@ -0,0 +1,10 @@
1
+ CHROMEDRIVER_STORAGE_URL = "https://chromedriver.storage.googleapis.com"
2
+ LAST_KNOWN_GOOD_VERSIONS_WITH_DOWNLOADS_URL = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json"
3
+ LAST_KNOWN_GOOD_VERSIONS_URL = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json"
4
+ KNOWN_GOOD_VERSIONS_WITH_DOWNLOADS_URL = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
5
+ KNOWN_GOOD_VERSIONS_URL = (
6
+ "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions.json"
7
+ )
8
+ CSS_SELECTOR_VERSIONS = "ul.n8H08c:nth-child(5)"
9
+ LATEST_STABLE_VERSION_STR = "Latest stable release"
10
+ LATEST_BETA_VERSION_STR = "Latest beta release"
@@ -0,0 +1,94 @@
1
+ import os
2
+ import requests
3
+ from urllib3.util.retry import Retry
4
+ from requests.adapters import HTTPAdapter
5
+ from urllib.parse import urlparse
6
+ from requests.exceptions import RequestException
7
+ from requests.exceptions import HTTPError
8
+
9
+
10
+ def download(url: str, output_path: str = None, file_name: str = None):
11
+ """
12
+ Download a file from url.
13
+ If output_path is None, the file will be downloaded directly at the current directory.
14
+ If file_name is None, the file name from the url will be used.
15
+ """
16
+
17
+ session = __retry_session(
18
+ retries=3,
19
+ backoff_factor=0.1,
20
+ status_forcelist=[429, 500, 502, 503, 504],
21
+ method_whitelist=["GET"],
22
+ )
23
+ try:
24
+ res = session.get(url=url)
25
+ except RequestException as err:
26
+ raise RequestException(err)
27
+ else:
28
+ if res.status_code != 200:
29
+ raise HTTPError("Invalid URL")
30
+
31
+ if file_name == "" or file_name is None:
32
+ # Get the file name from the url
33
+ file_name = __get_file_name_from_url(url)
34
+
35
+ if output_path == "" or output_path is None:
36
+ file_path = file_name
37
+ else:
38
+ __makedirs(output_path)
39
+ file_path = output_path + "/" + file_name
40
+
41
+ with open(file_path, "wb") as file:
42
+ # Download the file in chunks
43
+ for chunk in res.iter_content(chunk_size=1048576):
44
+ if chunk:
45
+ file.write(chunk)
46
+
47
+ return file_path, file_name
48
+ finally:
49
+ session.close()
50
+
51
+
52
+ def __retry_session(
53
+ retries: int, backoff_factor: float, status_forcelist: any, method_whitelist: any
54
+ ):
55
+ """
56
+ Retry session.
57
+ """
58
+
59
+ retry = Retry(
60
+ total=retries,
61
+ read=retries,
62
+ connect=retries,
63
+ backoff_factor=backoff_factor,
64
+ status_forcelist=status_forcelist,
65
+ allowed_methods=method_whitelist,
66
+ )
67
+
68
+ adapter = HTTPAdapter(max_retries=retry)
69
+ session = requests.Session()
70
+ session.mount("http://", adapter)
71
+ session.mount("https://", adapter)
72
+ return session
73
+
74
+
75
+ def __get_file_name_from_url(url: str):
76
+ """
77
+ Get file name from url.
78
+ """
79
+
80
+ path = urlparse(url).path
81
+
82
+ return path.split("/")[-1]
83
+
84
+
85
+ def __makedirs(path: str):
86
+ """
87
+ Make dirs.
88
+ """
89
+
90
+ try:
91
+ if not os.path.exists(path):
92
+ os.makedirs(path, exist_ok=True)
93
+ except OSError as err:
94
+ raise OSError(err)
@@ -0,0 +1,3 @@
1
+ from .os_platform import OsPlatform
2
+ from .phase import Phase
3
+ from .platform import Platform
@@ -0,0 +1,7 @@
1
+ from enum import Enum
2
+
3
+
4
+ class OsPlatform(Enum):
5
+ win = "win"
6
+ linux = "linux"
7
+ mac = "mac"
@@ -0,0 +1,6 @@
1
+ from enum import Enum
2
+
3
+
4
+ class Phase(Enum):
5
+ stable = "stable"
6
+ beta = "beta"
@@ -0,0 +1,12 @@
1
+ from enum import Enum
2
+
3
+
4
+ class Platform(Enum):
5
+ win32 = "win32"
6
+ win64 = "win64"
7
+ linux32 = "linux32"
8
+ linux64 = "linux64"
9
+ mac32 = "mac32"
10
+ mac64 = "mac64"
11
+ mac_arm64 = "mac-arm64"
12
+ mac_x64 = "mac-x64"
@@ -0,0 +1,22 @@
1
+ class GetChromeDriverError(Exception):
2
+ pass
3
+
4
+
5
+ class VersionUrlError(GetChromeDriverError):
6
+ pass
7
+
8
+
9
+ class UnknownPlatformError(GetChromeDriverError):
10
+ pass
11
+
12
+
13
+ class UnknownVersionError(GetChromeDriverError):
14
+ pass
15
+
16
+
17
+ class DownloadError(GetChromeDriverError):
18
+ pass
19
+
20
+
21
+ class VersionError(GetChromeDriverError):
22
+ pass