|
17 | 17 | from abr_testing.tools import plate_reader
|
18 | 18 |
|
19 | 19 |
|
20 |
| -def retrieve_protocol_file( |
21 |
| - protocol_id: str, |
| 20 | +def retrieve_version_file( |
22 | 21 | robot_ip: str,
|
23 | 22 | storage: str,
|
24 | 23 | ) -> Path | str:
|
25 |
| - """Find and copy protocol file on robot with error.""" |
26 |
| - protocol_dir = f"/var/lib/opentrons-robot-server/7.1/protocols/{protocol_id}" |
| 24 | + """Retrieve Version file.""" |
| 25 | + version_file_path = "/etc/VERSION.json" |
| 26 | + save_dir = Path(f"{storage}") |
| 27 | + print(save_dir) |
| 28 | + command = ["scp", "-r", f"root@{robot_ip}:{version_file_path}", save_dir] |
| 29 | + try: |
| 30 | + subprocess.run(command, check=True) # type: ignore |
| 31 | + return os.path.join(save_dir, "VERSION.json") |
| 32 | + except subprocess.CalledProcessError as e: |
| 33 | + print(f"Error during file transfer: {e}") |
| 34 | + return "" |
| 35 | + |
| 36 | + |
| 37 | +def retrieve_protocol_file(protocol_id: str, robot_ip: str, storage: str) -> Path | str: |
| 38 | + """Find and copy protocol file on robot with error handling.""" |
| 39 | + # List folders in the robot's directory |
| 40 | + list_folder_command = [ |
| 41 | + "ssh", |
| 42 | + f"root@{robot_ip}", |
| 43 | + "ls /var/lib/opentrons-robot-server", |
| 44 | + ] |
| 45 | + try: |
| 46 | + result = subprocess.run( |
| 47 | + list_folder_command, check=True, capture_output=True, text=True |
| 48 | + ) |
| 49 | + folders = result.stdout.splitlines() |
| 50 | + |
| 51 | + def convert_to_floats(data: List) -> List: |
| 52 | + """Convert list to floats.""" |
| 53 | + float_list = [] |
| 54 | + for item in data: |
| 55 | + try: |
| 56 | + float_value = float(item) |
| 57 | + float_list.append(float_value) |
| 58 | + except ValueError: |
| 59 | + pass # Ignore items that cannot be converted to float |
| 60 | + return float_list |
| 61 | + |
| 62 | + folders_float = convert_to_floats(folders) |
| 63 | + if not folders_float: |
| 64 | + print("No folders found.") |
| 65 | + return "" |
| 66 | + folder_num = max( |
| 67 | + folders_float |
| 68 | + ) # Assuming the highest folder number is the latest |
| 69 | + if folder_num.is_integer(): |
| 70 | + folder_num = int(folder_num) |
| 71 | + except subprocess.CalledProcessError: |
| 72 | + print("Could not find folder.") |
| 73 | + return "" |
| 74 | + protocol_dir = ( |
| 75 | + f"/var/lib/opentrons-robot-server/{folder_num}/protocols/{protocol_id}" |
| 76 | + ) |
| 77 | + |
27 | 78 | # Copy protocol file found in robot onto host computer
|
28 | 79 | save_dir = Path(f"{storage}")
|
29 | 80 | command = ["scp", "-r", f"root@{robot_ip}:{protocol_dir}", save_dir]
|
@@ -366,6 +417,8 @@ def get_run_error_info_from_robot(
|
366 | 417 | description = dict()
|
367 | 418 | # get run information
|
368 | 419 | results = get_run_logs.get_run_data(one_run, ip)
|
| 420 | + # Get version file |
| 421 | + |
369 | 422 | # save run information to local directory as .json file
|
370 | 423 | saved_file_path = read_robot_logs.save_run_log_to_json(
|
371 | 424 | ip, results, storage_directory
|
@@ -545,6 +598,8 @@ def get_run_error_info_from_robot(
|
545 | 598 | except requests.exceptions.InvalidURL:
|
546 | 599 | print("Invalid IP address.")
|
547 | 600 | sys.exit()
|
| 601 | + version_file_dir = retrieve_version_file(robot_ip=ip, storage=storage_directory) |
| 602 | + version_file_path = os.path.join(storage_directory, version_file_dir) |
548 | 603 | if len(run_or_other) < 1:
|
549 | 604 | # Retrieve the most recently run protocol file
|
550 | 605 | protocol_folder = retrieve_protocol_file(
|
@@ -611,12 +666,14 @@ def get_run_error_info_from_robot(
|
611 | 666 | # OPEN TICKET
|
612 | 667 | issue_url = ticket.open_issue(issue_key)
|
613 | 668 | # MOVE FILES TO ERROR FOLDER.
|
| 669 | + print(version_file_path) |
| 670 | + print(run_log_file_path) |
614 | 671 | error_files = [
|
615 | 672 | saved_file_path_calibration,
|
616 | 673 | run_log_file_path,
|
617 | 674 | protocol_file_path,
|
| 675 | + version_file_path, |
618 | 676 | ] + file_paths
|
619 |
| - |
620 | 677 | error_folder_path = os.path.join(storage_directory, issue_key)
|
621 | 678 | os.makedirs(error_folder_path, exist_ok=True)
|
622 | 679 | for source_file in error_files:
|
|
0 commit comments