Files
SteelCheck/push_steelcheck.py
T

47 lines
1.6 KiB
Python

import subprocess
import os
import urllib.parse
import sys
from datetime import datetime
# Configurações do Gitea
GITEA_USER = "admtracksteel"
GITEA_PASS = "@@Gi05Br;;"
GITEA_URL = "git.reifonas.cloud"
GITEA_REPO = "SteelCheck"
# URL codificada para evitar problemas com caracteres especiais
encoded_pass = urllib.parse.quote(GITEA_PASS)
remote_url = f"https://{GITEA_USER}:{encoded_pass}@{GITEA_URL}/{GITEA_USER}/{GITEA_REPO}.git"
def run_command(command, description):
print(f"Executando: {description}...")
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(f"Sucesso em {description}")
return result.stdout
except subprocess.CalledProcessError as e:
print(f"Erro em {description}: {e.stderr}")
return None
# Mudar para o diretório do projeto
os.chdir("/root/Apps/SteelCheck_base")
# Inicializar Git se necessário
if not os.path.exists(".git"):
run_command("git init", "inicializar git")
# Configurar Git localmente para evitar erros de autenticação
run_command(f'git remote remove origin', "limpar remote antigo")
run_command(f'git remote add origin {remote_url}', "adicionar novo remote")
# Add e Commit
commit_message = sys.argv[1] if len(sys.argv) > 1 and sys.argv[1].strip() else f"Atualização automática - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
run_command("git add .", "adicionar arquivos")
run_command(f'git commit -m "{commit_message}"', "fazer commit")
# Push final
run_command("git push -u origin main --force", "fazer push para o Gitea")
print("\n--- Processo SteelCheck Concluído! ---")