build_and_release.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from winpty import PtyProcess
  2. class BuildAndRelease:
  3. def __init__(self):
  4. self.commands = [
  5. "python clean_build_all.py",
  6. "python build_all.py",
  7. "python make_release.py",
  8. "python clean_build_all.py"
  9. ]
  10. self.user_input = input("请输入conda python环境的名称(例如:base): ")
  11. def __run_command(self, command):
  12. try:
  13. # 如果是"python build_all.py"命令,先获取用户输入
  14. if "python build_all.py" == command:
  15. command += " "
  16. command += f"-python_env_name={self.user_input}"
  17. # 使用PtyProcess来运行命令
  18. proc = PtyProcess.spawn(["powershell", "-Command", command])
  19. proc.setwinsize(20, 9999)
  20. # 读取输出并打印到当前终端
  21. while True:
  22. data = proc.readline()
  23. if not data:
  24. break
  25. print(data, end='')
  26. except Exception as e:
  27. print(f"Error executing command: {command}. Error: {e}")
  28. def build_and_release(self):
  29. for command in self.commands:
  30. self.__run_command(command)
  31. if __name__ == "__main__":
  32. bar = BuildAndRelease()
  33. bar.build_and_release()