#!/usr/bin/python -i
"""
Copyright (C) 2005 SAMPO.
Data analysis project of European Southern  Observatory (ESO) 
See LICENSE.txt in the docs directory of the source distribution for the 
terms of use.

Usage: pymidas [options] 

Options:
  
  -d  Debug
  -s  Socket connection
  -f  Files connection
  -m  MIDAS mimic

  -h  Print this message

Long versions of options:
  -d  --debug
  -s  --socket
  -f  --files
  -m  --mimic
  -h  --help
  
"""

# $Id: pymidas,v 0.2 2005/3/06  $
#
# Original R White, 2005 January 21
# Modified to Pymidas usage S. Maisala

import sys, os

# set search path to include directory above this script and current directory
# ... but do not want the pyraf package directory itself in the path, since
# that messes things up by allowing direct imports of midas submodules
# (bypassing the __init__ mechanism.)

# follow links to get to the real executable filename
executable = sys.argv[0]
while os.path.islink(executable):
    executable = os.readlink(executable)
midasDir = os.path.dirname(executable)
del executable
try:
    sys.path.remove(midasDir)
except ValueError:
    pass

absMidasDir = os.path.abspath(os.path.join(midasDir,'..'))
if absMidasDir not in sys.path: sys.path.insert(0, absMidasDir)
del absMidasDir, midasDir

if "." not in sys.path: sys.path.insert(0, ".")

# read the user's startup file (if there is one)

if os.environ.has_key("PYTHONSTARTUP") and \
                os.path.isfile(os.environ["PYTHONSTARTUP"]):
    execfile(os.environ["PYTHONSTARTUP"])

from pymidas import midas, __version__
#__version__ = '0.1'
doCmdline = 1 # We force to execute doCmdLine

logout = quit = exit = 'Use ".exit" to exit'

print "Pymidas", __version__, "Sampo Project, European Southern Observatory "
# just print first line of Python copyright (long in v2.0)
print "Python", sys.version.split()[0], sys.copyright.split('\n')[0]

if doCmdline:
    del doCmdline
    # Start up command line wrapper keeping definitions in main name space
    # Keep the command-line object in namespace too for access to history
    import pymidas.pycmdline
    _pycmdline = pymidas.pycmdline.PyCmdLine(locals=globals())

    _pycmdline.start()
else:
    del doCmdline
