Updated for proxies support #160

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2023-04-13 12:29:08 +03:00
parent 9487398738
commit 4e2143ebc4
4 changed files with 34 additions and 2 deletions

View file

@ -1,6 +1,7 @@
4.7.8 - 12/04/203
Added:
- Module to support for Unix shell-style wildcards for blacklist (Thanks yo marav)
- Supports proxies (Thanks to tpiszcze) #160
Updated:
- Config file for --reinstall option (Thanks to rizitis)
- Improve speed

View file

@ -64,3 +64,12 @@ CURL_OPTIONS = ""
LFTP_GET_OPTIONS = "-c get -e"
# Lftp mirror options are used to synchronize with the repositories.
LFTP_MIRROR_OPTIONS = "-c mirror --parallel=100 --only-newer"
# If you are going to use a proxy server, try to fill in these variables.
# Choose between http or socks proxy type, not both.
# If you want to use a socks proxy, you need to install the PySocks package.
# https://urllib3.readthedocs.io/en/stable/advanced-usage.html#socks-proxies
HTTP_PROXY_ADDRESS = ""
SOCKS_PROXY_ADDRESS = ""
PROXY_USERNAME = ""
PROXY_PASSWORD = ""

View file

@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-
import os
import urllib3
from pathlib import Path
from multiprocessing import Process
from urllib3 import PoolManager, ProxyManager, make_headers
from slpkg.configs import Configs
from slpkg.utilities import Utilities
@ -168,7 +168,20 @@ class CheckUpdates(Configs):
def compare_dates(self) -> bool:
local_date: int = 0
try:
http = urllib3.PoolManager()
http = PoolManager()
proxy_default_headers = make_headers(proxy_basic_auth=f'{self.proxy_username}:{self.proxy_password}')
if self.http_proxy_address:
http = ProxyManager(f'{self.http_proxy_address}', headers=proxy_default_headers)
elif self.socks_proxy_address:
try:
from urllib3.contrib.socks import SOCKSProxyManager
except (ModuleNotFoundError, ImportError):
raise SystemExit()
http = SOCKSProxyManager(f'{self.socks_proxy_address}', headers=proxy_default_headers)
repo = http.request('GET', self.repo_chg_txt)
except KeyboardInterrupt:
raise SystemExit(1)

View file

@ -77,6 +77,11 @@ class Configs:
progress_spinner: str = 'pixel'
spinner_color: str = 'green'
http_proxy_address: str = ''
socks_proxy_address: str = ''
proxy_username: str = ''
proxy_password: str = ''
load = Load()
configs = load.config_file(etc_path, prog_name)
@ -104,6 +109,10 @@ class Configs:
file_pattern_conf: str = config['FILE_PATTERN']
progress_spinner: str = config['PROGRESS_SPINNER']
spinner_color: str = config['SPINNER_COLOR']
http_proxy_address: str = config['HTTP_PROXY_ADDRESS']
socks_proxy_address: str = config['SOCKS_PROXY_ADDRESS']
proxy_username: str = config['PROXY_USERNAME']
proxy_password: str = config['PROXY_PASSWORD']
except KeyError as error:
raise SystemExit(f"\n{prog_name}: {color['bold']}{color['red']}Error{color['endc']}: "