I am attempting to run a program which uses TTYColoredFormatter from colorlog. This class formats log messages, adding ANSI escape codes only if the stream it is writing to returns True for stream.isatty().
Unfortunately, python-for-android's bootstrap code replaces sys.stderr and sys.stdout with a custom LogFile object:
|
PyRun_SimpleString( |
|
"class LogFile(object):\n" |
|
" def __init__(self):\n" |
|
" self.__buffer = ''\n" |
|
" def write(self, s):\n" |
|
" s = self.__buffer + s\n" |
|
" lines = s.split('\\n')\n" |
|
" for l in lines[:-1]:\n" |
|
" androidembed.log(l.replace('\\x00', ''))\n" |
|
" self.__buffer = lines[-1]\n" |
|
" def flush(self):\n" |
|
" return\n" |
|
"sys.stdout = sys.stderr = LogFile()\n" |
|
"print('Android path', sys.path)\n" |
|
"import os\n" |
|
"print('os.environ is', os.environ)\n" |
|
"print('Android kivy bootstrap done. __name__ is', __name__)"); |
This object doesn't implement isatty() (or much else, for that matter). As a result, the program raises an exception:
03-03 13:32:56.222 5806 5891 I python : Traceback (most recent call last):
03-03 13:32:56.222 5806 5891 I python : File "/home/jenkins/workspace/kolibri-installer-android-pr/src/main.py", line 3, in <module>
03-03 13:32:56.222 5806 5891 I python : File "/home/jenkins/workspace/kolibri-installer-android-pr/src/kolibri_android/main_activity/__main__.py", line 7, in main
03-03 13:32:56.222 5806 5891 I python : File "/home/jenkins/workspace/kolibri-installer-android-pr/src/kolibri_android/main_activity/activity.py", line 19, in <module>
03-03 13:32:56.222 5806 5891 I python : File "/home/jenkins/workspace/kolibri-installer-android-pr/src/kolibri_android/kolibri_utils.py", line 13, in <module>
03-03 13:32:56.223 5806 5891 I python : File "/home/jenkins/workspace/kolibri-installer-android-pr/src/kolibri_android/android_whitenoise.py", line 11, in <module>
03-03 13:32:56.223 5806 5891 I python : File "/home/jenkins/workspace/kolibri-installer-android-pr/src/kolibri/__init__.py", line 10, in <module>
03-03 13:32:56.223 5806 5891 I python : File "/home/jenkins/workspace/kolibri-installer-android-pr/src/kolibri/utils/env.py", line 29, in <module>
03-03 13:32:56.223 5806 5891 I python : File "/home/jenkins/workspace/kolibri-installer-android-pr/src/kolibri/dist/colorlog/colorlog.py", line 203, in __init__
03-03 13:32:56.223 5806 5891 I python : AttributeError: 'LogFile' object has no attribute 'isatty'
(For reference, we're using colorlog v3.2.0, so the code raising the exception looks like this: https://github.com/borntyping/python-colorlog/blob/v3.2.0/colorlog/colorlog.py#L191-L211).
I am attempting to run a program which uses
TTYColoredFormatterfrom colorlog. This class formats log messages, adding ANSI escape codes only if the stream it is writing to returnsTrueforstream.isatty().Unfortunately, python-for-android's bootstrap code replaces sys.stderr and sys.stdout with a custom
LogFileobject:python-for-android/pythonforandroid/bootstraps/common/build/jni/application/src/start.c
Lines 226 to 242 in 53d77fc
This object doesn't implement
isatty()(or much else, for that matter). As a result, the program raises an exception:(For reference, we're using colorlog v3.2.0, so the code raising the exception looks like this: https://github.com/borntyping/python-colorlog/blob/v3.2.0/colorlog/colorlog.py#L191-L211).