Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
import os
|
| 4 |
|
| 5 |
def execute_wp_cli(command, args):
|
| 6 |
"""
|
| 7 |
-
Função para executar comandos WP-CLI
|
| 8 |
"""
|
| 9 |
try:
|
| 10 |
# Recupera as variáveis de ambiente seguras
|
| 11 |
-
|
| 12 |
wp_user = os.getenv("WP_USER")
|
| 13 |
-
|
| 14 |
|
| 15 |
-
if not
|
| 16 |
-
return "Erro: Variáveis de ambiente
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
if result.returncode != 0:
|
| 26 |
-
return f"Erro ao executar o comando: {result.stderr}"
|
| 27 |
-
return result.stdout
|
| 28 |
except Exception as e:
|
| 29 |
return f"Erro: {str(e)}"
|
| 30 |
|
|
@@ -54,4 +60,4 @@ iface = gr.Interface(
|
|
| 54 |
)
|
| 55 |
|
| 56 |
# Inicia a interface
|
| 57 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
def execute_wp_cli(command, args):
|
| 6 |
"""
|
| 7 |
+
Função para executar comandos WP-CLI via API REST.
|
| 8 |
"""
|
| 9 |
try:
|
| 10 |
# Recupera as variáveis de ambiente seguras
|
| 11 |
+
wp_app_password = os.getenv("WP_APP_PASSWORD")
|
| 12 |
wp_user = os.getenv("WP_USER")
|
| 13 |
+
wp_url = os.getenv("WP_URL")
|
| 14 |
|
| 15 |
+
if not wp_app_password or not wp_user or not wp_url:
|
| 16 |
+
return "Erro: Variáveis de ambiente WP_APP_PASSWORD, WP_USER ou WP_URL não definidas."
|
| 17 |
|
| 18 |
+
# URL da API REST
|
| 19 |
+
api_url = f"{wp_url}/wp-json/wp/v2"
|
| 20 |
|
| 21 |
+
# Configura a autenticação
|
| 22 |
+
auth = (wp_user, wp_app_password)
|
| 23 |
+
|
| 24 |
+
# Monta a URL do comando WP-CLI
|
| 25 |
+
command_url = f"{api_url}/{command.replace(' ', '/')}"
|
| 26 |
+
|
| 27 |
+
# Executa o comando WP-CLI via API REST
|
| 28 |
+
response = requests.post(command_url, auth=auth, json={"args": args})
|
| 29 |
+
|
| 30 |
+
if response.status_code != 200:
|
| 31 |
+
return f"Erro ao executar o comando: {response.text}"
|
| 32 |
|
| 33 |
+
return response.json()
|
|
|
|
|
|
|
|
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"Erro: {str(e)}"
|
| 36 |
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
# Inicia a interface
|
| 63 |
+
iface.launch()
|