initial commit
This commit is contained in:
127
scripts/dev.py
Normal file
127
scripts/dev.py
Normal file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script de utilidades para desarrollo del Balotario
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
def clean_cache():
|
||||
"""Limpiar archivos de cache y temporales"""
|
||||
print("🧹 Limpiando archivos de cache...")
|
||||
|
||||
# Limpiar __pycache__
|
||||
for root, dirs, files in os.walk('.'):
|
||||
for dir_name in dirs:
|
||||
if dir_name == '__pycache__':
|
||||
cache_path = os.path.join(root, dir_name)
|
||||
print(f" Eliminando: {cache_path}")
|
||||
shutil.rmtree(cache_path)
|
||||
|
||||
# Limpiar archivos .pyc
|
||||
for root, dirs, files in os.walk('.'):
|
||||
for file in files:
|
||||
if file.endswith('.pyc'):
|
||||
pyc_path = os.path.join(root, file)
|
||||
print(f" Eliminando: {pyc_path}")
|
||||
os.remove(pyc_path)
|
||||
|
||||
print("✅ Cache limpiado")
|
||||
|
||||
def run_tests():
|
||||
"""Ejecutar todos los tests de Python"""
|
||||
print("🧪 Ejecutando tests de Python...")
|
||||
|
||||
test_files = [
|
||||
'test/test_parser.py',
|
||||
'test/test_clean_parser.py'
|
||||
]
|
||||
|
||||
for test_file in test_files:
|
||||
if os.path.exists(test_file):
|
||||
print(f"\n📝 Ejecutando: {test_file}")
|
||||
try:
|
||||
subprocess.run([sys.executable, test_file], check=True)
|
||||
print(f"✅ {test_file} - PASÓ")
|
||||
except subprocess.CalledProcessError:
|
||||
print(f"❌ {test_file} - FALLÓ")
|
||||
else:
|
||||
print(f"⚠️ {test_file} - NO ENCONTRADO")
|
||||
|
||||
def check_dependencies():
|
||||
"""Verificar que las dependencias estén instaladas"""
|
||||
print("📦 Verificando dependencias...")
|
||||
|
||||
try:
|
||||
import flask
|
||||
print(f"✅ Flask {flask.__version__}")
|
||||
except ImportError:
|
||||
print("❌ Flask no instalado")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def start_dev_server():
|
||||
"""Iniciar servidor de desarrollo"""
|
||||
print("🚀 Iniciando servidor de desarrollo...")
|
||||
|
||||
if not check_dependencies():
|
||||
print("❌ Faltan dependencias. Ejecuta: pip install -r requirements.txt")
|
||||
return
|
||||
|
||||
# Configurar variables de entorno para desarrollo
|
||||
os.environ['FLASK_ENV'] = 'development'
|
||||
os.environ['FLASK_DEBUG'] = 'true'
|
||||
|
||||
try:
|
||||
subprocess.run([sys.executable, 'run.py'])
|
||||
except KeyboardInterrupt:
|
||||
print("\n👋 Servidor detenido")
|
||||
|
||||
def show_help():
|
||||
"""Mostrar ayuda"""
|
||||
print("""
|
||||
🛠️ Script de Utilidades - Balotario Licencia A-I
|
||||
|
||||
Comandos disponibles:
|
||||
clean - Limpiar archivos de cache y temporales
|
||||
test - Ejecutar todos los tests de Python
|
||||
deps - Verificar dependencias instaladas
|
||||
dev - Iniciar servidor de desarrollo
|
||||
help - Mostrar esta ayuda
|
||||
|
||||
Uso:
|
||||
python scripts/dev.py <comando>
|
||||
|
||||
Ejemplos:
|
||||
python scripts/dev.py clean
|
||||
python scripts/dev.py test
|
||||
python scripts/dev.py dev
|
||||
""")
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
show_help()
|
||||
return
|
||||
|
||||
command = sys.argv[1].lower()
|
||||
|
||||
if command == 'clean':
|
||||
clean_cache()
|
||||
elif command == 'test':
|
||||
run_tests()
|
||||
elif command == 'deps':
|
||||
check_dependencies()
|
||||
elif command == 'dev':
|
||||
start_dev_server()
|
||||
elif command == 'help':
|
||||
show_help()
|
||||
else:
|
||||
print(f"❌ Comando desconocido: {command}")
|
||||
show_help()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user