Simfactory assumes python is python2

Issue #2058 closed
Steven R. Brandt created an issue

Simfactory assumes that python is python2. Until recently this seems to have been a valid assumption, but it is no longer so. The "sim" script needs to be updated to check the version of python before invoking any of the simfactory commands.

Keyword: newuser

Comments (12)

  1. Steven R. Brandt reporter
    • removed comment

    Based on conversations and emails, I think this is what we want.

    diff --git a/bin/sim b/bin/sim
    index 92f74ab..c6bc075 100755
    --- a/bin/sim
    +++ b/bin/sim
    @@ -20,4 +20,18 @@ if [ -z "$cmd" ]; then
     fi
    
     # Forward the call
    -exec python "$cmd" "$@"
    +for PYEXE in python python2
    +do
    +    $PYEXE - > /dev/null 2>&1 << EOF
    +import sys
    +if sys.hexversion < 0x3000000:
    +    exit(0)
    +else:
    +    exit(1)
    +EOF
    +    if [ $? = 0 ]
    +    then
    +        exec $PYEXE "$cmd" "$@"
    +        break
    +    fi
    +done
    
  2. Roland Haas
    • removed comment

    Since we are version testing, it would also make sense to put in a minimal accepted version (likely python 2.6 or 2.7) I think. The "break" should likely be replaced by an "exit $?" since "exec" can return to its caller (eg if redirection fails, but not if it fails to execute the program).

  3. Steven R. Brandt reporter
    • removed comment

    I don't want to pick an arbitrary minimum version. If you know of a version for which Simfactory doesn't then I'm all for setting one, otherwise I'd rather not. Using exits make some sense. Anyway, here's what I currently suggest.

    # Forward the call
    for PYEXE in python2 python
    do
        $PYEXE - > /dev/null 2>&1 << EOF
    import sys
    if sys.hexversion < 0x3000000:
        exit(0)
    else:
        exit(1)
    EOF
        if [ $? = 0 ] 
        then
            exec $PYEXE "$cmd" "$@"
            exit 1
        fi  
    done
    exit 2
    
  4. Erik Schnetter
    • removed comment

    Simfactory requires Python 2.3, since that was installed on Queen Bee at the time it was developed, and Queen Bee (at that time) had one of the oldest Red Hat versions. We might have switched to Python 2.6 in the mean time, either accidentally or on purpose, but I'd go with 2.3.

  5. Steven R. Brandt reporter
    • removed comment

    OK, then. Version 2.3 corresponds to 0x2030000.

    # Forward the call
    for PYEXE in python2 python
    do
        $PYEXE - > /dev/null 2>&1 << EOF
    import sys
    if sys.hexversion >= 0x2030000 and sys.hexversion < 0x3000000:
        exit(0)
    else:
        exit(1)
    EOF
        if [ $? = 0 ] 
        then
            exec $PYEXE "$cmd" "$@"
            exit 1
        fi  
    done
    exit 2
    
  6. Log in to comment