lib/pyexec: Allow boot.py/main.py execution be silent if file doesn't exist.

Make it such for esp8266 port, as some percentage of people treat diagnostic
boot messages like:

could not open file 'boot.py' for reading

as "errors". Of course, this comes at the expense of more complicated
diagnostics if something unexpected actually happens (like boot.py was
made up by user but isn't loaded). The current problem though is recurring
false reports due to messages above.
pyexec-silent
Paul Sokolovsky 2016-07-23 13:20:27 +03:00
parent 2dd21d9a68
commit 791ba7f038
6 changed files with 17 additions and 11 deletions

View File

@ -175,7 +175,7 @@ soft_reset:
if (!safeboot) {
// run boot.py
int ret = pyexec_file("boot.py");
int ret = pyexec_file("boot.py", false);
if (ret & PYEXEC_FORCED_EXIT) {
goto soft_reset_exit;
}
@ -200,7 +200,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(main_py, false);
if (ret & PYEXEC_FORCED_EXIT) {
goto soft_reset_exit;
}

View File

@ -63,8 +63,8 @@ STATIC void mp_reset(void) {
dupterm_task_init();
#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("_boot.py");
pyexec_file("boot.py");
pyexec_file("main.py");
pyexec_file("boot.py", true);
pyexec_file("main.py", true);
#endif
}

View File

@ -488,11 +488,17 @@ friendly_repl_reset:
#endif // MICROPY_REPL_EVENT_DRIVEN
int pyexec_file(const char *filename) {
// This function is mostly intended to execute boot.py/main.py, i.e.
// run in unattended mode. It has bool param because many people
// find diagnostic message printed on board boot confusing (treat
// it as "error"), so ports affected may silence them.
int pyexec_file(const char *filename, bool silent) {
mp_lexer_t *lex = mp_lexer_new_from_file(filename);
if (lex == NULL) {
printf("could not open file '%s' for reading\n", filename);
if (!silent) {
printf("could not open file '%s' for reading\n", filename);
}
return false;
}

View File

@ -38,7 +38,7 @@ extern pyexec_mode_kind_t pyexec_mode_kind;
int pyexec_raw_repl(void);
int pyexec_friendly_repl(void);
int pyexec_file(const char *filename);
int pyexec_file(const char *filename, bool silent);
int pyexec_frozen_module(const char *name);
void pyexec_event_repl_init(void);
int pyexec_event_repl_process_char(int c);

View File

@ -537,7 +537,7 @@ soft_reset:
const char *boot_py = "boot.py";
FRESULT res = f_stat(boot_py, NULL);
if (res == FR_OK) {
int ret = pyexec_file(boot_py);
int ret = pyexec_file(boot_py, false);
if (ret & PYEXEC_FORCED_EXIT) {
goto soft_reset_exit;
}
@ -598,7 +598,7 @@ soft_reset:
}
FRESULT res = f_stat(main_py, NULL);
if (res == FR_OK) {
int ret = pyexec_file(main_py);
int ret = pyexec_file(main_py, false);
if (ret & PYEXEC_FORCED_EXIT) {
goto soft_reset_exit;
}

View File

@ -304,7 +304,7 @@ soft_reset:
#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("boot");
#else
if (!pyexec_file("/boot.py")) {
if (!pyexec_file("/boot.py", false)) {
flash_error(4);
}
#endif
@ -324,7 +324,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(vstr_null_terminated_str(vstr), false)) {
flash_error(3);
}
vstr_free(vstr);