2026-04-25 10:54:00 -05:00
|
|
|
#+------------------------------------------------------------------+
|
|
|
|
|
#| Imports |
|
|
|
|
|
#+------------------------------------------------------------------+
|
|
|
|
|
# Importamos todo
|
|
|
|
|
from .Defines import *
|
|
|
|
|
|
|
|
|
|
#+------------------------------------------------------------------+
|
|
|
|
|
#| Comando install |
|
|
|
|
|
#+------------------------------------------------------------------+
|
2026-05-07 15:49:18 -05:00
|
|
|
# Nota por defecto se activan..
|
2026-04-25 10:54:00 -05:00
|
|
|
@tsndep.command()
|
|
|
|
|
@click.argument('url', required=True)
|
|
|
|
|
@click.argument('branch', required=True)
|
2026-05-09 06:53:40 -05:00
|
|
|
@click.option('--no_execute_hooks', required=False, is_flag=True, help='Does it allow the dependency manager to execute hooks?')
|
2026-04-25 10:54:00 -05:00
|
|
|
@click.option('--path_install', required=False, type=str, default=None, help='Custom path where the repository will be installed')
|
2026-05-09 06:53:40 -05:00
|
|
|
def install(url, branch, no_execute_hooks, path_install):
|
2026-04-25 10:54:00 -05:00
|
|
|
"""Download/update dependencies"""
|
|
|
|
|
|
|
|
|
|
# Obtener ruta
|
|
|
|
|
root = path_install or os.getcwd()
|
|
|
|
|
|
|
|
|
|
# Print rut
|
|
|
|
|
repo_name = url.rstrip("/").split("/")[-1]
|
|
|
|
|
click.echo(f"[INSTALL:{repo_name}] Root: {root}")
|
|
|
|
|
|
|
|
|
|
# Creamos la ruta donde se ubicara el repo
|
|
|
|
|
repo_path = os.path.join(root, repo_name)
|
|
|
|
|
|
|
|
|
|
# En caso no se clone damos error
|
|
|
|
|
if not GitCommands.clone_repo(url, repo_path, branch):
|
|
|
|
|
click.echo(f"[INSTALL:{repo_name}] Failed to clone repository", err=True)
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
click.echo(f"[INSTALL:{repo_name}] Repository cloned at: {repo_path}")
|
|
|
|
|
|
|
|
|
|
# Procesar dependencias
|
|
|
|
|
visited : set = set()
|
2026-04-27 07:30:55 -05:00
|
|
|
|
|
|
|
|
# Ctx
|
2026-05-09 06:53:40 -05:00
|
|
|
if not no_execute_hooks: # Solo si podemos ejeuctar hooks enotnces ejeuctamos
|
2026-05-07 15:49:18 -05:00
|
|
|
ctx : CCommondsVariables = CCommondsVariables()
|
|
|
|
|
ctx.m_dict_vals["repo.root"] = root
|
|
|
|
|
ctx.m_dict_vals["os.sep"] = os.sep
|
|
|
|
|
|
|
|
|
|
# Run
|
|
|
|
|
if GitCommands.process_dependencies(repo_path, root, visited, on_pre_process=Hooks.execute_hooks, on_post_process=Hooks.execute_hooks, ctx_rep=ctx):
|
|
|
|
|
click.echo(f"[INSTALL:{repo_name}] Installation completed successfully")
|
|
|
|
|
else:
|
|
|
|
|
click.echo(f"[INSTALL:{repo_name}] Installation completed with some errors")
|
2026-04-25 10:54:00 -05:00
|
|
|
else:
|
2026-05-07 15:49:18 -05:00
|
|
|
# Run
|
|
|
|
|
if GitCommands.process_dependencies(repo_path, root, visited, on_pre_process=None, on_post_process=None, ctx_rep=None):
|
|
|
|
|
click.echo(f"[INSTALL:{repo_name}] Installation completed successfully")
|
|
|
|
|
else:
|
|
|
|
|
click.echo(f"[INSTALL:{repo_name}] Installation completed with some errors")
|
2026-04-25 10:54:00 -05:00
|
|
|
|
|
|
|
|
#+------------------------------------------------------------------+
|
|
|
|
|
#| Comando add |
|
|
|
|
|
#+------------------------------------------------------------------+
|
|
|
|
|
@tsndep.command()
|
|
|
|
|
@click.argument('url', required=True)
|
|
|
|
|
@click.argument('branch', required=True)
|
|
|
|
|
@click.option('--name', required=True, type=str, help='Repository name')
|
|
|
|
|
@click.option('--comment', required=False, type=str, default='', help='Comment about the repository')
|
|
|
|
|
def add(url, branch, name, comment):
|
|
|
|
|
"""Add new dependency to dependencies.json"""
|
|
|
|
|
|
|
|
|
|
# Obtener path del JSON
|
|
|
|
|
json_path: str = os.path.join(os.getcwd(), "dependencies.json")
|
|
|
|
|
|
|
|
|
|
# Verificar que exista
|
|
|
|
|
if not os.path.exists(json_path):
|
|
|
|
|
click.echo(f"[ADD:{name}] Repository does not have dependencies.json", err=True)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Cargar JSON
|
|
|
|
|
data: dict = JsonV.load_json(json_path)
|
|
|
|
|
|
|
|
|
|
if not data:
|
|
|
|
|
click.echo(f"[ADD:{name}] Failed to load JSON", err=True)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Validar estructura
|
|
|
|
|
if "repos" not in data or not isinstance(data["repos"], list):
|
|
|
|
|
click.echo(f"[ADD:{name}] JSON does not have valid structure (missing 'repos')", err=True)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Verificar que el repo no exista ya
|
|
|
|
|
if any(repo["name"] == name for repo in data["repos"]):
|
|
|
|
|
click.echo(f"[ADD:{name}] Repository '{name}' already exists", err=True)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Crear nuevo repo
|
|
|
|
|
new_repo: dict = {
|
|
|
|
|
"name": name,
|
|
|
|
|
"url": url,
|
|
|
|
|
"rama": branch,
|
|
|
|
|
"comment": comment
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Agregar al JSON
|
|
|
|
|
data["repos"].append(new_repo)
|
|
|
|
|
|
|
|
|
|
# Guardar
|
|
|
|
|
if JsonV.save_json(json_path, data):
|
|
|
|
|
click.echo(f"[ADD:{name}] Added successfully")
|
|
|
|
|
click.echo(f"[ADD:{name}] URL: {url}")
|
|
|
|
|
click.echo(f"[ADD:{name}] Branch: {branch}")
|
|
|
|
|
else:
|
|
|
|
|
click.echo(f"[ADD:{name}] Error saving JSON", err=True)
|
|
|
|
|
|
|
|
|
|
#+------------------------------------------------------------------+
|
|
|
|
|
#| Comando remove |
|
|
|
|
|
#+------------------------------------------------------------------+
|
|
|
|
|
@tsndep.command()
|
|
|
|
|
@click.argument('repo_name', required=True)
|
|
|
|
|
def remove(repo_name):
|
|
|
|
|
"""Remove a dependency from dependencies.json"""
|
|
|
|
|
|
|
|
|
|
# Obtenemos el path json
|
|
|
|
|
json_path: str = os.path.join(os.getcwd(), "dependencies.json")
|
|
|
|
|
|
|
|
|
|
# Check de existencia
|
|
|
|
|
if not os.path.exists(json_path):
|
|
|
|
|
click.echo(f"[REMOVE:{repo_name}] Repository does not have dependencies.json", err=True)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Cargamos y validamos
|
|
|
|
|
data: dict = JsonV.load_json(json_path)
|
|
|
|
|
if not data:
|
|
|
|
|
click.echo(f"[REMOVE:{repo_name}] Failed to load JSON", err=True)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if "repos" not in data:
|
|
|
|
|
click.echo(f"[REMOVE:{repo_name}] JSON does not have valid structure", err=True)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Guardar original para comparación
|
|
|
|
|
original_count = len(data["repos"])
|
|
|
|
|
|
|
|
|
|
# Filtrar (remover el que coincida)
|
|
|
|
|
data["repos"] = [repo for repo in data["repos"] if repo["name"] != repo_name]
|
|
|
|
|
|
|
|
|
|
# Verificar que se removió algo
|
|
|
|
|
if len(data["repos"]) == original_count:
|
|
|
|
|
click.echo(f"[REMOVE:{repo_name}] Repository not found", err=True)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Guardar
|
|
|
|
|
if JsonV.save_json(json_path, data):
|
|
|
|
|
click.echo(f"[REMOVE:{repo_name}] Removed successfully")
|
|
|
|
|
else:
|
|
|
|
|
click.echo(f"[REMOVE:{repo_name}] Error saving JSON", err=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#+------------------------------------------------------------------+
|
|
|
|
|
#| Comando update |
|
|
|
|
|
#+------------------------------------------------------------------+
|
|
|
|
|
@tsndep.command()
|
2026-05-09 06:53:40 -05:00
|
|
|
@click.option('--no_execute_hooks', required=False, is_flag=True, help='Does it allow the dependency manager to execute hooks?')
|
|
|
|
|
def update(no_execute_hooks):
|
2026-04-25 10:54:00 -05:00
|
|
|
"""Update repositories and dependencies"""
|
|
|
|
|
|
|
|
|
|
# Variables inciales
|
2026-05-15 11:44:03 -05:00
|
|
|
repo_path : str = os.getcwd() # Path al repo como tal
|
|
|
|
|
root : str = os.path.dirname(repo_path) # Path al rooot
|
2026-04-25 10:54:00 -05:00
|
|
|
repo_basename: str = os.path.basename(root)
|
|
|
|
|
visited : set = set()
|
2026-04-27 07:30:55 -05:00
|
|
|
|
|
|
|
|
# Actulizamos este repo (rama corriente)
|
|
|
|
|
if not GitCommands.update_repo(repo_path, "__curr"):
|
|
|
|
|
click.echo(f"[UPDATE:{repo_basename}] Error updating repository", err=True)
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
click.echo(f"[UPDATE:{repo_basename}] Updating repository, current branch")
|
2026-05-07 15:49:18 -05:00
|
|
|
|
2026-05-09 06:53:40 -05:00
|
|
|
if not no_execute_hooks:
|
2026-05-07 15:49:18 -05:00
|
|
|
# Ctx
|
|
|
|
|
ctx : CCommondsVariables = CCommondsVariables()
|
|
|
|
|
ctx.m_dict_vals["repo.root"] = root
|
|
|
|
|
ctx.m_dict_vals["os.sep"] = os.sep
|
2026-04-25 10:54:00 -05:00
|
|
|
|
2026-05-07 15:49:18 -05:00
|
|
|
# Ejecutamos
|
|
|
|
|
if GitCommands.update_dependencies(repo_path, root, visited, on_pre_process=Hooks.execute_hooks, on_post_process=Hooks.execute_hooks, ctx_rep=ctx):
|
|
|
|
|
click.echo(f"[UPDATE:{repo_basename}] Update completed successfully")
|
|
|
|
|
else:
|
|
|
|
|
click.echo(f"[UPDATE:{repo_basename}] Update completed with errors", err=True)
|
2026-04-25 10:54:00 -05:00
|
|
|
else:
|
2026-05-07 15:49:18 -05:00
|
|
|
# Ejecutamos
|
|
|
|
|
if GitCommands.update_dependencies(repo_path, root, visited, on_pre_process=None, on_post_process=None, ctx_rep=None):
|
|
|
|
|
click.echo(f"[UPDATE:{repo_basename}] Update completed successfully")
|
|
|
|
|
else:
|
|
|
|
|
click.echo(f"[UPDATE:{repo_basename}] Update completed with errors", err=True)
|
|
|
|
|
|