Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still can't pipe console output (#1065 not fixed) #1072

Closed
3 tasks done
dragontamer8740 opened this issue Jan 17, 2022 · 5 comments
Closed
3 tasks done

Still can't pipe console output (#1065 not fixed) #1072

dragontamer8740 opened this issue Jan 17, 2022 · 5 comments

Comments

@dragontamer8740
Copy link
Contributor

dragontamer8740 commented Jan 17, 2022

This 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

  1. $ 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.

@biggestsonicfan
Copy link
Contributor

Can confirm on my system python3 PixivUtil2.py --help | cat produces an identical error.

@dragontamer8740
Copy link
Contributor Author

dragontamer8740 commented Jan 29, 2022

Better fix: make the existing fix apply to all platforms instead of only Windows.

def set_console_title(title):
    try:
        if platform.system() == "Windows":
            subprocess.call('title' + ' ' + title, shell=True)
        else:
            sys.stdout.write(f'\33]0;{title}\a')
            sys.stdout.flush()
    except FileNotFoundError:
        print_and_log("error", f"Cannot set console title to {title}")
    except AttributeError:
        # Issue #1065
        pass

@Nandaka
Copy link
Owner

Nandaka commented Jan 29, 2022

can you raise a pull request?

@dragontamer8740
Copy link
Contributor Author

dragontamer8740 commented Feb 5, 2022

Pull request in #1082

@Nandaka Nandaka closed this as completed in dbe3e6b Feb 6, 2022
@Nandaka
Copy link
Owner

Nandaka commented Feb 6, 2022

merged :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants