diff options
| author | Damien George | 2019-04-26 15:22:14 +1000 |
|---|---|---|
| committer | Damien George | 2019-04-26 15:22:14 +1000 |
| commit | 0646e607b537b43901db53c743ec2011a375f5e2 (patch) | |
| tree | c5049313f11beabef7936d1ec264f0416cdee6d0 | |
| parent | 06a532c227c2f37fc190deb84970fdfeaaf37d6a (diff) | |
ports: Convert to use pyexec_file_if_exists() to execute boot/main.py.
The stm32 and nrf ports already had the behaviour that they would first
check if the script exists before executing it, and this patch makes all
other ports work the same way. This helps when developing apps because
it's hard to tell (when unconditionally trying to execute the scripts) if
the resulting OSError at boot up comes from missing boot.py or main.py, or
from some other error. And it's not really an error if these scripts don't
exist.
| -rw-r--r-- | ports/cc3200/mptask.c | 4 | ||||
| -rw-r--r-- | ports/esp32/main.c | 4 | ||||
| -rw-r--r-- | ports/esp8266/main.c | 4 | ||||
| -rw-r--r-- | ports/nrf/main.c | 8 | ||||
| -rw-r--r-- | ports/stm32/main.c | 30 | ||||
| -rw-r--r-- | ports/teensy/main.c | 4 |
6 files changed, 22 insertions, 32 deletions
diff --git a/ports/cc3200/mptask.c b/ports/cc3200/mptask.c index 9d75f4678..d35338be1 100644 --- a/ports/cc3200/mptask.c +++ b/ports/cc3200/mptask.c @@ -180,7 +180,7 @@ soft_reset: if (!safeboot) { // run boot.py - int ret = pyexec_file("boot.py"); + int ret = pyexec_file_if_exists("boot.py"); if (ret & PYEXEC_FORCED_EXIT) { goto soft_reset_exit; } @@ -205,7 +205,7 @@ soft_reset: } else { main_py = mp_obj_str_get_str(MP_STATE_PORT(machine_config_main)); } - int ret = pyexec_file(main_py); + int ret = pyexec_file_if_exists(main_py); if (ret & PYEXEC_FORCED_EXIT) { goto soft_reset_exit; } diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 188fb5e70..d4f79646f 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -111,9 +111,9 @@ soft_reset: // run boot-up scripts pyexec_frozen_module("_boot.py"); - pyexec_file("boot.py"); + pyexec_file_if_exists("boot.py"); if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) { - pyexec_file("main.py"); + pyexec_file_if_exists("main.py"); } for (;;) { diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c index 67157ce18..3465e0446 100644 --- a/ports/esp8266/main.c +++ b/ports/esp8266/main.c @@ -77,9 +77,9 @@ STATIC void mp_reset(void) { #if MICROPY_MODULE_FROZEN pyexec_frozen_module("_boot.py"); - pyexec_file("boot.py"); + pyexec_file_if_exists("boot.py"); if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) { - pyexec_file("main.py"); + pyexec_file_if_exists("main.py"); } #endif } diff --git a/ports/nrf/main.c b/ports/nrf/main.c index b9c29e753..e1ffce938 100644 --- a/ports/nrf/main.c +++ b/ports/nrf/main.c @@ -227,12 +227,8 @@ pin_init0(); #if MICROPY_VFS || MICROPY_MBFS // run boot.py and main.py if they exist. - if (mp_import_stat("boot.py") == MP_IMPORT_STAT_FILE) { - pyexec_file("boot.py"); - } - if (mp_import_stat("main.py") == MP_IMPORT_STAT_FILE) { - pyexec_file("main.py"); - } + pyexec_file_if_exists("boot.py"); + pyexec_file_if_exists("main.py"); #endif for (;;) { diff --git a/ports/stm32/main.c b/ports/stm32/main.c index 6fa6a6267..0bdbbd481 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -678,15 +678,12 @@ soft_reset: // TODO perhaps have pyb.reboot([bootpy]) function to soft-reboot and execute custom boot.py if (reset_mode == 1 || reset_mode == 3) { const char *boot_py = "boot.py"; - mp_import_stat_t stat = mp_import_stat(boot_py); - if (stat == MP_IMPORT_STAT_FILE) { - int ret = pyexec_file(boot_py); - if (ret & PYEXEC_FORCED_EXIT) { - goto soft_reset_exit; - } - if (!ret) { - flash_error(4); - } + int ret = pyexec_file_if_exists(boot_py); + if (ret & PYEXEC_FORCED_EXIT) { + goto soft_reset_exit; + } + if (!ret) { + flash_error(4); } } @@ -735,15 +732,12 @@ soft_reset: } else { main_py = mp_obj_str_get_str(MP_STATE_PORT(pyb_config_main)); } - mp_import_stat_t stat = mp_import_stat(main_py); - if (stat == MP_IMPORT_STAT_FILE) { - int ret = pyexec_file(main_py); - if (ret & PYEXEC_FORCED_EXIT) { - goto soft_reset_exit; - } - if (!ret) { - flash_error(3); - } + int ret = pyexec_file_if_exists(main_py); + if (ret & PYEXEC_FORCED_EXIT) { + goto soft_reset_exit; + } + if (!ret) { + flash_error(3); } } diff --git a/ports/teensy/main.c b/ports/teensy/main.c index ad98a4364..1f529f589 100644 --- a/ports/teensy/main.c +++ b/ports/teensy/main.c @@ -302,7 +302,7 @@ soft_reset: #if MICROPY_MODULE_FROZEN pyexec_frozen_module("boot.py"); #else - if (!pyexec_file("/boot.py")) { + if (!pyexec_file_if_exists("/boot.py")) { flash_error(4); } #endif @@ -322,7 +322,7 @@ soft_reset: } else { vstr_add_str(vstr, mp_obj_str_get_str(pyb_config_main)); } - if (!pyexec_file(vstr_null_terminated_str(vstr))) { + if (!pyexec_file_if_exists(vstr_null_terminated_str(vstr))) { flash_error(3); } vstr_free(vstr); |
