Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
166 lines (134 loc) · 4.93 KB
/
Copy pathsetup.py
File metadata and controls
166 lines (134 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
"""
Setup script for Ubuntu Code of Conduct Tool
Supports both Windows (with WSL) and Linux environments
"""
import subprocess
import sys
import os
import platform
def check_python():
"""Check if Python is properly installed"""
if sys.version_info < (3, 7):
print("❌ Python 3.7 o superior es requerido")
return False
print(f"✓ Python {sys.version.split()[0]} detectado")
return True
def check_wsl():
"""Check if WSL is available on Windows"""
if platform.system() != "Windows":
return True, "Linux nativo"
try:
result = subprocess.run(["wsl", "--list", "--quiet"],
capture_output=True, text=True, shell=True)
if result.returncode == 0:
distros = [line.strip() for line in result.stdout.strip().split('\n') if line.strip()]
if distros:
ubuntu_distros = [d for d in distros if 'ubuntu' in d.lower()]
distro = ubuntu_distros[0] if ubuntu_distros else distros[0]
return True, f"WSL disponible ({distro})"
return False, "WSL no está instalado"
except Exception:
return False, "WSL no está disponible"
def install_requirements():
"""Install Python requirements"""
try:
print("📦 Instalando dependencias de Python...")
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"],
check=True, shell=True)
print("✓ Dependencias de Python instaladas")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Error instalando dependencias: {e}")
return False
def install_streamlit_if_missing():
"""Install Streamlit if not available"""
try:
import streamlit
print("✓ Streamlit ya está instalado")
return True
except ImportError:
print("📦 Instalando Streamlit...")
try:
subprocess.run([sys.executable, "-m", "pip", "install", "streamlit"],
check=True, shell=True)
print("✓ Streamlit instalado")
return True
except subprocess.CalledProcessError:
print("❌ Error instalando Streamlit")
return False
def run_app():
"""Run the Streamlit application"""
try:
print("\n🚀 Iniciando Ubuntu Code of Conduct Tool...")
print("La aplicación se abrirá en tu navegador web.")
print("Presiona Ctrl+C para detener la aplicación.")
print("=" * 50)
# Change to the correct directory
app_path = os.path.join(os.path.dirname(__file__), "ui", "app.py")
subprocess.run([sys.executable, "-m", "streamlit", "run", app_path],
shell=True)
except KeyboardInterrupt:
print("\n👋 Aplicación detenida")
except Exception as e:
print(f"❌ Error ejecutando la aplicación: {e}")
def show_wsl_instructions():
"""Show WSL installation instructions"""
print("""
🔧 INSTRUCCIONES PARA INSTALAR WSL
================================
Para usar esta herramienta en Windows, necesitas WSL:
1. 📋 Abre PowerShell como Administrador:
- Presiona Win + X
- Selecciona "Windows PowerShell (Administrador)"
2. 🔽 Instala WSL:
wsl --install
3. 🔄 Reinicia tu computadora cuando se solicite
4. 🐧 Configura Ubuntu:
- Se abrirá automáticamente después del reinicio
- Crea un usuario y contraseña para Ubuntu
5. ✅ Ejecuta este script nuevamente
Alternativamente, puedes instalar desde Microsoft Store:
- Busca "Ubuntu" en Microsoft Store
- Instala "Ubuntu 20.04 LTS" o superior
Para más información: https://docs.microsoft.com/en-us/windows/wsl/install
""")
def main():
print("🔧 Ubuntu Code of Conduct Tool - Setup")
print("=" * 50)
# Check Python
if not check_python():
return
# Check WSL on Windows
wsl_available, wsl_message = check_wsl()
print(f"🐧 Entorno: {wsl_message}")
if not wsl_available:
show_wsl_instructions()
return
# Install Python dependencies
if not install_requirements():
return
# Ensure Streamlit is available
if not install_streamlit_if_missing():
return
print("\n✅ Setup completado exitosamente!")
# Show environment info
if platform.system() == "Windows":
print("""
💡 INFORMACIÓN IMPORTANTE PARA WINDOWS:
- Esta herramienta usa WSL para mantener compatibilidad completa
- Las claves se generan en el entorno Linux de WSL
- Son accesibles tanto desde Windows como desde WSL
""")
response = input("\n¿Quieres ejecutar la aplicación ahora? (s/n): ")
if response.lower() in ['s', 'si', 'sí', 'y', 'yes']:
run_app()
else:
print(f"""
Para ejecutar la aplicación más tarde, usa:
python setup.py
O directamente:
streamlit run ui/app.py
""")
if __name__ == "__main__":
main()