blink 1018 Bytes
Newer Older
Dan Pascu's avatar
Dan Pascu committed
1 2 3 4 5 6 7
#!/usr/bin/env python

import os
import sys

# We need to mangle Python's import path in case blink is run directly from
# the bin/ directory.
8 9
script = globals().get('__file__', sys.argv[0])
script_dir = os.path.dirname(os.path.realpath(script))
Dan Pascu's avatar
Dan Pascu committed
10 11 12 13 14 15 16 17 18 19 20 21 22
parent_dir = os.path.dirname(script_dir)
if os.path.basename(script_dir)=='bin' and os.path.exists(os.path.join(parent_dir, 'blink', '__init__.py')):
    # Insert the parent path just before the existing script's path. We need
    # to do this in order to work with debuggers which insert their own paths
    # at the beginning. The script's path is the last Python itself inserted
    # so we should insert just before that.
    try:
        position = sys.path.index(script_dir)
    except ValueError:
        position = 0
    sys.path.insert(position, parent_dir)


Saul Ibarra's avatar
Saul Ibarra committed
23
if getattr(sys, 'frozen', False):
Saul Ibarra's avatar
Saul Ibarra committed
24
    from StringIO import StringIO
25
    sys.stdout = sys.stderr = StringIO()
Saul Ibarra's avatar
Saul Ibarra committed
26 27


Dan Pascu's avatar
Dan Pascu committed
28 29 30 31 32
if __name__ == '__main__':
    from blink import Blink
    blink = Blink()
    blink.run()