|
| 1 | +"""Push one or more folders to one or more robots.""" |
| 2 | +import subprocess |
| 3 | +import multiprocessing |
| 4 | +import json |
| 5 | + |
| 6 | +global folders |
| 7 | +# Opentrons folders that can be pushed to robot |
| 8 | +folders = [ |
| 9 | + "abr-testing", |
| 10 | + "hardware-testing", |
| 11 | + "abr-testing + hardware-testing", |
| 12 | + "other", |
| 13 | +] |
| 14 | + |
| 15 | + |
| 16 | +def push_subroutine(cmd: str) -> None: |
| 17 | + """Pushes specified folder to specified robot.""" |
| 18 | + try: |
| 19 | + subprocess.run(cmd) |
| 20 | + except Exception: |
| 21 | + print("failed to push folder") |
| 22 | + raise |
| 23 | + |
| 24 | + |
| 25 | +def main(folder_to_push: str, robot_to_push: str) -> int: |
| 26 | + """Main process!""" |
| 27 | + cmd = "make -C {folder} push-ot3 host={ip}" |
| 28 | + robot_ip_path = "" |
| 29 | + push_cmd = "" |
| 30 | + folder_int = int(folder_to_push) |
| 31 | + if folders[folder_int].lower() == "abr-testing + hardware-testing": |
| 32 | + if robot_to_push.lower() == "all": |
| 33 | + robot_ip_path = input("Path to robot ips: ") |
| 34 | + with open(robot_ip_path, "r") as ip_file: |
| 35 | + robot_json = json.load(ip_file) |
| 36 | + robot_ips_dict = robot_json.get("ip_address_list") |
| 37 | + robot_ips = list(robot_ips_dict.keys()) |
| 38 | + ip_file.close() |
| 39 | + else: |
| 40 | + robot_ips = [robot_to_push] |
| 41 | + for folder_name in folders[:-2]: |
| 42 | + # Push abr-testing and hardware-testing folders to all robots |
| 43 | + for robot in robot_ips: |
| 44 | + print_proc = multiprocessing.Process( |
| 45 | + target=print, args=(f"Pushing {folder_name} to {robot}!\n\n",) |
| 46 | + ) |
| 47 | + print_proc.start() |
| 48 | + print_proc.join() |
| 49 | + push_cmd = cmd.format(folder=folder_name, ip=robot) |
| 50 | + process = multiprocessing.Process( |
| 51 | + target=push_subroutine, args=(push_cmd,) |
| 52 | + ) |
| 53 | + process.start() |
| 54 | + process.join() |
| 55 | + print_proc = multiprocessing.Process(target=print, args=("Done!\n\n",)) |
| 56 | + print_proc.start() |
| 57 | + print_proc.join() |
| 58 | + else: |
| 59 | + |
| 60 | + if folder_int == (len(folders) - 1): |
| 61 | + folder_name = input("Which folder? ") |
| 62 | + else: |
| 63 | + folder_name = folders[folder_int] |
| 64 | + if robot_to_push.lower() == "all": |
| 65 | + robot_ip_path = input("Path to robot ips: ") |
| 66 | + with open(robot_ip_path, "r") as ip_file: |
| 67 | + robot_json = json.load(ip_file) |
| 68 | + robot_ips = robot_json.get("ip_address_list") |
| 69 | + ip_file.close() |
| 70 | + else: |
| 71 | + robot_ips = [robot_to_push] |
| 72 | + |
| 73 | + # Push folder to robots |
| 74 | + for robot in robot_ips: |
| 75 | + print_proc = multiprocessing.Process( |
| 76 | + target=print, args=(f"Pushing {folder_name} to {robot}!\n\n",) |
| 77 | + ) |
| 78 | + print_proc.start() |
| 79 | + print_proc.join() |
| 80 | + push_cmd = cmd.format(folder=folder_name, ip=robot) |
| 81 | + process = multiprocessing.Process(target=push_subroutine, args=(push_cmd,)) |
| 82 | + process.start() |
| 83 | + process.join() |
| 84 | + print_proc = multiprocessing.Process(target=print, args=("Done!\n\n",)) |
| 85 | + print_proc.start() |
| 86 | + print_proc.join() |
| 87 | + return 0 |
| 88 | + |
| 89 | + |
| 90 | +if __name__ == "__main__": |
| 91 | + for i, folder in enumerate(folders): |
| 92 | + print(f"{i}) {folder}") |
| 93 | + folder_to_push = input("Please Select a Folder to Push: ") |
| 94 | + robot_to_push = input("Type in robots ip (type all for all): ") |
| 95 | + print(main(folder_to_push, robot_to_push)) |
0 commit comments