77logger = logging .getLogger ("fs" )
88logging .basicConfig (format = "%(levelname)s: %(message)s" , encoding = "utf-8" , level = logging .WARNING )
99
10- device = sys .argv [1 ]
10+ ''' device = sys.argv[1]
1111test_type = sys.argv[2]
12- mem_type = sys .argv [3 ]
12+ mem_type = sys.argv[3]'''
13+
14+ device = "/dev/ttyACM1"
15+ test_type = "basic"
16+ mem_type = "flash"
17+
1318
1419test_input_dir = "./ports/psoc6/inputs"
1520test_script_dir = "./ports/psoc6/mp_custom"
1621curr_dir = os .getcwd ()
1722print (f"Current directory: { curr_dir } " )
1823
24+ mpremote = "~/MPY/micropython/tools/mpremote/mpremote.py"
25+
1926
2027# List of mpremote commands
21- mpr_connect = f"../tools/ mpremote/mpremote.py connect { device } "
28+ # mpr_connect = f"{ mpremote} connect {device}"
2229mpr_run_script = ""
2330
2431# Remote directory path
@@ -157,14 +164,9 @@ def copy_files(input_cp_files):
157164 cp_sub_cmd += f"cp { test_input_dir } /{ file } :{ remote_directory_path } { append_cmd_operand } "
158165
159166 cp_cmd = f"{ mpr_connect } { mpr_run_script } { cp_sub_cmd } "
160- cp_cmd = f"{ mpr_connect } "
161-
162- ls_cmd = f"ls -l ./ports/psoc6/inputs"
163167
164168 logger .debug (f"cp_files command: { cp_cmd } " )
165169
166- print ("Check if file is available: " , subprocess .run (ls_cmd , shell = True , capture_output = True ))
167-
168170 print ("Copying files..." , subprocess .run (cp_cmd , shell = True , capture_output = True ))
169171
170172
@@ -192,7 +194,7 @@ def validate_test(files, file_sizes):
192194def cp_files_test (input_files , input_files_size ):
193195 rm_files_if_exist (input_files )
194196 copy_files (input_files )
195- validate_test (input_files , input_files_size )
197+ # validate_test(input_files, input_files_size)
196198
197199
198200def large_file_tests (device , test_type , mem_type ):
@@ -204,13 +206,54 @@ def large_file_tests(device, test_type, mem_type):
204206 cp_files_test (input_files , input_files_size )
205207
206208
207- def connect_to_dev_test ():
208- print ("Connecting to device..." )
209+ def copy_files_to_dev (cmd , file ):
210+ mpr_cp = f"{ mpr_connect } fs cp { file } :/"
211+ print ("Copying files..." , subprocess .run (mpr_cp , shell = True , capture_output = True ))
212+
213+
214+ # Function to find the micropython project root directory
215+ def find_micropython_root (start_path = "/" ):
216+ for root , dirs , files in os .walk (start_path ):
217+ if os .path .basename (root ) == "micropython" :
218+ return root
219+ return None
220+
221+
222+ # Function to search for a file within the micropython project directory
223+ def find_file_in_micropython (root_dir , filename ):
224+ for root , dirs , files in os .walk (root_dir ):
225+ if filename in files :
226+ return os .path .join (root , filename )
227+ return None
209228
210- mpr_connect_ls = f"{ mpr_connect } fs ls"
211- print (subprocess .run (f"{ mpr_connect_ls } " , shell = True , capture_output = True ))
212- # print(subprocess.run(f"{mpr_connect}", shell=True, capture_output=True))
213229
230+ # Main script logic
231+ if __name__ == "__main__" :
232+ # Find the micropython project root starting from the root of the filesystem
233+ root_dir = find_micropython_root (start_path = "/" )
234+
235+ if root_dir is None :
236+ print ("micropython directory not found" )
237+ else :
238+ print (f"Found micropython project root at: { root_dir } " )
239+
240+ filename = "mpremote.py"
241+ mpremote = find_file_in_micropython (root_dir , filename )
242+
243+ if mpremote :
244+ print (f"File found at: { mpremote } " )
245+ else :
246+ print (f"File { filename } not found in the micropython project." )
247+
248+ mpr_connect = f"{ mpremote } connect { device } "
249+
250+ ip_file = "test_fs_small_file.txt"
251+ test_ip = find_file_in_micropython (root_dir , ip_file )
252+
253+ mpr_cp = f"{ mpr_connect } fs cp { test_ip } :/"
254+ print ("Copying files..." , subprocess .run (mpr_cp , shell = True , capture_output = True ))
214255
215256# connect_to_dev_test()
216- large_file_tests (device , test_type , mem_type )
257+ # large_file_tests(device, test_type, mem_type)
258+
259+ # copy_files_to_dev()
0 commit comments