[INIT] Inicialización de proyecto

This commit is contained in:
Mauro Rosero P. 2024-11-30 04:37:33 -05:00
parent 1a764c38de
commit 62a1030271
Signed by: mrosero
GPG key ID: 83BD2A5F674B7E26
8 changed files with 206 additions and 0 deletions

1
capture/__init__.py Normal file
View file

@ -0,0 +1 @@

134
capture/capture.py Normal file
View file

@ -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

25
capture/validate.py Normal file
View file

@ -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

20
config/.env.dev Normal file
View file

@ -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}

20
config/devs.j2 Normal file
View file

@ -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}

1
config/project.head Normal file
View file

@ -0,0 +1 @@
Odoo Developers Environment

1
config/project.name Normal file
View file

@ -0,0 +1 @@
odoo_devs

4
config/setup.es.ask Normal file
View file

@ -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]
]