77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
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"]
|
|
|
|
# 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 = os.getcwd()
|
|
|
|
comand: str = 'git clone'
|
|
URL_GITEA = 'ssh://git@gitea.onecluster.org:6666/' # link ssh
|
|
ORGS = ['OneTeam', 'NaNtic']
|
|
destination_dir = './modules'
|
|
PREFIX_ORG = {'NaNtic': 'trytond-',
|
|
'OneTeam': 'trytondo-',
|
|
'Trytond': 'trytond'}
|
|
|
|
with open('sets/modules.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:
|
|
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}')
|
|
os.chdir('..') # Regresar al directorio prinicipal
|
|
except Exception as e:
|
|
logging.error(e)
|