|
|
import gradio as gr |
|
|
import subprocess |
|
|
import os |
|
|
|
|
|
def execute_wp_cli(command, args): |
|
|
""" |
|
|
Função para executar comandos WP-CLI com argumentos. |
|
|
""" |
|
|
try: |
|
|
|
|
|
wp_path = os.getenv("WP_PATH") |
|
|
wp_user = os.getenv("WP_USER") |
|
|
wp_password = os.getenv("WP_PASSWORD") |
|
|
|
|
|
if not wp_path or not wp_user or not wp_password: |
|
|
return "Erro: Variáveis de ambiente WP_PATH, WP_USER ou WP_PASSWORD não definidas." |
|
|
|
|
|
|
|
|
full_command = ['wp', '--path=' + wp_path, '--user=' + wp_user, '--prompt=password', command] + args.split() |
|
|
|
|
|
|
|
|
result = subprocess.run(full_command, input=wp_password + "\n", capture_output=True, text=True, shell=True) |
|
|
|
|
|
if result.returncode != 0: |
|
|
return f"Erro ao executar o comando: {result.stderr}" |
|
|
return result.stdout |
|
|
except Exception as e: |
|
|
return f"Erro: {str(e)}" |
|
|
|
|
|
|
|
|
commands = [ |
|
|
"plugin list", |
|
|
"plugin activate", |
|
|
"plugin deactivate", |
|
|
"theme list", |
|
|
"theme activate", |
|
|
"post list", |
|
|
"post create", |
|
|
"post update", |
|
|
"post delete", |
|
|
] |
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=execute_wp_cli, |
|
|
inputs=[ |
|
|
gr.Dropdown(choices=commands, label="Comando WP-CLI"), |
|
|
gr.Textbox(lines=1, placeholder="Digite os argumentos (se necessário)", label="Argumentos") |
|
|
], |
|
|
outputs="text", |
|
|
title="Painel de Controle WP-CLI", |
|
|
description="Selecione um comando WP-CLI e insira os argumentos necessários." |
|
|
) |
|
|
|
|
|
|
|
|
iface.launch() |