mesaport.Installer.choice
1import os 2 3from rich import print, prompt 4 5from . import mesaurls 6 7def choose_directory(directory=''): 8 """Choose a directory to install MESA. 9 10 Args: 11 directory (str, optional): 12 Path to a directory to install MESA and MESA SDK. CLI is used to choose directory if not specified. 13 14 Returns: 15 str: Path to a directory to install MESA and MESA SDK. 16 """ 17 if directory == '': 18 directory = prompt.Prompt.ask("\n[bold cyan]Input path to a directory for installation[/bold cyan]") 19 while not os.path.exists(directory): 20 print("[red]Directory does not exist. Please try again.[/red]") 21 if prompt.Confirm.ask("\n[cyan]Would you like to create the directory?[/cyan]"): 22 os.mkdir(directory) 23 directory = prompt.Prompt.ask("\n[bold cyan]Input path to a directory for installation[/bold cyan]") 24 software_directory = os.path.abspath(os.path.join(directory, "software")) 25 print(f"MESA will be installed at path: [green]{software_directory}[/green]\n") 26 if not os.path.exists(software_directory): 27 os.mkdir(software_directory) 28 return software_directory 29 30 31 32def choose_ver(ostype, ver=''): 33 """Choose a version of MESA to install. 34 35 Args: 36 ver (str, optional): 37 Version of MESA to install. CLI is used to choose version if not specified. 38 39 Returns: 40 str: Version of MESA to install. 41 """ 42 if ostype == "Linux": 43 versions = mesaurls.linux_versions 44 elif ostype == "macOS-Intel": 45 versions = mesaurls.mac_intel_versions 46 elif ostype == "macOS-ARM": 47 versions = mesaurls.mac_arm_versions 48 while ver not in versions: 49 print("Versions available for your system through this insaller are:") 50 print(versions, '\n') 51 ver = prompt.Prompt.ask("[bold cyan]Input the version of MESA to install[/bold cyan]") 52 if ver not in versions: 53 print("[red]Version not recognised, try again.[/red]\n") 54 55 if ostype == "Linux": 56 sdk = mesaurls.linux_sdk_urls.get(ver).split('-')[-1][:-7] 57 elif ostype == "macOS-Intel": 58 sdk = mesaurls.mac_intel_sdk_urls.get(ver).split('-')[-1][:-4] 59 elif ostype == "macOS-ARM": 60 sdk = mesaurls.mac_arm_sdk_urls.get(ver).split('-')[-1][:-4] 61 mesa = mesaurls.mesa_urls.get(ver).split('/')[-1].split('r')[-1][:-4] 62 print("The following will be installed:") 63 print(f"MESA SDK version: [green b]{sdk}[/green b]") 64 print(f"MESA version: [green b]{mesa}[/green b]\n") 65 return ver
def
choose_directory(directory=''):
8def choose_directory(directory=''): 9 """Choose a directory to install MESA. 10 11 Args: 12 directory (str, optional): 13 Path to a directory to install MESA and MESA SDK. CLI is used to choose directory if not specified. 14 15 Returns: 16 str: Path to a directory to install MESA and MESA SDK. 17 """ 18 if directory == '': 19 directory = prompt.Prompt.ask("\n[bold cyan]Input path to a directory for installation[/bold cyan]") 20 while not os.path.exists(directory): 21 print("[red]Directory does not exist. Please try again.[/red]") 22 if prompt.Confirm.ask("\n[cyan]Would you like to create the directory?[/cyan]"): 23 os.mkdir(directory) 24 directory = prompt.Prompt.ask("\n[bold cyan]Input path to a directory for installation[/bold cyan]") 25 software_directory = os.path.abspath(os.path.join(directory, "software")) 26 print(f"MESA will be installed at path: [green]{software_directory}[/green]\n") 27 if not os.path.exists(software_directory): 28 os.mkdir(software_directory) 29 return software_directory
Choose a directory to install MESA.
Arguments:
- directory (str, optional):
- Path to a directory to install MESA and MESA SDK. CLI is used to choose directory if not specified.
Returns:
str: Path to a directory to install MESA and MESA SDK.
def
choose_ver(ostype, ver=''):
33def choose_ver(ostype, ver=''): 34 """Choose a version of MESA to install. 35 36 Args: 37 ver (str, optional): 38 Version of MESA to install. CLI is used to choose version if not specified. 39 40 Returns: 41 str: Version of MESA to install. 42 """ 43 if ostype == "Linux": 44 versions = mesaurls.linux_versions 45 elif ostype == "macOS-Intel": 46 versions = mesaurls.mac_intel_versions 47 elif ostype == "macOS-ARM": 48 versions = mesaurls.mac_arm_versions 49 while ver not in versions: 50 print("Versions available for your system through this insaller are:") 51 print(versions, '\n') 52 ver = prompt.Prompt.ask("[bold cyan]Input the version of MESA to install[/bold cyan]") 53 if ver not in versions: 54 print("[red]Version not recognised, try again.[/red]\n") 55 56 if ostype == "Linux": 57 sdk = mesaurls.linux_sdk_urls.get(ver).split('-')[-1][:-7] 58 elif ostype == "macOS-Intel": 59 sdk = mesaurls.mac_intel_sdk_urls.get(ver).split('-')[-1][:-4] 60 elif ostype == "macOS-ARM": 61 sdk = mesaurls.mac_arm_sdk_urls.get(ver).split('-')[-1][:-4] 62 mesa = mesaurls.mesa_urls.get(ver).split('/')[-1].split('r')[-1][:-4] 63 print("The following will be installed:") 64 print(f"MESA SDK version: [green b]{sdk}[/green b]") 65 print(f"MESA version: [green b]{mesa}[/green b]\n") 66 return ver
Choose a version of MESA to install.
Arguments:
- ver (str, optional):
- Version of MESA to install. CLI is used to choose version if not specified.
Returns:
str: Version of MESA to install.