| Warn users whenever `python2` is invoked. |
| |
| --- a/Modules/main.c |
| +++ b/Modules/main.c |
| @@ -237,6 +237,20 @@ static int RunMainFromImporter(char *filename) |
| return -1; |
| } |
| |
| +void deprecate_warn(FILE *fp) |
| +{ |
| + int tty = isatty(2); |
| + if (tty) |
| + fprintf(fp, "\e[5;1;31m"); |
| + fprintf(fp, "%s: warning: Python 2.7 is deprecated and will be removed from CrOS by end of 2021. All users must migrate ASAP.\n", |
| + orig_argv[0]); |
| + fprintf(fp, "%s: commandline:", orig_argv[0]); |
| + for (int i = 1; i < orig_argc; ++i) |
| + fprintf(fp, " %s", orig_argv[i]); |
| + if (tty) |
| + fprintf(fp, "\e[m"); |
| + fprintf(fp, "\n"); |
| +} |
| |
| /* Main program */ |
| |
| @@ -372,6 +372,7 @@ Py_Main(int argc, char **argv) |
| _Py_QnewFlag = 1; |
| break; |
| } |
| + deprecate_warn(stderr); |
| fprintf(stderr, |
| "-Q option should be `-Qold', " |
| "`-Qwarn', `-Qwarnall', or `-Qnew' only\n"); |
| @@ -458,14 +459,19 @@ Py_Main(int argc, char **argv) |
| } |
| } |
| |
| - if (help) |
| + if (help) { |
| + deprecate_warn(stderr); |
| return usage(0, argv[0]); |
| + } |
| |
| if (version) { |
| + deprecate_warn(stdout); |
| fprintf(stderr, "Python %s\n", PY_VERSION); |
| return 0; |
| } |
| |
| + deprecate_warn(stderr); |
| + |
| if (Py_Py3kWarningFlag && !Py_TabcheckFlag) |
| /* -3 implies -t (but not -tt) */ |
| Py_TabcheckFlag = 1; |