Skip to content
hashstat edited this page May 26, 2015 · 1 revision
# OpenEmbedded sitecustomize.py (C) 2002-2008 Michael 'Mickey' Lauer <[email protected]>
# GPLv2 or later
# Version: 20081123
# Features:
# * set proper default encoding
# * enable readline completion in the interactive interpreter
# * load command line history on startup
# * save command line history on exit


'''Use readline to make the interactive interpreter more friendly.

The readline module should only be imported in interactive mode because
it has side-effects which may interfere with the output of scripts. But
because sitecustomize is executed at such an early stage of Python
initialization it cannot determine if Python is executed interactively.
Therefore, this script injects itself as the PYTHONSETUP script where
interactivity can be determined. The PYTHONSETUP environment is first
saved in the environment so it can later be restored. Then, PYTHONSETUP
is set to this script. After executing this script as the PYTHONSETUP
script, the original PYTHONSETUP, script is restored and, if set, is
exectuted.
'''


def main():
    '''This function wraps up the script to keep the environment clean.'''

    import os

    def __exithandler():
        try:
            readline.write_history_file( "%s/.python-history" % os.getenv( "HOME", "/tmp" ) )
        except IOError:
            pass

    def __registerExitHandler():
        import atexit
        atexit.register( __exithandler )

    def __enableReadlineSupport():
        readline.set_history_length( 1000 )
        readline.parse_and_bind( "tab: complete" )
        try:
            readline.read_history_file( "%s/.python-history" % os.getenv( "HOME", "/tmp" ) )
        except IOError:
            pass

    def __enableDefaultEncoding():
        import sys
        try:
            sys.setdefaultencoding( "utf8" )
        except LookupError:
            pass

    def __execPythonStartup():
        try:
            filename = os.environ.pop('__PYTHONSTARTUP__')
        except KeyError:
            os.environ.pop('PYTHONSTARTUP', None)
        else:
            os.environ['PYTHONSTARTUP'] = filename
            if filename:
                execfile(filename)

    def __savePythonStartup():
        try:
            os.environ['__PYTHONSTARTUP__'] = os.environ['PYTHONSTARTUP']
        except KeyError:
            pass
        os.environ['PYTHONSTARTUP'] = __file__


    if __name__ == '__main__':
        # Executing as PYTHONSETUP script
        try:
            import rlcompleter, readline
        except ImportError:
            pass
        else:
            __registerExitHandler()
            __enableReadlineSupport()
        __execPythonStartup()
    else:
        # Executing as sitecustomize
        __enableDefaultEncoding()
        __savePythonStartup()

main()
del main

Wiki Home

Quick Start Guide

Getting VOLTTRON

VOLTTRON Community

VOLTTRON Core Services

Historians

Drivers

Instance Management

Applications
  • ...
Examples
Developers
HOWTOS

VOLTTRON Versions and Features

Transactional Network Platform Overview

Platform Services

Volttron Restricted

Information Exchange Standards

FAQ

Project Home

Clone this wiki locally