-
Notifications
You must be signed in to change notification settings - Fork 532
/
language.py
103 lines (85 loc) · 4.27 KB
/
language.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import subprocess
import os
from pathlib import Path
import questionary
from rich.console import Console
from rich.panel import Panel
from rich.traceback import install
import colorama
from colorama import Fore, init, Style
colorama.init
install()
console = Console()
def clear_screen():
os.system('clear')
print(f"""{Style.BRIGHT}{Fore.RED}
▄▄▄██▀▀▀▒█████ ▄▄▄ ▒█████ ██ ▄█▀ ██▀███ ██▓ ██████ ▄▄▄█████▓ ▄▄▄ ███▄ █ ██▓
▒██ ▒██▒ ██▒▒████▄ ▒██▒ ██▒ ██▄█▒ ▓██ ▒ ██▒▓██▒▒██ ▒ ▓ ██▒ ▓▒▒████▄ ██ ▀█ █ ▓██▒
░██ ▒██░ ██▒▒██ ▀█▄ ▒██░ ██▒▓███▄░ ▓██ ░▄█ ▒▒██▒░ ▓██▄ ▒ ▓██░ ▒░▒██ ▀█▄ ▓██ ▀█ ██▒▒██▒
▓██▄██▓ ▒██ ██░░██▄▄▄▄██ ▒██ ██░▓██ █▄ ▒██▀▀█▄ ░██░ ▒ ██▒░ ▓██▓ ░ ░██▄▄▄▄██ ▓██▒ ▐▌██▒░██░
▓███▒ ░ ████▓▒░ ▓█ ▓██▒░ ████▓▒░▒██▒ █▄░██▓ ▒██▒░██░▒██████▒▒ ▒██▒ ░ ▓█ ▓██▒▒██░ ▓██░░██░
▒▓▒▒░ ░ ▒░▒░▒░ ▒▒ ▓▒█░░ ▒░▒░▒░ ▒ ▒▒ ▓▒░ ▒▓ ░▒▓░░▓ ▒ ▒▓▒ ▒ ░ ▒ ░░ ▒▒ ▓▒█░░ ▒░ ▒ ▒ ░▓
▒ ░▒░ ░ ▒ ▒░ ▒ ▒▒ ░ ░ ▒ ▒░ ░ ░▒ ▒░ ░▒ ░ ▒░ ▒ ░░ ░▒ ░ ░ ░ ▒ ▒▒ ░░ ░░ ░ ▒░ ▒ ░
░ ░ ░ ░ ░ ░ ▒ ░ ▒ ░ ░ ░ ▒ ░ ░░ ░ ░░ ░ ▒ ░░ ░ ░ ░ ░ ▒ ░ ░ ░ ▒ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
{Style.RESET_ALL}{Fore.MAGENTA}{Fore.RESET}""")
def main():
clear_screen()
language = questionary.select("Escolha uma linguagem:",
choices=["pt", "en"]).ask()
if not is_python_installed():
clear_screen()
console.print(
Panel(f"O Python não está instalado em seu sistema.",
title="[bold red]Erro[/bold red]"))
return
elif not is_main_script_present(language):
clear_screen()
console.print(
Panel(f"Arquivo main-{language}.py não encontrado.",
title="[bold red]Erro[/bold red]"))
return
elif not confirm_execution(language):
clear_screen()
console.print(
Panel("Operação cancelada.",
title="[bold yellow]Aviso[/bold yellow]"))
return
try:
subprocess.run([get_python_interpreter(), f"main-{language}.py"])
except subprocess.CalledProcessError as e:
clear_screen()
console.print(
Panel(f"Erro ao executar o subprocesso: {e}",
title="[bold red]Erro[/bold red]"))
def is_python_installed():
try:
subprocess.check_output(["python", "--version"])
return True
except subprocess.CalledProcessError:
return False
def is_main_script_present(language):
return Path(f"main-{language}.py").is_file()
def confirm_execution(language):
messages = {
"pt":
"Você está prestes a executar o script main-pt.py. Deseja continuar?",
"en":
"You are about to execute the main-en.py script. Do you want to continue?"
}
clear_screen()
confirmation = questionary.confirm(messages[language]).ask()
return confirmation
def get_python_interpreter():
if is_python3_installed():
return "python3"
else:
return "python"
def is_python3_installed():
try:
subprocess.check_output(["python3", "--version"])
return True
except subprocess.CalledProcessError:
return False
if __name__ == "__main__":
main()