parent
96fb176388
commit
142b9942f6
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,95 @@ |
||||
Mapeate.Base = function(mapeate, entradas){ |
||||
|
||||
const self = this,
|
||||
base_cache = {x : 0, y : 0}; |
||||
let iniciado = false,
|
||||
base_hilo,
|
||||
construido = false; |
||||
|
||||
const constructor = () => { |
||||
|
||||
mapeate.print("info", "mapeate_base_construyendose"); |
||||
|
||||
mapeate.print("ok", "mapeate_base_construido"); |
||||
|
||||
}; |
||||
|
||||
this.iniciar = callback => { |
||||
|
||||
const terminar = estado => typeof callback == "function" && callback(estado); |
||||
|
||||
if(iniciado){ |
||||
terminar(false); |
||||
return false; |
||||
}; |
||||
iniciado = true; |
||||
|
||||
self.construir(() => { |
||||
mapeate.print("ok", "base_construida"); |
||||
terminar(true); |
||||
}); |
||||
|
||||
return true; |
||||
}; |
||||
|
||||
const base_hilo_metodo = () => { |
||||
|
||||
if(mapeate.si_mismo && (base_cache.x != mapeate.si_mismo.offsetWidth || base_cache.y != mapeate.si_mismo.offsetHeight) && mapeate.si_mismo.getAttribute){ |
||||
|
||||
const minimo = Number(mapeate.si_mismo.getAttribute("data-celdas-minimo")); |
||||
let tamano; |
||||
|
||||
base_cache.x = mapeate.si_mismo.offsetWidth; |
||||
base_cache.y = mapeate.si_mismo.offsetHeight; |
||||
|
||||
tamano = base_cache[base_cache.x < base_cache.y ? "x" : "y"] / Number(mapeate.si_mismo.getAttribute("data-celdas")); |
||||
|
||||
mapeate.si_mismo.style.fontSize = (tamano < minimo ? tamano = minimo : tamano) + "px"; |
||||
mapeate.si_mismo.setAttribute("data-menu-principal-completo", base_cache.x / tamano > 50); |
||||
|
||||
}; |
||||
|
||||
}; |
||||
|
||||
this.construir = callback => { |
||||
|
||||
const terminar = estado => typeof callback == "function" && callback(estado); |
||||
|
||||
if(construido){ |
||||
terminar(false); |
||||
return false; |
||||
}; |
||||
construido = true; |
||||
|
||||
mapeate.vistas.establecer(mapeate.configuracion("posicion_html"), mapeate.vistas.coger("base"), { |
||||
clases : "",
|
||||
link_local : "#",
|
||||
logo : mapeate.configuracion("logo"),
|
||||
hash : mapeate.coger_hash(),
|
||||
menu_principal : mapeate.vistas.crear_elementos_de_menu("elemento_menu_principal", mapeate.configuracion("menu_principal")),
|
||||
menu_links : mapeate.vistas.crear_elementos_de_menu("elemento_menu_links", mapeate.configuracion("menu_links")),
|
||||
lista_mapas : mapeate.mapas.selector.crear_lista(),
|
||||
parametros_raiz : { |
||||
aplicacion : mapeate.configuracion("aplicacion"),
|
||||
link : mapeate.configuracion("link"),
|
||||
git : mapeate.configuracion("git"),
|
||||
organizacion : mapeate.configuracion("organizacion"),
|
||||
celdas : mapeate.configuracion("celdas"),
|
||||
celdas_minimo : mapeate.configuracion("tamano_minimo_celda") |
||||
} |
||||
}, () => { |
||||
|
||||
mapeate.establecer_si_mismo(document.querySelector("#" + mapeate.hash_self)); |
||||
|
||||
base_hilo = mapeate.anadir_hilo_de_proceso(base_hilo_metodo); |
||||
|
||||
terminar(true); |
||||
|
||||
}); |
||||
|
||||
return true; |
||||
}; |
||||
|
||||
constructor(); |
||||
|
||||
}; |
@ -0,0 +1,99 @@ |
||||
Mapeate.Mapas.Selector = function(mapeate, entradas){ |
||||
|
||||
const self = this; |
||||
let iniciado = false; |
||||
|
||||
const constructor = () => { |
||||
|
||||
mapeate.print("info", "mapeate_mapas_selector_construyendose"); |
||||
|
||||
mapeate.print("ok", "mapeate_mapas_selector_construido"); |
||||
|
||||
}; |
||||
|
||||
this.iniciar = callback => { |
||||
|
||||
const terminar = estado => typeof callback == "function" && callback(estado); |
||||
|
||||
mapeate.print("info", "mapeate_mapas_selector_iniciando"); |
||||
|
||||
if(iniciado){ |
||||
mapeate.print("warn", "mapeate_mapas_selector_ya_iniciado"); |
||||
terminar(false); |
||||
return false; |
||||
}; |
||||
iniciado = true; |
||||
|
||||
mapeate.print("ok", "mapeate_mapas_selector_iniciado"); |
||||
|
||||
terminar(true); |
||||
|
||||
return true; |
||||
}; |
||||
|
||||
this.crear_lista = () => Object.keys(mapeate.mapas.coger_todos()).map(clave => { |
||||
|
||||
const mapa = mapeate.mapas.coger(clave); |
||||
|
||||
return mapeate.string_variables(mapeate.vistas.coger("elemento_seleccion_mapa"), { |
||||
...mapa,
|
||||
nombre_objeto : mapeate.nombre_objeto,
|
||||
nombre : clave,
|
||||
nombre_texto : mapeate.i18n(clave),
|
||||
objetivos : mapa.objetivos || Object.keys(mapa.elementos).length |
||||
}); |
||||
}).join(""); |
||||
|
||||
this.seleccionar = (elemento, evento) => { |
||||
|
||||
let error = ( |
||||
elemento === undefined ? 1 << 0 : |
||||
elemento === null ? 1 << 1 :
|
||||
typeof elemento != "object" ? 1 << 2 :
|
||||
!(elemento.tagName || elemento.nodeName) ? 1 << 3 :
|
||||
!elemento.hasAttribute("data-i18n") ? 1 << 4 :
|
||||
0) << 1; |
||||
|
||||
console.log(["A", error]); |
||||
|
||||
if(error) |
||||
return; |
||||
|
||||
let clave = elemento.getAttribute("data-i18n"); |
||||
const mapa_datos = mapeate.mapas.coger(clave); |
||||
|
||||
error = ( |
||||
clave === undefined ? 1 << 0 :
|
||||
clave === null ? 1 << 1 :
|
||||
typeof clave != "string" ? 1 << 2 :
|
||||
!clave ? 1 << 3 :
|
||||
!(clave = clave.trim()) ? 1 << 4 :
|
||||
mapa_datos === undefined ? 1 << 5 :
|
||||
mapa_datos === null ? 1 << 6 :
|
||||
0) << 1; |
||||
|
||||
console.log(["B", error]); |
||||
|
||||
if(error) |
||||
return; |
||||
|
||||
const mapa = { |
||||
nombre : clave,
|
||||
...mapa_datos,
|
||||
datos : mapeate.mapas.cache(mapa_datos.url) |
||||
}; |
||||
|
||||
if(!mapa.datos) |
||||
mapeate.leer_archivo(mapa_datos.url, datos => { |
||||
mapeate.mapas.cache(mapa_datos.url, datos); |
||||
mapa.datos = datos; |
||||
console.log(mapa); |
||||
}); |
||||
else
|
||||
console.log(mapa); |
||||
|
||||
}; |
||||
|
||||
constructor(); |
||||
|
||||
}; |
@ -0,0 +1,115 @@ |
||||
Mapeate.Mapas = function(mapeate, entradas){ |
||||
|
||||
const self = this,
|
||||
mapas = {},
|
||||
cache = {}; |
||||
let iniciado = false,
|
||||
sobreescribir_por_defecto; |
||||
|
||||
let selector = this.selector; |
||||
|
||||
const constructor = () => { |
||||
|
||||
mapeate.print("info", "mapeate_mapas_construyendose"); |
||||
|
||||
selector = self.selector = new Mapeate.Mapas.Selector(mapeate, entradas); |
||||
|
||||
mapeate.print("ok", "mapeate_mapas_construido"); |
||||
|
||||
}; |
||||
|
||||
this.iniciar = callback => { |
||||
|
||||
const terminar = estado => typeof callback == "function" && callback(estado); |
||||
|
||||
mapeate.print("info", "mapeate_mapas_iniciando"); |
||||
|
||||
if(iniciado){ |
||||
mapeate.print("warn", "mapeate_mapas_ya_iniciado"); |
||||
terminar(false); |
||||
return false; |
||||
}; |
||||
iniciado = true; |
||||
|
||||
sobreescribir_por_defecto = mapeate.configuracion(["mapas_sobreescribir", "sobreescribir"]); |
||||
|
||||
mapeate.ejecutar_array_asincrono([ |
||||
"archivos_de_mapas_por_defecto",
|
||||
"archivos_de_mapas",
|
||||
"mapas_por_defecto",
|
||||
"mapas" |
||||
], (clave, callback) => self.cargar(mapeate.configuracion(clave), true, callback), () => { |
||||
selector.iniciar(() => { |
||||
mapeate.print("ok", "mapeate_mapas_iniciado"); |
||||
terminar(true); |
||||
}); |
||||
}); |
||||
|
||||
return true; |
||||
}; |
||||
|
||||
const cargar = (entradas, sobreescribir, callback, i) => { |
||||
|
||||
if(!entradas || i >= entradas.length){ |
||||
typeof callback == "function" && callback(); |
||||
return; |
||||
}; |
||||
|
||||
const terminar = () => cargar(entradas, sobreescribir, callback, i + 1); |
||||
|
||||
if(!entradas[i]){ |
||||
terminar(); |
||||
return; |
||||
}; |
||||
|
||||
if(typeof entradas[i] == "object"){ |
||||
if(entradas[i] instanceof Array) |
||||
cargar(entradas[i], sobreescribir, terminar, 0); |
||||
else{ |
||||
for(const clave in entradas[i]) |
||||
if(sobreescribir || mapas[clave] === undefined) |
||||
mapas[clave] = entradas[i][clave]; |
||||
terminar(); |
||||
}; |
||||
}else if(typeof entradas[i] == "string"){ |
||||
|
||||
const procesar = string => mapeate.procesar_json( |
||||
string,
|
||||
json => cargar(json instanceof Array ? json : [json], sobreescribir, terminar, 0),
|
||||
terminar |
||||
); |
||||
|
||||
if(/^(\{(.|[\n\r])*\}|\[(.|[\r\n])*\])$/.test(entradas[i].trim())) |
||||
procesar(entradas[i]); |
||||
else
|
||||
mapeate.leer_archivo(entradas[i], procesar); |
||||
|
||||
}else
|
||||
terminar(); |
||||
|
||||
}; |
||||
|
||||
this.cargar = (entradas, sobreescribir, callback) => cargar( |
||||
typeof entradas == "object" && entradas instanceof Array ? entradas : [entradas],
|
||||
typeof sobreescribir == "boolean" ? sobreescribir : sobreescribir_por_defecto,
|
||||
callback,
|
||||
0 |
||||
); |
||||
|
||||
this.coger = claves => { |
||||
|
||||
const l = (claves = mapeate.coger_array_de_strings(claves)).length; |
||||
|
||||
for(let i = 0; i < l; i ++) |
||||
if(mapas[claves[i]] !== undefined) |
||||
return mapas[claves[i]]; |
||||
return claves[0] || null; |
||||
}; |
||||
|
||||
this.coger_todos = () => ({...mapas}); |
||||
|
||||
this.cache = (clave, datos) => datos === undefined ? cache[clave] : (cache[clave] = datos); |
||||
|
||||
constructor(); |
||||
|
||||
}; |
@ -0,0 +1,149 @@ |
||||
Mapeate.Vistas = function(mapeate, entradas){ |
||||
|
||||
const self = this,
|
||||
vistas = {}; |
||||
let iniciado = false,
|
||||
sobreescribir_por_defecto; |
||||
|
||||
const constructor = () => { |
||||
|
||||
mapeate.print("info", "mapeate_vistas_construyendose"); |
||||
|
||||
mapeate.print("ok", "mapeate_vistas_construido"); |
||||
|
||||
}; |
||||
|
||||
this.iniciar = callback => { |
||||
|
||||
const terminar = estado => typeof callback == "function" && callback(estado); |
||||
|
||||
mapeate.print("info", "mapeate_vistas_iniciando"); |
||||
|
||||
if(iniciado){ |
||||
mapeate.print("warn", "mapeate_vistas_ya_iniciado"); |
||||
terminar(false); |
||||
return false; |
||||
}; |
||||
iniciado = true; |
||||
|
||||
sobreescribir_por_defecto = mapeate.configuracion(["sobreescribir_vistas", "sobreescribir"]) |
||||
|
||||
mapeate.ejecutar_array_asincrono([ |
||||
"archivos_de_vistas_por_defecto",
|
||||
"archivos_de_vistas" |
||||
], (clave, callback) => self.cargar(mapeate.configuracion(clave), true, callback), () => { |
||||
mapeate.print("ok", "mapeate_vistas_iniciado"); |
||||
terminar(true); |
||||
}); |
||||
|
||||
return true; |
||||
}; |
||||
|
||||
const cargar = (entradas, sobreescribir, callback, i) => { |
||||
|
||||
if(!entradas || i >= entradas.length){ |
||||
typeof callback == "function" && callback(); |
||||
return; |
||||
}; |
||||
|
||||
const terminar = () => cargar(entradas, sobreescribir, callback, i + 1); |
||||
|
||||
if(!entradas[i]){ |
||||
terminar(); |
||||
return; |
||||
}; |
||||
|
||||
if(typeof entradas[i] == "object"){ |
||||
if(entradas[i] instanceof Array) |
||||
cargar(entradas[i], sobreescribir, terminar, 0); |
||||
else{ |
||||
for(const clave in entradas[i]) |
||||
if(typeof entradas[i] == "string" && (sobreescribir || vistas[clave] === undefined)) |
||||
vistas[clave] = entradas[i]; |
||||
terminar(); |
||||
}; |
||||
}else if(typeof entradas[i] == "string"){ |
||||
if(!(entradas[i] = entradas[i].trim())){ |
||||
terminar(); |
||||
return; |
||||
}; |
||||
|
||||
if(/^(\/|[a-z0-9]{3,5}\:\/{2})[^\r\n]*$/i.test(entradas[i])) |
||||
mapeate.leer_archivo(entradas[i], salida => cargar([salida], sobreescribir, terminar, 0)); |
||||
else{ |
||||
|
||||
if(/^(\[(.|[\r|\n])*\]|\{(.|[\n\n])*\})$/.test(entradas[i]) && mapeate.procesar_json( |
||||
entradas[i],
|
||||
json => cargar(json instanceof Array ? json : [json], sobreescribir, terminar, 0),
|
||||
terminar |
||||
)) |
||||
return; |
||||
|
||||
while(entradas[i].length){ |
||||
|
||||
const matches = entradas[i].match(/<\!\-{2} *\[{2}([^\[\]]+)\]{2} *\-{2}>/); |
||||
|
||||
if(!matches) |
||||
break; |
||||
|
||||
const l = (entradas[i] = entradas[i].substring(matches.index + matches[0].length)).indexOf(matches[0]); |
||||
|
||||
if(l == -1) |
||||
continue; |
||||
|
||||
if(sobreescribir || vistas[matches[1]] === undefined) |
||||
vistas[matches[1]] = entradas[i].substring(0, l); |
||||
entradas[i] = entradas[i].substring(l + matches[0].length); |
||||
|
||||
}; |
||||
|
||||
terminar(); |
||||
|
||||
}; |
||||
|
||||
}else
|
||||
terminar(); |
||||
|
||||
}; |
||||
|
||||
this.cargar = (entradas, sobreescribir, callback) => cargar( |
||||
typeof entradas == "object" && entradas instanceof Array ? entradas : [entradas],
|
||||
typeof sobreescribir == "boolean" ? sobreescribir : sobreescribir_por_defecto,
|
||||
callback,
|
||||
0 |
||||
); |
||||
|
||||
this.crear_elementos_de_menu = (vista, opciones) => opciones.map(opcion => mapeate.string_variables(vistas[vista], { |
||||
...opcion,
|
||||
nombre_texto : mapeate.i18n(opcion.nombre, opcion) |
||||
})).join(""); |
||||
|
||||
this.establecer = (posicion, vista, entradas, callback) => mapeate.precargar(posicion, posicion => { |
||||
|
||||
const precarga_hash = mapeate.hash(); |
||||
|
||||
posicion.innerHTML = mapeate.string_variables( |
||||
(vistas[vista] || vista) + '<div data-precarga="' + precarga_hash + '"></div>',
|
||||
entradas |
||||
); |
||||
|
||||
mapeate.precargar("div[data-precarga=" + precarga_hash + "]", elemento => { |
||||
elemento.remove(); |
||||
typeof callback == "function" && callback(); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
this.coger = claves => { |
||||
|
||||
const l = (claves = mapeate.coger_array_de_strings(claves)).length; |
||||
|
||||
for(let i = 0; i < l; i ++) |
||||
if(vistas[claves[i]] !== undefined) |
||||
return vistas[claves[i]]; |
||||
return claves[0] || null; |
||||
}; |
||||
|
||||
constructor(); |
||||
|
||||
}; |
@ -0,0 +1,251 @@ |
||||
#!/usr/bin/env python |
||||
# -*- coding: utf-8 -*- |
||||
|
||||
from os.path import dirname as nombre_directorio |
||||
from os.path import abspath as path_absoluto |
||||
from os.path import exists as path_existe |
||||
from re import compile as RECompile |
||||
from re import MULTILINE |
||||
import datetime |
||||
from json import loads as json_decodificar |
||||
|
||||
class PaisesMundoContinentes: |
||||
|
||||
__path_raiz = nombre_directorio(path_absoluto(__file__)) |
||||
__configuracion_por_defecto = { |
||||
"archivo_paises_continentes" : "/Data/continent.json", |
||||
"archivo_paises_mundo" : "/Data/World map.svg", |
||||
"archivo_respuesta" : __path_raiz + "/../Data/world-map-continented.svg", |
||||
"autoiniciar" : True, |
||||
"formato_terminal" : "[{tipo}] {yyyy}{mm}{dd} {hh}{ii}{ss}: {mensaje}", |
||||
"texto_por_defecto" : "" |
||||
} |
||||
__es_dos = '\\' in __path_raiz |
||||
__slash = '\\' if __es_dos else '/' |
||||
|
||||
re_arreglar_path = RECompile(r'[\\\\\/]+') |
||||
re_string_variables = RECompile(r'\{([^\{\}]+)\}') |
||||
re_id_paises = RECompile(r'^\t<(path|g) id="([^"]+)"', MULTILINE) |
||||
|
||||
def __init__(self, entradas = None): |
||||
|
||||
self.__configuracion = {} |
||||
self.__entradas = entradas |
||||
self.__tipos_terminal = [ |
||||
["unkn", "unknown", "desc", "desconocido"], |
||||
["info", "information", "informacion"], |
||||
[" ok ", "ok", "yes", "y", "si", "s"], |
||||
["warn", "warning", "avis", "aviso"], |
||||
["erro", "error", "no", "n", "wrong", "bad"], |
||||
["exce", "exception", "excepcion"] |
||||
] |
||||
self.__textos = { |
||||
"espanol" : { |
||||
"pmc_construyendo" : "La herramienta 'PaisesMundoContinentes' se está construyendo...", |
||||
"pmc_construido" : "La herramienta 'PaisesMundoContinentes' se construyó completamente.", |
||||
"pmc_iniciando" : "La herramienta 'PaisesMundoContinentes' se está iniciando...", |
||||
"pmc_iniciado" : "La herramienta 'PaisesMundoContinentes' se inició completamente." |
||||
} |
||||
} |
||||
self.__idioma = "espanol" |
||||
self.__idioma_por_defecto = "espanol" |
||||
self.__formato_terminal = self.configuracion("formato_terminal") |
||||
|
||||
self.imprimir("info", "pmc_construyendo") |
||||
|
||||
self.__paths_raiz = ["", self.__path_raiz + "/..", self.__path_raiz] |
||||
self.__iniciado = False |
||||
|
||||
self.imprimir("ok", "pmc_construido") |
||||
|
||||
self.configuracion("autoiniciar") and self.iniciar() |
||||
|
||||
def iniciar(self, callback = None): |
||||
|
||||
self.imprimir("info", "pmc_iniciando") |
||||
|
||||
def terminar(estado): |
||||
self.imprimir(*(("ok", "pmc_iniciado") if estado else ("warn", "pmc_ya_iniciado"))) |
||||
callable(callback) and callback(estado) |
||||
|
||||
if self.__iniciado: |
||||
terminar(False) |
||||
return False |
||||
self.__iniciado = True |
||||
|
||||
terminar(True) |
||||
|
||||
diccionario_paises_continentes = self.leer_archivo(self.configuracion("archivo_paises_continentes")) |
||||
paises_mundo = self.leer_archivo(self.configuracion("archivo_paises_mundo")) |
||||
|
||||
try: |
||||
diccionario_paises_continentes = json_decodificar(diccionario_paises_continentes) |
||||
except: |
||||
diccionario_paises_continentes = None |
||||
|
||||
if diccionario_paises_continentes != None: |
||||
|
||||
def callback(matches): |
||||
|
||||
codigo = matches.group(2).upper() |
||||
fragmento = matches.group(0) |
||||
|
||||
if codigo in diccionario_paises_continentes: |
||||
fragmento += ' data-continente="' + diccionario_paises_continentes[codigo] + '"' |
||||
|
||||
codigo == "NZ" and print(fragmento) |
||||
|
||||
return fragmento |
||||
|
||||
self.escribir_archivo(self.configuracion("archivo_respuesta"), self.re_id_paises.sub(callback, paises_mundo)) |
||||
|
||||
return True |
||||
|
||||
def cerrar(self, callback = None): |
||||
|
||||
self.imprimir("info", "pmc_cerrando") |
||||
|
||||
def terminar(estado): |
||||
self.imprimir(*(("ok", "pmc_cerrado") if estado else ("warn", "pmc_ya_cerrado"))) |
||||
callable(callback) and callback(estado) |
||||
|
||||
if not self.__iniciado: |
||||
terminar(False) |
||||
return False |
||||
self.__iniciado = False |
||||
|
||||
terminar(True) |
||||
|
||||
return True |
||||
|
||||
def nulos(self, nulos = None): |
||||
return nulos if isinstance(nulos, bool) else self.configuracion("nulos", None, False, False) |
||||
|
||||
def por_defecto(self, por_defecto = None, nulos = None): |
||||
return por_defecto if por_defecto != None or self.nulos(nulos) else self.configuracion("por_defecto", None, None, True) |
||||
|
||||
def configuracion(self, claves, entradas = None, por_defecto = None, nulos = None): |
||||
|
||||
claves = [clave.strip() for clave in (claves if isinstance(claves, (list, tuple)) else [claves]) if isinstance(clave, str)] |
||||
claves = [clave for i, clave in enumerate(claves) if clave and clave not in claves[:i]] |
||||
|
||||
if len(claves): |
||||
|
||||
nulos = self.nulos(nulos) |
||||
|
||||
for entrada in ( |
||||
list(entradas) if isinstance(entradas, (list, tuple)) else [entradas] |
||||
) + [self.__entradas, self.__configuracion, self.__configuracion_por_defecto]: |
||||
if isinstance(entrada, dict): |
||||
for clave in claves: |
||||
if clave in entrada and (nulos or entrada[clave] != None): |
||||
return entrada[clave] |
||||
return self.por_defecto(por_defecto, nulos) |
||||
|
||||
@classmethod |
||||
def string_variables(self, string, variables = None, por_defecto = None): |
||||
|
||||
variables = [conjunto for conjunto in ( |
||||
variables if isinstance(variables, (list, tuple)) else [variables] |
||||
) if isinstance(conjunto, dict)] |
||||
|
||||
def callback(matches): |
||||
clave = matches.group(1) |
||||
for conjunto in variables: |
||||
if clave in conjunto: |
||||
return str(conjunto[clave]) |
||||
return por_defecto if por_defecto != None else matches.group(0) |
||||
|
||||
return self.re_string_variables.sub(callback, string) |
||||
|
||||
def texto_por_defecto(self, por_defecto = None): |
||||
return str(por_defecto if isinstance(por_defecto, str) else self.configuracion("texto_por_defecto")) |
||||
|
||||
def __coger_i18n(self, claves, por_defecto): |
||||
|
||||
if not isinstance(claves, (list, tuple)): |
||||
claves = [claves] |
||||
claves = [clave.strip() for clave in claves if isinstance(clave, str)] |
||||
claves = [clave for i, clave in enumerate(claves) if clave not in claves[:i]] |
||||
|
||||
if len(claves): |
||||
|
||||
idiomas = [self.__idioma, self.__idioma_por_defecto] + list(self.__textos.keys()) |
||||
|
||||
for i, idioma in enumerate(idiomas): |
||||
if idioma and idioma not in idiomas[:i] and isinstance(idioma, str) and idioma in self.__textos: |
||||
for clave in claves: |
||||
if clave in self.__textos[idioma]: |
||||
return str(self.__textos[idioma][clave]) |
||||
return claves[0] |
||||
return self.texto_por_defecto(por_defecto) |
||||
|
||||
def i18n(self, claves, variables = None, por_defecto = None): |
||||
return self.string_variables(self.__coger_i18n(claves, por_defecto), variables, por_defecto) |
||||
|
||||
def coger_tipo_terminal(self, tipo): |
||||
|
||||
tipo = tipo.lower() |
||||
|
||||
for conjunto in self.__tipos_terminal: |
||||
if tipo in conjunto: |
||||
return conjunto[0] |
||||
return conjunto[0][0] |
||||
|
||||
def imprimir(self, tipo, mensaje, variables = None): |
||||
|
||||
conjunto = { |
||||
**( |
||||
variables if isinstance(variables, dict) else |
||||
{clave : valor for conjunto in [ |
||||
conjunto for conjunto in variables if isinstance(conjunto, dict) |
||||
] for clave, valor in conjunto.items()} if isinstance(variables, (list, tuple)) else |
||||
{}), |
||||
"tipo" : self.coger_tipo_terminal(tipo).upper(), |
||||
"tipo_crudo" : tipo, |
||||
"i18n" : mensaje |
||||
} |
||||
fecha = datetime.datetime.now() |
||||
|
||||
for clave in ("year", "month", "day", "hour", "minute", "second"): |
||||
|
||||
k = clave[0] if clave != "minute" else "i" |
||||
|
||||
conjunto[clave] = getattr(fecha, clave) |
||||
conjunto[k] = conjunto[clave] / 100 |
||||
conjunto[k + k] = ("00" + str(conjunto[k]))[-2:] |
||||
|
||||
conjunto["yyyy"] = conjunto["year"] |
||||
conjunto["mensaje"] = self.i18n(mensaje, conjunto) |
||||
|
||||
print(self.string_variables(self.__formato_terminal, conjunto)) |
||||
|
||||
@classmethod |
||||
def arreglar_path(self, path): |
||||
return self.re_arreglar_path.sub(self.__slash, path) |
||||
|
||||
def coger_path_absoluto(self, path): |
||||
for path_raiz in self.__paths_raiz: |
||||
path_absoluto = self.arreglar_path(path_raiz + self.__slash + path) |
||||
if path_existe(path_absoluto): |
||||
return path_absoluto |
||||
return None |
||||
|
||||
def leer_archivo(self, path): |
||||
path = self.coger_path_absoluto(path) |
||||
if path: |
||||
try: |
||||
with open(path, 'r') as archivo: |
||||
return archivo.read() |
||||
except Exception as excepcion: |
||||
pass |
||||
return None |
||||
|
||||
def escribir_archivo(self, path, contenido): |
||||
try: |
||||
with open(path, 'w') as archivo: |
||||
archivo.write(contenido) |
||||
except Exception as excepcion: |
||||
pass |
||||
|
||||
paises_mundo_continentes = PaisesMundoContinentes() |
@ -0,0 +1,17 @@ |
||||
# Desarrollo de KyMAN |
||||
|
||||
Archivo dedicado únicamente al desarrollo por KyMAN. |
||||
|
||||
## Continentes |
||||
|
||||
Para gestionar los continentes a partir del mapa de países, se establece un diccionario de paises y continentes y mediante patrón regular se le añade código de continente. De esta forma puede ser manipulado el mapa para mostrar únicamente el continente de interés con sus correspondientes países. Para ello se hace uso del siguiente diccionario ubicado en la fuente correspondiente: |
||||
|
||||
- /Data/continent.json |
||||
- http://country.io/continent.json |
||||
- http://country.io/data/ |
||||
|
||||
Para su implementación se hará uso de la herramienta siguiente: |
||||
|
||||
- /Python/PaisesMundoContinentes.py |
||||
|
||||
> La herramienta se conforma como clase por motivos de facilidad y agilidad visual para KyMAN, pero ésta no requiere de ser una clase y puede tener un diseño estructural perfectamente. |
Loading…
Reference in new issue