@@ -73,12 +73,11 @@ function device_present {
73
73
74
74
# Check if a directory exists
75
75
# Returns 0 if directory exists, 1 if it does not
76
- function directory_exists {
76
+ function folder_exists {
77
77
# Run mpremote and capture the error message
78
- error=$( mpremote fs ls $1 )
79
-
80
- # Return error if error message contains "OSError: [Errno 2] ENOENT"
81
- if [[ $error == * " OSError: [Errno 2] ENOENT" * ]]; then
78
+ error=$( mpremote fs ls " $1 " 2>&1 )
79
+ # Return error if error message contains "ENOENT" or "No such file or directory" (>= 1.26.0)
80
+ if [[ $error == * " ENOENT" * ]] || [[ $error == * " No such file or directory" * ]]; then
82
81
return 1
83
82
else
84
83
return 0
@@ -88,7 +87,7 @@ function directory_exists {
88
87
# Copies a file to the board using mpremote
89
88
# Only produces output if an error occurs
90
89
function copy_file {
91
- output=" Copying $1 to $2 "
90
+ output=" Copying file to board: $1 >> $2 "
92
91
echo -n " $output "
93
92
# Run mpremote and capture the error message
94
93
error=$( mpremote cp $1 $2 )
@@ -103,7 +102,7 @@ function copy_file {
103
102
# Deletes a file from the board using mpremote
104
103
# Only produces output if an error occurs
105
104
function delete_file {
106
- output=" Deleting File $1 "
105
+ output=" Deleting file on board: $1 "
107
106
echo -n " $output "
108
107
# Run mpremote and capture the error message
109
108
error=$( mpremote rm $1 )
@@ -116,7 +115,7 @@ function delete_file {
116
115
}
117
116
118
117
function create_folder {
119
- output_msg=" Creating $1 on board"
118
+ output_msg=" Creating folder on board: $1 "
120
119
echo -n " $output_msg "
121
120
error=$( mpremote mkdir " $1 " )
122
121
# Print error message if return code is not 0
@@ -128,7 +127,7 @@ function create_folder {
128
127
}
129
128
130
129
function delete_folder {
131
- output_msg=" Deleting Folder $1 on board"
130
+ output_msg=" Deleting Folder on board: $1 "
132
131
echo -n " $output_msg "
133
132
delete_folder=" ${PYTHON_HELPERS} delete_folder(\" /$1 \" )"
134
133
error=$( mpremote exec " $delete_folder " )
@@ -140,6 +139,16 @@ function delete_folder {
140
139
echo -e " \r√ $output_msg "
141
140
}
142
141
142
+ function get_board_lib_path {
143
+ device_root=" ${PYTHON_HELPERS} get_root()"
144
+ output=$( mpremote exec " $device_root " )
145
+ output=$( echo " $output " | tr -d ' [:space:]' )
146
+ if [[ -n " $output " ]]; then
147
+ echo " $output /lib"
148
+ else
149
+ echo " lib"
150
+ fi
151
+ }
143
152
144
153
function install_package {
145
154
if [[ $1 == " " ]]; then
@@ -152,17 +161,10 @@ function install_package {
152
161
PKGDIR=` basename $1 `
153
162
# Source directory for the package on the host
154
163
SRCDIR=` realpath .`
155
- # Board's library directory
156
- device_root=" ${PYTHON_HELPERS} print(get_root())"
157
- output=$( mpremote exec " $device_root " )
158
- output=$( echo " $output " | tr -d ' [:space:]' )
159
- # echo "Device Root: $output"
160
- if [ " $output " == " /flash" ]; then
161
- echo " Board has root in /flash"
162
- # output=""
163
- fi
164
- LIBDIR=" $output " " lib"
165
- create_folder " $LIBDIR "
164
+
165
+ LIBDIR=" $( get_board_lib_path) "
166
+ echo " Installing package $PKGNAME from $SRCDIR to $LIBDIR /$PKGDIR "
167
+
166
168
IFS=$' \n ' read -rd ' ' -a package_files < <( find . -mindepth 1)
167
169
items_count=${# package_files[@]}
168
170
current_item=0
@@ -176,8 +178,8 @@ function install_package {
176
178
# only delete and create package directory if it is the first item
177
179
# if the script never made it here, it means no files were found
178
180
if [ $current_item == 1 ]; then
179
- output_msg=" Deleting Package $LIBDIR /$PKGDIR on board "
180
- if directory_exists " ${LIBDIR} /${PKGDIR} " ; then
181
+ output_msg=" Deleting Package folder on board: $LIBDIR /$PKGDIR "
182
+ if folder_exists " ${LIBDIR} /${PKGDIR} " ; then
181
183
echo -n " $output_msg "
182
184
delete_folder=" ${PYTHON_HELPERS} delete_folder(\" ${LIBDIR} /${PKGDIR} \" )"
183
185
mpremote exec " $delete_folder "
@@ -196,7 +198,6 @@ function install_package {
196
198
destination_extension=$source_extension
197
199
clean_item_path=" ${item_path// .\/ / } "
198
200
if [[ " $ext " == " mpy" && " $source_extension " == " py" ]]; then
199
- echo -n " Compiling $clean_item_path to mpy"
200
201
mpy-cross " $item_path "
201
202
destination_extension=$ext
202
203
copy_file ${clean_item_path% .* } .$destination_extension :$LIBDIR /${destination_subpath% .* } .$destination_extension
@@ -244,7 +245,6 @@ for arg in "$@"; do
244
245
continue
245
246
fi
246
247
if [ " $arg " == " --mpy" ]; then
247
- echo " Compiling .py files to .mpy"
248
248
ext=" mpy"
249
249
continue
250
250
fi
@@ -266,6 +266,16 @@ if device_present == 0; then
266
266
exit 1
267
267
fi
268
268
269
+ LIBDIR=" $( get_board_lib_path) "
270
+ output_msg=" "
271
+ if folder_exists " ${LIBDIR} " ; then
272
+ output_msg=" Library folder ($LIBDIR ) exists on board"
273
+ else
274
+ create_folder " $LIBDIR "
275
+ output_msg=" Library folder ($LIBDIR ) did not exist on board, it was created."
276
+ fi
277
+ echo -ne " \r\033[2K"
278
+ echo -e " \r√ $output_msg "
269
279
package_number=0
270
280
start_dir=` pwd`
271
281
for package in " ${packages[@]} " ; do
0 commit comments