import yaml import os import subprocess import argparse import logging # configurar el nivel logging.basicConfig(level=logging.DEBUG) if not os.path.exists('modules'): os.makedirs('modules') parser = argparse.ArgumentParser( description='Script para clonar los modulos que se utilizaran') # Empresas permitidas empresas_permitidos = ["OneTeam", "NaNtic", "Trytond"] # Agregar al menos un argumento de tipo str para elegir la empresa parser.add_argument( 'empresas', nargs='+', # Permitir mĂșltiples valores type=str, choices=empresas_permitidos, help='Empresas (debe elegir algunas de de las siguientes: OneTeam, NaNtic)' ) # Parsear los argumentos de la lĂ­nea de comandos args = parser.parse_args() # Acceder a la lista de nombres de las empresas empresas = args.empresas directorio_principal = f"../{os.getcwd()}" comand: str = 'git clone' #URL_GITEA = 'ssh://git@gitea.onecluster.org:6666/' # link ssh URL_GITEA = 'https://rodia:3sh0r4d3s3gu1r@gitea.onecluster.org/' ORGS = ['OneTeam', 'NaNtic'] destination_dir = './modules' PREFIX_ORG = {'NaNtic': 'trytond-', 'OneTeam': 'trytondo-', 'Trytond': 'trytond'} with open('sets/deploy_tpv.txt', 'r') as file_txt: selected_modules: list = [ m.replace('\n', '') for m in file_txt.readlines()] file_txt.close() try: for empresa in empresas: with open('./modules.yml', 'r') as file: dict_modules = yaml.safe_load(file) list_modules = dict_modules[empresa]['modules'] branch = dict_modules[empresa]['branch'] for modulo in list_modules: if modulo in selected_modules: if empresa != 'Trytond': PREFIX = PREFIX_ORG[empresa] link_module = f'{URL_GITEA}{empresa}/{PREFIX}{modulo}' if directorio_principal == os.getcwd(): os.chdir(destination_dir) comand: str = f'git clone {link_module} -b {branch}' subprocess.run(comand, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) logging.info(f'--> The module "{modulo}" has been cloned.') os.rename(f'./{PREFIX}{modulo}', f'./{modulo}') else: comand: str = f'pip3 install {modulo} -b {branch}' subprocess.run( comand, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) logging.info(f'--> The module "{modulo}" has been Installed.') os.chdir('..') # Regresar al directorio prinicipal except Exception as e: logging.error(e)