#!/usr/bin/env python3 """Upload nginx.conf to production server via JumpServer""" import base64 import subprocess import sys import os # Read and encode the nginx.conf file nginx_conf_path = os.path.join(os.path.dirname(__file__), 'nginx.conf') with open(nginx_conf_path, 'rb') as f: b64_data = base64.b64encode(f.read()).decode() print(f"Encoded {len(b64_data)} characters") # Create the remote Python script remote_script = 'python3 -c "' remote_script += f"import base64; data = '''{b64_data}'''; " remote_script += "with open('/opt/wecom-it-desk/nginx/nginx.conf', 'wb') as f: f.write(base64.b64decode(data)); print('OK')" remote_script += '"' # Execute via jms_ops result = subprocess.run([ 'python', r'C:\Users\simon\.workbuddy\skills\jumpserver-ops\scripts\jms_ops.py', 'exec', '-c', remote_script ], capture_output=True, text=True, encoding='utf-8', errors='replace', cwd=r'd:\资料\03-项目开发\wecom_it_smart_desk') print(result.stdout) print(result.stderr)