zioinfo-mail/push_final2.py
DESKTOP-TKLFCPR\ython 777e027553 refactor(structure): move app -> workspace/guardia-messenger
Permission denied on git mv, used robocopy instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 23:53:57 +09:00

88 lines
2.7 KiB
Python

"""최종 push - git fetch refspec 수정"""
import paramiko, sys, os, subprocess
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=30)
sftp = client.open_sftp()
GITEA_AUTH_URL = 'zio:Zio%40Admin2026%21'
def run(label, cmd, timeout=300):
print(f' [{label}]')
_, o, e = client.exec_command(cmd, timeout=timeout)
out = o.read().decode('utf-8', errors='replace').strip()
err = e.read().decode('utf-8', errors='replace').strip()
if out: print(f' {out[-200:]}')
if err:
bad = [l for l in err.splitlines() if not any(k in l.lower() for k in ['warn','hint','cloning','into','updating','%','done'])]
if bad: print(f' ERR: {bad[-1]}')
return out
# 아직 push 안된 repos
REPOS = {
"zioinfo-web": "zio/zioinfo-web",
"guardia-itsm": "zio/guardia-itsm",
"guardia-manager": "zio/guardia-manager",
"guardia-docs": "zio/guardia-docs",
}
for local, gitea in REPOS.items():
local_path = f"C:/GUARDiA/repos/{local}"
bundle_path = f"C:/GUARDiA/repos/{local}.bundle"
server_bundle = f"/tmp/{local}.bundle"
name = gitea.split('/')[1]
print(f'\n {local}{gitea}')
# 번들 생성
r = subprocess.run(
['git', '-C', local_path, 'bundle', 'create', bundle_path, 'refs/heads/main'],
capture_output=True, text=True, timeout=120
)
if r.returncode != 0:
print(f' bundle 실패: {r.stderr[:100]}')
continue
size_mb = os.path.getsize(bundle_path) // (1024*1024)
print(f' bundle: {size_mb}MB')
sftp.put(bundle_path, server_bundle)
os.remove(bundle_path)
gitea_url = f"http://{GITEA_AUTH_URL}@127.0.0.1:9003/{gitea}.git"
run(f'push {local}', f"""
rm -rf /tmp/{name}_w
mkdir /tmp/{name}_w
cd /tmp/{name}_w
git init -b main
# refspec 명시하여 fetch
git fetch {server_bundle} refs/heads/main:refs/heads/main 2>&1 | head -3
git checkout main 2>/dev/null
HASH=$(git log --oneline -1 2>/dev/null)
echo "HEAD: $HASH"
git remote add origin '{gitea_url}'
git push origin main --force 2>&1 | tail -3
rm -rf /tmp/{name}_w {server_bundle}
echo "완료"
""")
# 최종 확인
run('최종 저장소 크기', """
curl -sf 'http://127.0.0.1:9003/api/v1/repos/search?limit=20' \
-u 'zio:Zio@Admin2026!' 2>/dev/null | \
python3 -c "
import sys,json
data = json.load(sys.stdin).get('data',[])
for r in data:
print(f' {r[\"full_name\"]:35s} {r.get(\"size\",0):8d} KB')
"
""")
sftp.close()
client.close()
print('\n=== 완료 ===')