From 975c2f5b83e10acbbf03609261e784da7186d0ab Mon Sep 17 00:00:00 2001 From: sTiKyt Date: Tue, 11 Aug 2020 20:17:49 +0300 Subject: [PATCH] Created EULA_controller.py --- controllers/EULA_controller.py | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 controllers/EULA_controller.py diff --git a/controllers/EULA_controller.py b/controllers/EULA_controller.py new file mode 100644 index 0000000..cdaa79f --- /dev/null +++ b/controllers/EULA_controller.py @@ -0,0 +1,38 @@ +import pathlib +from os import chmod +import stat +from views.EULA_view import EULAView + + +class EULAController: + def __init__(self, confirmation_text: str = 'eula = True'): + self.eula = "eula.txt" + self.confirmation_text = confirmation_text + self.license = open("LICENSE", 'r') + + 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() + with open(str(self.eula), 'w+') as temp_eula: + chmod(self.eula, 0o777) + temp_eula.write("{0}\n{1}".format(EULAView().EULA_messages["eula_start_of_file"], text_license)) + temp_eula.close() + + def check_eula_confirmation(self): + with open(self.eula, 'r') as file: + 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