From 93cfd13622799f494b608da6bc5720a1ba36f530 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sun, 21 Jan 2024 22:36:17 +0200 Subject: [PATCH] Added urllib configs --- configs/slpkg.toml | 8 ++++++++ slpkg/check_updates.py | 8 ++++++-- slpkg/configs.py | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/configs/slpkg.toml b/configs/slpkg.toml index 31d25acb..14fc8a18 100644 --- a/configs/slpkg.toml +++ b/configs/slpkg.toml @@ -114,6 +114,14 @@ LFTP_MIRROR_OPTIONS = "-c mirror --parallel=100 --only-newer" # from SBo and ponce repositories. LFTP_EXCLUDE = "-X SLACKBUILDS.TXT.gz -X CHECKSUMS.md5.asc -X 'TAGS.txt*' -X '*.tar.gz*'" +# Python urllib3 settings used for checking between two changelog files. +# Timeouts allow you to control how long (in seconds) requests are allowed +# to run before being aborted. In simple cases, you can specify a timeout as a float. +# By default, urllib3 will retry requests 3 times and follow up to 3 redirects. +URLLIB_RETRIES = false +URLLIB_REDIRECT = false +URLLIB_TIMEOUT = 3.0 + # If you are going to use a proxy server, try to fill in these variables. # Choose between http or socks proxy type. # For a sock proxy, you need to install the PySocks package. diff --git a/slpkg/check_updates.py b/slpkg/check_updates.py index 3194f748..1c8e6982 100644 --- a/slpkg/check_updates.py +++ b/slpkg/check_updates.py @@ -31,7 +31,7 @@ class CheckUpdates(Configs): self.compare: dict = {} - self.http = PoolManager() + self.http = PoolManager(timeout=self.urllib_timeout) self.proxy_default_headers = make_headers( proxy_basic_auth=f'{self.proxy_username}:{self.proxy_password}') @@ -107,7 +107,11 @@ class CheckUpdates(Configs): local_size: int = int(os.stat(local_chg_txt).st_size) try: # Get repository changelog file size. - repo = self.http.request('GET', repo_chg_txt) + repo = self.http.request( + 'GET', repo_chg_txt, + retries=self.urllib_retries, + redirect=self.urllib_redirect + ) repo_size: int = int(repo.headers.get('content-length', 0)) except KeyboardInterrupt: raise SystemExit(1) diff --git a/slpkg/configs.py b/slpkg/configs.py index d17851a0..79641e2f 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -3,6 +3,7 @@ import tomli import platform +from typing import Any from pathlib import Path from dataclasses import dataclass @@ -52,6 +53,10 @@ class Configs: case_sensitive: bool = True process_log: bool = True + urllib_retries: Any = False + urllib_redirect: Any = False + urllib_timeout: float = 3.0 + proxy_address: str = '' proxy_username: str = '' proxy_password: str = '' @@ -91,6 +96,11 @@ class Configs: border_color: str = config['BORDER_COLOR'] case_sensitive: bool = config['CASE_SENSITIVE'] process_log: bool = config['PROCESS_LOG'] + + urllib_retries: Any = config['URLLIB_RETRIES'] + urllib_redirect: Any = config['URLLIB_REDIRECT'] + urllib_timeout: float = config['URLLIB_TIMEOUT'] + proxy_address: str = config['PROXY_ADDRESS'] proxy_username: str = config['PROXY_USERNAME'] proxy_password: str = config['PROXY_PASSWORD']