Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
send_bucket.py
Go to the documentation of this file.
1import os
2import sys
3import argparse
4from bucket_operations import upload_csv_to_bucket
5
6# Define the folders to retrieve files from
7FOLDERS = {
8 "state_est": "performance/exec_time/ekf_state_est",
9 "perception": "performance/exec_time/perception",
10 "planning_exec_time": "performance/exec_time/planning",
11 "evaluator": "performance/evaluator_metrics",
12 "power_log": "performance/power_log_metrics",
13 "planning_cone_coloring": "performance/other_metrics/planning",
14 "test": "test",
15}
16
17
18def list_files(directory, filenames):
19 """!
20 List files in a directory.
21
22 Args:
23 directory: Directory to list files from.
24 filenames: Names of the files to retrieve, or 'all' to get all files.
25 """
26 try:
27 all_files = os.listdir(directory)
28 except FileNotFoundError:
29 print(f"Error: Directory '{directory}' not found.")
30 return []
31
32 if filenames == "all":
33 return [file for file in all_files if file not in [".gitkeep", ".gitignore"]]
34
35 selected_files = []
36 for filename in filenames:
37 if filename in all_files:
38 selected_files.append(filename)
39 else:
40 print(f"Warning: File '{filename}' not found in directory '{directory}'.")
41
42 return selected_files
43
44
45def main():
46 """!
47 Retrieve files from specified folders. Using argparse to parse command-line arguments.
48 """
49 parser = argparse.ArgumentParser(
50 description="Retrieve files from specified folders."
51 )
52 parser.add_argument(
53 "folder", choices=FOLDERS.keys(), help="Folder to retrieve files from."
54 )
55 parser.add_argument(
56 "filenames",
57 nargs="+",
58 help="Names of the files to retrieve, or 'all' to get all files.",
59 )
60 args = parser.parse_args()
61
62 directory = FOLDERS[args.folder]
63 filenames = args.filenames if args.filenames[0] != "all" else "all"
64
65 files = list_files(directory, filenames)
66
67 if files:
68 print("Retrieved files:")
69 for file in files:
70 source_file_name = directory + "/" + file
71 destination_path = f"{args.folder}/{file}"
72 upload_csv_to_bucket("as_evaluation", source_file_name, destination_path)
73 else:
74 print("No files retrieved.")
75
76
77if __name__ == "__main__":
78 main()
Definition main.py:1
list_files(directory, filenames)
List files in a directory.
main()
Retrieve files from specified folders.