#!/usr/bin/python3 -s -u

### Command-line version of StoryText

import os, sys

install_root = os.path.dirname(os.path.dirname(os.path.normpath(os.path.realpath(os.path.abspath(sys.argv[0])))))
# Find our own "lib" directory
sys.path.insert(0, os.path.join(install_root, "lib"))

def removeSelfFromPath():
   # On Windows, this file is storytext.py, which means it can get imported!
   # Remove ourselves and cause a reimport in this case
   binDir = os.path.normpath(os.path.dirname(os.path.abspath(__file__))).replace("/", "\\")
   for path in sys.path:
      if binDir == os.path.normpath(path).replace("/", "\\"):
         sys.path.remove(path)
         break

if os.name == "nt":
   removeSelfFromPath()

if __name__ == "__main__":
    from storytext.cmdline import main
    main(install_root)
else:
   del sys.modules["storytext"]
   from storytext import *

