Autoformat

This commit is contained in:
hhh
2024-05-27 17:12:21 +03:00
parent 0afca0dd67
commit 918d5af851
25 changed files with 358 additions and 378 deletions

View File

@@ -1,51 +1,51 @@
import os
import io
import tarfile
import requests
import os
import re
import sys
import tarfile
from typing import Literal
import requests
def get_latest_version() -> str:
"""
Gets latest non-alfa version name from dist.torproject.org
:return:
"""
r = requests.get('https://dist.torproject.org/torbrowser/').text
r = requests.get("https://dist.torproject.org/torbrowser/").text
results = re.findall(r'<a href=".+/">(.+)/</a>', r)
for res in results:
if 'a' not in res:
if "a" not in res:
return res
def get_build() -> Literal[
'windows-x86_64',
'linux-x86_64',
'macos-x86_64',
'macos-aarch64'
"windows-x86_64", "linux-x86_64", "macos-x86_64", "macos-aarch64"
]:
"""
Gets proper build name for your system
:return:
"""
if sys.platform == 'win32':
return 'windows-x86_64'
elif sys.platform == 'linux':
return 'linux-x86_64'
elif sys.platform == 'darwin':
if sys.platform == "win32":
return "windows-x86_64"
elif sys.platform == "linux":
return "linux-x86_64"
elif sys.platform == "darwin":
import platform
if platform.uname().machine == 'arm64':
return 'macos-aarch64'
if platform.uname().machine == "arm64":
return "macos-aarch64"
else:
return 'macos-x86_64'
return "macos-x86_64"
else:
raise 'System not supported'
raise "System not supported"
def get_tor_expert_bundles(version: str = get_latest_version(),
platform: str = get_build()):
def get_tor_expert_bundles(
version: str = get_latest_version(), platform: str = get_build()
):
"""
Returns a link for downloading tor expert bundle by version and platform
:param version: Tor expert bundle version that exists in dist.torproject.org
@@ -53,11 +53,13 @@ def get_tor_expert_bundles(version: str = get_latest_version(),
get_build()
:return:
"""
return f'https://dist.torproject.org/torbrowser/{version}/tor-expert-bundle-' \
f'{version}-{platform}.tar.gz'
return (
f"https://dist.torproject.org/torbrowser/{version}/tor-expert-bundle-"
f"{version}-{platform}.tar.gz"
)
def download_tor(url: str = get_tor_expert_bundles(), dist: str = 'tor'):
def download_tor(url: str = get_tor_expert_bundles(), dist: str = "tor"):
"""
Downloads tor from url and unpacks it to specified directory. Note, that
it doesn't unpack only tor executable to dist folder, but creates there
@@ -69,15 +71,15 @@ def download_tor(url: str = get_tor_expert_bundles(), dist: str = 'tor'):
if not os.path.exists(dist):
os.makedirs(dist)
(tar := tarfile.open(fileobj=io.BytesIO(requests.get(url).content),
mode='r:gz')).extractall(
(
tar := tarfile.open(fileobj=io.BytesIO(requests.get(url).content), mode="r:gz")
).extractall(
members=[
tarinfo
for tarinfo
in tar.getmembers()
if tarinfo.name.startswith("tor/")
], path=dist)
tarinfo for tarinfo in tar.getmembers() if tarinfo.name.startswith("tor/")
],
path=dist,
)
if __name__ == '__main__':
if __name__ == "__main__":
download_tor()