blink 1.32 KB
Newer Older
Dan Pascu's avatar
Dan Pascu committed
1 2 3 4 5
#!/usr/bin/env python

import os
import sys

Dan Pascu's avatar
Dan Pascu committed
6
from application import log
Dan Pascu's avatar
Dan Pascu committed
7 8 9 10 11 12 13


def except_hook(exception_type, exception_value, traceback):
    sys.__excepthook__(exception_type, exception_value, traceback)

sys.excepthook = except_hook  # pyqt5 (>=5.5) will abort if an exception happens in python code when called from Qt, unless we define this

Dan Pascu's avatar
Dan Pascu committed
14 15
log.level.current = log.level.WARNING

Dan Pascu's avatar
Dan Pascu committed
16 17
frozen = hasattr(sys, 'frozen')

Dan Pascu's avatar
Dan Pascu committed
18 19
# We need to mangle Python's import path in case blink is run directly from
# the bin/ directory.
Dan Pascu's avatar
Dan Pascu committed
20
script_dir = os.path.dirname(os.path.realpath(sys.executable if frozen else __file__))
Dan Pascu's avatar
Dan Pascu committed
21
parent_dir = os.path.dirname(script_dir)
Dan Pascu's avatar
Dan Pascu committed
22
if os.path.basename(script_dir) == 'bin' and os.path.exists(os.path.join(parent_dir, 'blink', '__init__.py')):
Dan Pascu's avatar
Dan Pascu committed
23 24 25 26 27 28 29 30 31 32 33
    # 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)


Dan Pascu's avatar
Dan Pascu committed
34
if frozen:
Saul Ibarra's avatar
Saul Ibarra committed
35
    from StringIO import StringIO
36
    sys.stdout = sys.stderr = StringIO()
Saul Ibarra's avatar
Saul Ibarra committed
37 38


Dan Pascu's avatar
Dan Pascu committed
39 40 41 42 43
if __name__ == '__main__':
    from blink import Blink
    blink = Blink()
    blink.run()