GithubHelp home page GithubHelp logo

Comments (4)

mmulqueen avatar mmulqueen commented on May 25, 2024

@satterly This seems to work for me now. The weird thing is that the new environmental variables you're checking are unset, but equally the problem has gone away with the latest version on git. So I think this may have created a new bug, which has accidentally masked the old bug for me.

I think your new if statement may not evaluate what you intended.

The current code is:

if not sys.stdin.isatty() and (os.environ.get('TERM', None) or os.environ.get('PS1', None)):

I read this as: It's not a TTY and it either TERM or PS1 is truthy.

not has a higher priority than and in Python. So if I put in some more brackets to clarify the order:

if (not sys.stdin.isatty()) and (os.environ.get('TERM', None) or os.environ.get('PS1', None)):

I think you were aiming for: It's not a tty and neither TERM or PS1 is truthy, which would be:

if not sys.stdin.isatty() and not (os.environ.get('TERM', None) or os.environ.get('PS1', None)):

Or equally and perhaps clearer:

if not (sys.stin.isatty() or os.environ.get('TERM', None) or os.environ.get('PS1', None)):

I'm not sure whether I've got the wrong end of the stick or not here. If I'm on the right lines, then by fixing this new bug, the old bug will reappear.

I'd like to suggest that the piping behaviour be disabled by default and enabled by it's own CLI option (e.g. --pipe-input json_lines). It looks like it's almost impossible to tell the difference between a job running a cron environment and a pipe.

from python-alerta-client.

satterly avatar satterly commented on May 25, 2024

not only applies to the first test (ie. the isatty() check) otherwise both these statements would give the same result...

>>> not True and False
False
>>> not (True and False)
True

What I'm checking for is ...

IF it does not have a TTY
    THEN it is either cron or data is being piped to stdin
    IF it is a terminal (ie. is `TERM` or `PS1` set?)
        THEN read data from stdin
ELSE
    assume it is a terminal console, or cron, and run send with command-line args

So I'm pretty sure this change works as intended but let me know if this still doesn't make sense.

from python-alerta-client.

mmulqueen avatar mmulqueen commented on May 25, 2024

@satterly My mistake. Fully understand why you've done this and how it works now. Bug indeed fixed and there is no new bug. Sorry about the false alarm!

from python-alerta-client.

satterly avatar satterly commented on May 25, 2024

No problem. It was good to clarify, in my own head, what was going on just to be sure.

from python-alerta-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.