Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
|
|
|
| 3 |
|
| 4 |
def execute_wp_cli(command, args):
|
| 5 |
"""
|
| 6 |
Função para executar comandos WP-CLI com argumentos.
|
| 7 |
"""
|
| 8 |
try:
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Executa o comando WP-CLI
|
| 12 |
-
result = subprocess.run(full_command, capture_output=True, text=True)
|
| 13 |
# Retorna a saída do comando
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
except Exception as e:
|
| 16 |
-
return str(e)
|
| 17 |
|
| 18 |
# Lista de comandos WP-CLI comuns
|
| 19 |
commands = [
|
|
@@ -41,4 +53,4 @@ iface = gr.Interface(
|
|
| 41 |
)
|
| 42 |
|
| 43 |
# Inicia a interface
|
| 44 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
def execute_wp_cli(command, args):
|
| 6 |
"""
|
| 7 |
Função para executar comandos WP-CLI com argumentos.
|
| 8 |
"""
|
| 9 |
try:
|
| 10 |
+
# Recupera as variáveis de ambiente seguras
|
| 11 |
+
wp_path = os.getenv("WP_PATH")
|
| 12 |
+
wp_user = os.getenv("WP_USER")
|
| 13 |
+
wp_password = os.getenv("WP_PASSWORD")
|
| 14 |
+
|
| 15 |
+
if not wp_path or not wp_user or not wp_password:
|
| 16 |
+
return "Erro: Variáveis de ambiente WP_PATH, WP_USER ou WP_PASSWORD não definidas."
|
| 17 |
+
|
| 18 |
+
# Define o comando completo com credenciais
|
| 19 |
+
full_command = ['wp', '--path=' + wp_path, '--user=' + wp_user, '--prompt=password', command] + args.split()
|
| 20 |
+
|
| 21 |
# Executa o comando WP-CLI
|
| 22 |
+
result = subprocess.run(full_command, input=wp_password + "\n", capture_output=True, text=True, shell=True)
|
| 23 |
# Retorna a saída do comando
|
| 24 |
+
if result.returncode != 0:
|
| 25 |
+
return f"Erro ao executar o comando: {result.stderr}"
|
| 26 |
+
return result.stdout
|
| 27 |
except Exception as e:
|
| 28 |
+
return f"Erro: {str(e)}"
|
| 29 |
|
| 30 |
# Lista de comandos WP-CLI comuns
|
| 31 |
commands = [
|
|
|
|
| 53 |
)
|
| 54 |
|
| 55 |
# Inicia a interface
|
| 56 |
+
iface.launch()
|