From 62a1030271e6e9614cbc984245c3198e7c457b80 Mon Sep 17 00:00:00 2001 From: Mauro Rosero P Date: Sat, 30 Nov 2024 04:37:33 -0500 Subject: [PATCH] =?UTF-8?q?[INIT]=20Inicializaci=C3=B3n=20de=20proyecto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- capture/__init__.py | 1 + capture/capture.py | 134 ++++++++++++++++++++++++++++++++++++++++++++ capture/validate.py | 25 +++++++++ config/.env.dev | 20 +++++++ config/devs.j2 | 20 +++++++ config/project.head | 1 + config/project.name | 1 + config/setup.es.ask | 4 ++ 8 files changed, 206 insertions(+) create mode 100644 capture/__init__.py create mode 100644 capture/capture.py create mode 100644 capture/validate.py create mode 100644 config/.env.dev create mode 100644 config/devs.j2 create mode 100644 config/project.head create mode 100644 config/project.name create mode 100644 config/setup.es.ask diff --git a/capture/__init__.py b/capture/__init__.py new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/capture/__init__.py @@ -0,0 +1 @@ + diff --git a/capture/capture.py b/capture/capture.py new file mode 100644 index 0000000..0fe9f2e --- /dev/null +++ b/capture/capture.py @@ -0,0 +1,134 @@ +# -*- coding: utf-8 -*- +import os, json, yaml +from yaml.loader import SafeLoader +from whiptail import Whiptail +from capture.validate import Validate + +M_ERROR="ERROR!" +M_WARNING="ADVERTENCIA" +M_INFO="INFORMACIÓN" + +class Capture(): + + def __init__(self): + self.mtitle=None + self.btitle=None + self.prompt_file=None + self.cfg_file=None + self.prompts=[] + self.fingerprints=None + + def set_mtitle(self, title): + self.mtitle = title + + def set_btitle(self, title): + self.btitle = title + + def set_title(self, mtitle, btitle): + set_mtitle(self, mtitle) + set_btitle(self, btitle) + + def build_window(self): + return Whiptail(title=self.mtitle, backtitle=self.btitle) + + def read_prompts(self, p_file=None): + if p_file == None: + p_file = self.prompt_file + with open(p_file, 'r') as f: + try: + json_data = f.read() + prompts=json.loads(json_data) + self.prompts = prompts + return prompts, None + except ValueError as e: + return None, str(e) + + def read_devinfo(self, p_file=None): + if p_file == None: + p_file = self.cfg__file + with open(p_file) as f: + try: + devdata = yaml.load(f, Loader=SafeLoader) + return devdata, None + except ValueError as e: + return None, str(e) + + def ask_prompts(self, widget, prompt=[]): + prompt_result = [100, None] + if len(prompt) >= 2: + mesg=prompt[2] + "\n" + prompt[3] + match prompt[1]: + case "inputbox": + prompt_result = widget.inputbox(mesg) + case "passwordbox": + prompt_result = widget.inputbox(mesg, password=True) + case "radiolist": + prompt_result = widget.radiolist(mesg, prompt[4]) + case _: + prompt_result = [253, None] + return prompt_result + + def go_capture(self, widget, prompts=[]): + result={} + count=0 + exit=0 + if prompts == [] or prompts == None: + prompts = self.prompts + while count <= len(prompts) - 1: + p=prompts[count] + result[p[0]] = self.ask_prompts(widget, p) + # End to ESC Key or Error + if result[p[0]][1] == 255: + exit=1 + break + # End when cancel button and first prompt + if result[p[0]][1] == 1 and count < 1: + exit=1 + break + # Back to previous prompt when cancel button + if result[p[0]][1] == 1: + count = count - 1 - p[6] + continue + # Don't accept null value, stay in this prompt + if result[p[0]][0] == "": + continue + # CONFIRM: + if f"confirm" in p[5]: + temporal = p[2] + p[2] = "Confirmar: " + p[2] + ck = self.ask_prompts(widget, p) + p[2] = temporal + if result[p[0]][0] != ck[0]: + widget.msgbox(M_ERROR + f" - " + p[3] + f":\n" + p[4][0]) + continue + else: + # VALIDATE: + for v in p[5]: + params = [] + validator = Validate() + if not hasattr(validator, v): + widget.msgbox(M_WARNING + f" - " + p[3] + f":\n" + v + ": Validación no existe!") + continue + # Se obtiene el método del objeto + ck_validate = getattr(validator, v) + params.append(result[p[0]][0]) + if not ck_validate(*params): + widget.msgbox(M_ERROR + f" - " + p[3] + f":\n" + p[4][0]) + count = count - 1 + break + count = count + 1 + p[7] + return exit, result + + def get_fingerprints(self, widget): + fingerprint = ["sops_fingerprint", "inputbox", "Fingerprint (GPG)", "Indique la huella gpg de encriptación para el instalador", [], [], 0, 0] + exit = False + fp_result = [100, None] + while not exit: + fp_result = self.ask_prompts(widget, fingerprint) + if fp_result[1] == 1: + exit = True + continue + if fp_result[0] != "": + exit = True + self.fingerprints = fp_result + return fp_result diff --git a/capture/validate.py b/capture/validate.py new file mode 100644 index 0000000..9a38fe6 --- /dev/null +++ b/capture/validate.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +import re, validators +from validate_email import validate_email + +### VALIDATION FUNCTIONS CLASS +class Validate(): + def __init__(self): + self.domain=None + + def dns1(self, domain): + self.domain = domain + return validators.domain(self.domain) + + def email1(self, email): + regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b' + result = False + if (re.fullmatch(regex, email)): + result = True + return result + + def email2(self, email): + result = False + if validate_email(email, verify=True): + result = True + return result diff --git a/config/.env.dev b/config/.env.dev new file mode 100644 index 0000000..ef4738d --- /dev/null +++ b/config/.env.dev @@ -0,0 +1,20 @@ +# Ultima actualización: 2024-04-21-13:12:10 +POSTGRES_VERSION=15 +POSTGRES_USER=${USER} +POSTGRES_PASS=odoo.DBA2024 +POSTGRES_PATH=./db/v17/l10n_cr/pg +POSTGRES_INIT=./db/v17/l10n_cr/init +ODOO_PROJECT=l10n_cr +ODOO_VERSION=17 +ODOO_PORT=10109 +ODOO_CHAT=20109 +ODOO_BACKUPS=./backups/v17/l10n_cr +ODOO_APPS=./apps +ODOO_ETC=./etc +ODOO_DATA=./db/v17/l10n_cr/data +ODOO_DATABASE=./db/v17/l10n_cr +ODOO_MASTER=l10n_cr_2024 +ODOO_WEB=./web +ODOO_UID=${UID} +ODOO_SUDO=y +POSTGRES_UID=${UID} diff --git a/config/devs.j2 b/config/devs.j2 new file mode 100644 index 0000000..8472f24 --- /dev/null +++ b/config/devs.j2 @@ -0,0 +1,20 @@ +# Ultima actualización: {{ date_today }} +POSTGRES_VERSION=15 +POSTGRES_USER=${USER} +POSTGRES_PASS=odoo.DBA{{ date_year }} +POSTGRES_PATH=./db/v{{ odoo_ver }}/{{ project }}/pg +POSTGRES_INIT=./db/v{{ odoo_ver }}/{{ project }}/init +ODOO_PROJECT={{ project }} +ODOO_VERSION={{ odoo_ver }} +ODOO_PORT=101{{ odoo_port }} +ODOO_CHAT=201{{ odoo_port }} +ODOO_BACKUPS=./backups/v{{ odoo_ver }}/{{ project }} +ODOO_APPS=./apps +ODOO_ETC=./etc +ODOO_DATA=./db/v{{ odoo_ver }}/{{ project }}/data +ODOO_DATABASE=./db/v{{ odoo_ver }}/{{ project }} +ODOO_MASTER={{ project }}_{{ date_year }} +ODOO_WEB=./web +ODOO_UID=${UID} +ODOO_SUDO=y +POSTGRES_UID=${UID} diff --git a/config/project.head b/config/project.head new file mode 100644 index 0000000..7841cb2 --- /dev/null +++ b/config/project.head @@ -0,0 +1 @@ +Odoo Developers Environment diff --git a/config/project.name b/config/project.name new file mode 100644 index 0000000..bb5b419 --- /dev/null +++ b/config/project.name @@ -0,0 +1 @@ +odoo_devs diff --git a/config/setup.es.ask b/config/setup.es.ask new file mode 100644 index 0000000..9c0caed --- /dev/null +++ b/config/setup.es.ask @@ -0,0 +1,4 @@ +[ +["odoo_version", "inputbox", "Versión Odoo", "Indique el número de la versión de Odoo a utilizar", [], [], 0, 0], +["odoo_port", "inputbox", "Puerto Odoo", "Indique el número de puerto a desplegar la instancia de Odoo", [], [], 0, 0] +]