1 Star 0 Fork 0

wangjh/obs_build

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.py 2.37 KB
一键复制 编辑 原始数据 按行查看 历史
wangjh 提交于 2024-02-22 09:13 . obs_build
import os
import subprocess
from flask import Flask, request, Response
import paramiko
import socket # 添加socket模块的导入
app = Flask(__name__)
def execute_remote_command(hostname, username, password, commands):
output = ""
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(hostname, username=username, password=password)
print(f"连接到远程主机 {hostname} 成功")
ssh_stdin, ssh_stdout, ssh_stderr = client.exec_command(" && ".join(commands)) # 将多个命令以字符串的形式连接起来传递给 exec_command
for line in ssh_stdout:
print(line.strip('\n'))
output += line
for line in ssh_stderr:
print(line.strip('\n'))
# 或者将错误信息存储到变量中,以便后续处理
# error += line
except (paramiko.ssh_exception.AuthenticationException, paramiko.ssh_exception.SSHException, socket.error) as e: # 添加socket.error在异常处理中
print(f"连接到远程主机 {hostname} 失败: {e}")
finally:
client.close()
return output
@app.route('/build-and-compile')
def build_and_compile():
package = request.args.get('package')
target_platform = request.args.get('platform')
if package and target_platform:
project, package_name = package.split('/')
target_dir = f"{project}/{package_name}"
print(target_dir)
if target_platform == 'x86':
x86_hostname = "192.168.1.72"
x86_username = "wjh"
x86_passwd = "wjh@#1234"
commands = [
f"rm -rf ~/devel/{project}/{package_name}*",
f"cd ~/devel && osc co {project}/{package_name}",
f"cd ~/devel/{project}/{package_name} && osc up -S",
f"cd ~/devel/{project}/{package_name} && rm -f _service; for file in `ls | grep -v .osc`; do new_file=${{file##*:}}; mv $file $new_file; done",
f"cd ~/devel/{project}/{package_name} && osc build standard_x86_64_gcc x86_64"
]
result = execute_remote_command(x86_hostname, x86_username, x86_passwd, commands)
result_with_br = result.replace('\n', '<br>')
return Response(result_with_br, content_type='text/html')
if __name__ == "__main__":
app.run()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangjh1121/obs_build.git
git@gitee.com:wangjh1121/obs_build.git
wangjh1121
obs_build
obs_build
master

搜索帮助