From f6c54099863049b33891a9d738e7071747a16661 Mon Sep 17 00:00:00 2001 From: "neo.webmaster.2@gmail.com" Date: Wed, 4 Mar 2026 08:36:07 +0100 Subject: [PATCH] "Auto-commit via make git" --- Makefile.am | 2 +- src/Makefile.am | 10 ++++---- src/bootstrap.py | 43 ++++++++++++++++++++++++++++++++++ src/myhomelab | 10 ++++++++ src/{neuro.in => myhomelab.in} | 3 +-- src/neuro/Makefile.am | 3 +++ 6 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 src/bootstrap.py create mode 100755 src/myhomelab rename src/{neuro.in => myhomelab.in} (92%) diff --git a/Makefile.am b/Makefile.am index ec3d38e..1f5f5ac 100644 --- a/Makefile.am +++ b/Makefile.am @@ -113,7 +113,7 @@ check-remote: # Teste # =========================== run: - @python3 src/neuro/__main__.py + @python3 src/lab/__main__.py # =========================== # Limpeza diff --git a/src/Makefile.am b/src/Makefile.am index d7cfe13..22c27d7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,18 +1,18 @@ SUBDIRS = neuro -bin_SCRIPTS = neuro +bin_SCRIPTS = myhomelab CLEANFILES = $(bin_SCRIPTS) -EXTRA_DIST = neuro.in +EXTRA_DIST = myhomelab.in # =========================== # Substituição dinâmica # =========================== -neuro: neuro.in Makefile +myhomelab: myhomelab.in Makefile @which git >/dev/null || { echo "⚠️ Git não encontrado — instale-o manualmente."; exit 1; } sed \ -e 's,[@]pythondir[@],$(pythondir),g' \ -e 's,[@]PACKAGE[@],$(PACKAGE),g' \ -e 's,[@]VERSION[@],$(VERSION),g' \ - < $(srcdir)/neuro.in > neuro - chmod +x neuro + < $(srcdir)/myhomelab.in > myhomelab + chmod +x myhomelab diff --git a/src/bootstrap.py b/src/bootstrap.py new file mode 100644 index 0000000..467b863 --- /dev/null +++ b/src/bootstrap.py @@ -0,0 +1,43 @@ +from pathlib import Path +import subprocess +import sys +import os + + +class Application(object): + def __init__(self, *args, **kwargs): + for key in kwargs: + setattr(self, key, kwargs[key]) + self.base_path = Path(__file__).resolve().parents[1] + self.venv_path = self.base_path / "venv" + self.python = self.venv_path / "bin" / "python" + self._hello() + + def _hello(self): + print(f"Iniciando o {getattr(self, 'package', '')} {getattr(self, 'version', '')}...") + + def _print(self, msg: str): + print(f"[{getattr(self, 'package', '')}] {msg}", flush=True) + + def run(self): + self._ensure_venv() + self.launch_neuro() + + def _ensure_venv(self): + os.chdir(self.base_path) + + if not self.venv_path.exists(): + self._print("Criando ambiente Python...") + subprocess.run( + [sys.executable, "-m", "venv", str(self.venv_path)], + check=True + ) + else: + self._print("Ambiente Python já existente.") + + def launch_neuro(self): + neuro = self.base_path / "src" / "neuro" / "__main__.py" + subprocess.run([str(self.python), str(neuro)]) + + + diff --git a/src/myhomelab b/src/myhomelab new file mode 100755 index 0000000..e387d72 --- /dev/null +++ b/src/myhomelab @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +import sys +sys.path.insert(1, '/usr/local/local/lib/python3.12/dist-packages') + +from bootstrap import Application + +if __name__ == "__main__": + app = Application(package="myhomelab", version="51b9a23-dirty") + app.run() \ No newline at end of file diff --git a/src/neuro.in b/src/myhomelab.in similarity index 92% rename from src/neuro.in rename to src/myhomelab.in index 127b044..28353f6 100644 --- a/src/neuro.in +++ b/src/myhomelab.in @@ -7,5 +7,4 @@ from bootstrap import Application if __name__ == "__main__": app = Application(package="@PACKAGE@", version="@VERSION@") - app.run() - + app.run() \ No newline at end of file diff --git a/src/neuro/Makefile.am b/src/neuro/Makefile.am index 32c6840..7eaa4fb 100644 --- a/src/neuro/Makefile.am +++ b/src/neuro/Makefile.am @@ -9,5 +9,8 @@ neurodir = $(pythondir) dist_neuro_PYTHON = \ __main__.py \ __init__.py + +# Inclui o bootstrap (nível acima) como parte deste pacote +EXTRA_DIST = ../bootstrap.py