Still can't pipe console output (#1065 not fixed)
See original GitHub issueThis is basically re-opening #1065; the patch in 28a9895 did not fix the problem.
Prerequisites
- Did you read FAQ section in readme.md?
- Did you test with the latest releases or commit ? (Yes, git master)
- Did you search for existing issues in Issues?
Description
AttributeError: 'NoneType' object has no attribute 'set_title'
.
The patch that closed #1065 did not actually fix the issue.
Steps to Reproduce
$ PixivUtil2 --help |cat
(on Unix)
Expected behavior: help text should print to standard output.
Actual behavior:
Traceback (most recent call last):
File "/home/fake-user-name/bin/PixivUtil2", line 1566, in <module>
main()
File "/home/fake-user-name/bin/PixivUtil2", line 1359, in main
set_console_title()
File "/home/fake-user-name/bin/PixivUtil2", line 1044, in set_console_title
PixivHelper.set_console_title(set_title)
File "/home/fake-user-name/development/PixivUtil2/PixivHelper.py", line 389, in set_console_title
sys.stdout.write(f'\33]0;{title}\a')
File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 41, in write
self.__convertor.write(text)
File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 162, in write
self.write_and_convert(text)
File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 184, in write_and_convert
text = self.convert_osc(text)
File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 256, in convert_osc
winterm.set_title(params[1])
AttributeError: 'NoneType' object has no attribute 'set_title'
Also, you have embedded xterm-specific escape sequences into the program. These sequences do not render correctly on anything but xterm. A real VT100 or VT220, or any number of other terminals, would exhibit undefined behavior.
Log file: [Attach the pixivutil.log
file in the application folder, recommended to delete the old file, reproduce the issue, and upload the newly generated file here]
Log file is blank.
Versions
Git master. Commit 3495f52.
PixivDownloader2 version 20211104
Changing the function to:
def set_console_title(title):
if platform.system() == "Windows":
try:
subprocess.call('title' + ' ' + title, shell=True)
except FileNotFoundError:
print_and_log("error", f"Cannot set console title to {title}")
except AttributeError:
# Issue #1065
pass
else:
if "xterm" in os.getenv("TERM"):
try:
sys.stdout.write(f'\33]0;{title}\a')
sys.stdout.flush()
except AttributeError:
pass
Fixes the issue, and also makes it only attempt to set the title string with xterm escape codes on xterm and similar terminals.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Can confirm on my system
python3 PixivUtil2.py --help | cat
produces an identical error.merged 😄