From cdd19d6e65b9df2a7e1ceff1d78051d1528cd346 Mon Sep 17 00:00:00 2001 From: lgromero Date: Wed, 29 May 2024 16:24:20 +0200 Subject: [PATCH] refs #404 Adds swagger installation --- installer/ogboot_installer.py | 43 +++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/installer/ogboot_installer.py b/installer/ogboot_installer.py index 499bac5..08e0e5d 100755 --- a/installer/ogboot_installer.py +++ b/installer/ogboot_installer.py @@ -5,10 +5,8 @@ ##### Autor: Antonio Emmanuel Guerrero Silva ######## ################################################################################# -import platform, os, sys, subprocess, datetime, shutil, argparse, time, pwd, glob -import subprocess -import os -import shutil +import platform, os, sys, subprocess, datetime, shutil, argparse, time, pwd, glob, zipfile + global UBUNTU_OS_VERSION, OPENGNGYS_VERSION, PYTHON_VERSION_LAST, PYTHON_VERSION, DEPENDENCIES2, INSTALL_OGBOOT_TARGET, WORK_DIR, LOG_FILE, CHECKPKG, INSTALLPKG, PATH, PROGRAM_DIR, OPENGNSYS_SERVER, UPDATEPKGLIST @@ -309,6 +307,41 @@ def downloadComposer(): echoAndLog("composer.phar downloaded to /opt/ogboot/bin") return 0 +import urllib.request + +def install_swagger_ui(): + # Define la URL del archivo de Swagger UI que quieres descargar + swagger_ui_url = "https://github.com/swagger-api/swagger-ui/archive/refs/heads/master.zip" + + # Define la ruta donde quieres descomprimir Swagger UI + swagger_ui_path = "/tmp/swagger-ui" + + # Define la ruta de destino para los archivos de Swagger UI + destination_path = os.path.join(INSTALL_TARGET, "public") + + # Crea los directorios si no existen + os.makedirs(swagger_ui_path, exist_ok=True) + os.makedirs(destination_path, exist_ok=True) + + # Descarga el archivo de Swagger UI + urllib.request.urlretrieve(swagger_ui_url, "/tmp/swagger-ui.zip") + + # Descomprime el archivo de Swagger UI en la ruta especificada + with zipfile.ZipFile("/tmp/swagger-ui.zip", "r") as zip_ref: + zip_ref.extractall(swagger_ui_path) + + # Copia los archivos de Swagger UI al directorio de destino + shutil.copytree(os.path.join(swagger_ui_path, "swagger-ui-master", "dist"), destination_path) + + # Elimina el archivo descargado y el directorio temporal + os.remove("/tmp/swagger-ui.zip") + shutil.rmtree(swagger_ui_path) + + # Genera el archivo swagger.json + os.system(f"{os.path.join(INSTALL_TARGET, 'vendor', 'bin', 'openapi')} {INSTALL_TARGET}/src/OgBootBundle/Controller/ -o {destination_path}/swagger.json") + + print(f"Swagger UI instalado en {destination_path}.") + def create_ogboot_project(path_opengnsys_base): # Verificar si el usuario 'ogboot' ya existe @@ -379,6 +412,8 @@ def create_ogboot_project(path_opengnsys_base): if os.path.exists(composer_lock_path): os.remove(composer_lock_path) + install_swagger_ui() # Instalar Swagger UI + print("Esqueleto de la aplicación creado y archivo composer.lock eliminado.")