HiddenEye-Legacy/controllers/EULA_controller.py

70 lines
2.5 KiB
Python
Raw Normal View History

2020-08-12 01:17:49 +08:00
import pathlib
import stat
2020-08-13 18:29:54 +08:00
from os import chmod
from time import sleep
2020-08-13 18:29:54 +08:00
2020-08-12 01:17:49 +08:00
from views.EULA_view import EULAView
class EULAController:
2020-08-13 18:29:52 +08:00
def __init__(self, confirmation_text: str = "eula = True"):
2020-08-12 01:17:49 +08:00
self.eula = "eula.txt"
self.confirmation_text = confirmation_text
2020-08-13 18:29:52 +08:00
self.license = open("LICENSE", "r")
2020-08-12 01:17:49 +08:00
def check_eula_existence(self):
"""
:return: True if self.eula exists
"""
if pathlib.Path(self.eula).exists():
print(EULAView().EULA_messages["eula_found"])
return True
print(EULAView().EULA_messages["eula_not_found"])
return False
def generate_new_eula(self):
pathlib.Path(str(self.eula)).touch(exist_ok=True)
text_license = self.license.read()
2020-08-13 18:29:52 +08:00
with open(str(self.eula), "w+") as temp_eula:
2020-08-12 01:17:49 +08:00
chmod(self.eula, 0o777)
2020-08-13 18:30:01 +08:00
temp_eula.write("{0}\n{1}".format(
EULAView().EULA_messages["eula_start_of_file_unconfirmed"],
text_license,
))
2020-08-12 01:17:49 +08:00
temp_eula.close()
def check_eula_confirmation(self):
2020-08-13 18:29:52 +08:00
with open(self.eula, "r") as file:
2020-08-12 01:17:49 +08:00
if self.confirmation_text in file.read():
print(EULAView().EULA_messages["eula_is_confirmed"])
return True
else:
print(EULAView().EULA_messages["eula_is_not_confirmed"])
return False
def confirm_eula(self):
2020-08-13 20:56:47 +08:00
print(
f'{self.license.read()}\n{EULAView().EULA_messages["eula_power_and_responsibility_message"]}\n')
print(EULAView().EULA_messages["eula_full_disclaimer"])
2020-08-13 20:56:47 +08:00
print(
f'{EULAView().EULA_messages["eula_do_you_accept"]} \n\n{EULAView().EULA_messages["eula_enter_to_continue"]}\n')
answer = input(
EULAView().EULA_messages["eula_input_prompt"]).lower().replace(" ", "")
if answer == "iaccepteula":
eula_temp_input = open(self.eula, "rt")
2020-08-13 18:29:52 +08:00
eula_temp_data = eula_temp_input.read().replace(
EULAView().EULA_messages["eula_start_of_file_unconfirmed"],
EULAView().EULA_messages["eula_start_of_file_confirmed"],
)
eula_temp_input.close()
eula_temp_input = open(self.eula, "wt")
eula_temp_input.write(eula_temp_data)
eula_temp_input.close()
print(EULAView().EULA_messages["eula_was_just_accepted"])
2020-08-13 20:56:16 +08:00
sleep(1.5)
pass
else:
print(EULAView().EULA_messages["eula_was_just_rejected"])
2020-08-13 20:56:16 +08:00
sleep(1.5)
exit()