diff --git a/src/install/filesize.py b/src/install/filesize.py index b5e8be5..6fc8ff1 100644 --- a/src/install/filesize.py +++ b/src/install/filesize.py @@ -2,7 +2,9 @@ from typing import TypeAlias -traditional: list[tuple[int, str | tuple[str, str]]] = [ +SizeSystem: TypeAlias = list[tuple[int, str | tuple[str, str]]] + +traditional: SizeSystem = [ (1024 ** 5, 'P'), (1024 ** 4, 'T'), (1024 ** 3, 'G'), @@ -11,7 +13,7 @@ (1024 ** 0, 'B'), ] -alternative: list[tuple[int, str | tuple[str, str]]] = [ +alternative: SizeSystem = [ (1024 ** 5, ' PB'), (1024 ** 4, ' TB'), (1024 ** 3, ' GB'), @@ -20,7 +22,7 @@ (1024 ** 0, (' byte', ' bytes')), ] -verbose: list[tuple[int, str | tuple[str, str]]] = [ +verbose: SizeSystem = [ (1024 ** 5, (' petabyte', ' petabytes')), (1024 ** 4, (' terabyte', ' terabytes')), (1024 ** 3, (' gigabyte', ' gigabytes')), @@ -29,7 +31,7 @@ (1024 ** 0, (' byte', ' bytes')), ] -iec: list[tuple[int, str | tuple[str, str]]] = [ +iec: SizeSystem = [ (1024 ** 5, 'Pi'), (1024 ** 4, 'Ti'), (1024 ** 3, 'Gi'), @@ -38,7 +40,7 @@ (1024 ** 0, ''), ] -si: list[tuple[int, str | tuple[str, str]]] = [ +si: SizeSystem = [ (1000 ** 5, 'P'), (1000 ** 4, 'T'), (1000 ** 3, 'G'), @@ -47,10 +49,8 @@ (1000 ** 0, 'B'), ] -size_system: TypeAlias = list[tuple[int, str | tuple[str, str]]] - -def size(bytes: int, system: size_system) -> str: +def size(bytes: int, system: SizeSystem) -> str: """Human-readable file size. Using the traditional system, where a factor of 1024 is used:: diff --git a/src/install/media.py b/src/install/media.py index 380c823..4f09440 100644 --- a/src/install/media.py +++ b/src/install/media.py @@ -1,15 +1,18 @@ from os import path, get_terminal_size from tqdm import tqdm -from typing import Any +from typing import Any, TypeAlias from urllib import parse, request, error from install.headers import headers from install.url_generator import generate_url +MediaList: TypeAlias = list[dict[str, Any]] +Media: TypeAlias = dict[str, Any] -def prepare_media(total_size: int, install_path: str, mods: list[dict[str, Any]], resourcepacks: list[dict[str, Any]]) -> int: + +def prepare_media(total_size: int, install_path: str, mods: MediaList, resourcepacks: MediaList) -> int: """Get the file size and check media validity while listing all media""" - def check_media_validity(media_list: list[dict[str, Any]], media_type: str) -> None: + def check_media_validity(media_list: MediaList, media_type: str) -> None: """Check for the modpack file validity""" for media in media_list: for key in ['type', 'slug', 'name']: @@ -20,7 +23,7 @@ def check_media_validity(media_list: list[dict[str, Any]], media_type: str) -> N raise KeyError( f"The type '{media['type']}' does not exist: {media}.") - def get_headers(media: dict[str, Any], total_size: int) -> int: + def get_headers(media: Media, total_size: int) -> int: """Recieve the content-length headers""" try: size = int(request.urlopen( diff --git a/src/install/url_generator.py b/src/install/url_generator.py index bb628c9..3a76925 100644 --- a/src/install/url_generator.py +++ b/src/install/url_generator.py @@ -1,9 +1,11 @@ from os import path -from typing import Any +from typing import Any, TypeAlias from urllib import parse +Media: TypeAlias = dict[str, Any] -def generate_url(media: dict[str, Any], install_path: str, folder: str) -> tuple[str, tuple[str, str]]: + +def generate_url(media: Media, install_path: str, folder: str) -> tuple[str, tuple[str, str]]: """Generate an url to download""" match media['type']: diff --git a/src/main.py b/src/main.py index 70d1f47..684d4d1 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,14 @@ from json import load from os import path, get_terminal_size, mkdir from tqdm import tqdm -from typing import Any +from typing import Any, TypeAlias from install import filesize, media +MediaList: TypeAlias = list[dict[str, Any]] +Media: TypeAlias = dict[str, Any] -def download_files(total_size: int, install_path: str, mods: list[dict[str, Any]], resourcepacks: list[dict[str, Any]]): + +def download_files(total_size: int, install_path: str, mods: MediaList, resourcepacks: MediaList): """Download all files with a tqdm loading bar""" if not path.isdir(path.join(install_path, 'mods')): mkdir(path.join(install_path, 'mods')) @@ -80,6 +83,20 @@ def install(manifest_file: str, install_path: str = path.dirname(path.realpath(_ "slug": "(slug)", "name": "(filename)" } + ], + "resourcepacks": [ + { + "type": "(type)", + "slug": "(slug)", + "name": "(filename)" + } + ], + "shaderpacks": [ + { + "type": "(type)", + "slug": "(slug)", + "name": "(filename)" + } ] } ``` @@ -90,7 +107,7 @@ def install(manifest_file: str, install_path: str = path.dirname(path.realpath(_ # Import the manifest file with open(manifest_file) as json_file: - manifest: dict[str, Any] = load(json_file) + manifest: Media = load(json_file) # Check for validity if manifest.get('minecraft', None) is None: