build_and_release.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. # 读取输出并打印到当前终端
  20. while True:
  21. data = proc.read()
  22. if not data:
  23. break
  24. print(data, end='')
  25. except Exception as e:
  26. print(f"Error executing command: {command}. Error: {e}")
  27. def build_and_release(self):
  28. for command in self.commands:
  29. self.__run_command(command)
  30. if __name__ == "__main__":
  31. bar = BuildAndRelease()
  32. bar.build_and_release()