-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlanguage.py
116 lines (96 loc) · 5.89 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
104
105
106
107
108
109
110
111
112
113
114
115
116
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("Pilih bahasa:",
choices=["ID", "EN"]).ask()
if not is_python_installed():
clear_screen()
console.print(
Panel(f"Python tidak terinstal di sistem Anda.",
title="[bold red]Error[/bold red]"))
return
elif not is_main_script_present(language):
clear_screen()
console.print(
Panel(f"Tidak dapat menemukan file main-{language}.py.",
title="[bold red]Error[/bold red]"))
return
elif not confirm_execution(language):
clear_screen()
console.print(
Panel("Operasi dibatalkan.",
title="[bold yellow]Peringatan[/bold yellow]"))
return
try:
subprocess.run([get_python_interpreter(), f"main-{language}.py"])
console.log(
f"Subprocess command: {get_python_interpreter(), f'main-{language}.py'}"
)
clear_screen()
console.print(
Panel("Script berhasil dijalankan.",
title="[bold green]Sukses[/bold green]"))
except subprocess.CalledProcessError as e:
clear_screen()
console.print(
Panel(f"Terjadi kesalahan saat menjalankan subprocess: {e}",
title="[bold red]Error[/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 = {
"ID":
"Anda akan menjalankan skrip main-id.py. Apakah Anda ingin melanjutkan?",
"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()