#!/usr/bin/env python
############################################################################
#    Copyright (C) 2007 Cody Precord                                       #
#    cprecord@editra.org                                                   #
#                                                                          #
#    Editra is free software; you can redistribute it and#or modify        #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation; either version 2 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    Editra is distributed in the hope that it will be useful,             #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program; if not, write to the                         #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

"""
#--------------------------------------------------------------------------#
# FILE:	Editra						   
# AUTHOR: Cody Precord
# LANGUAGE: Python							   
# SUMMARY:
#    Editor Launcher
#
#--------------------------------------------------------------------------#
"""

__author__ = "Cody Precord <cprecord@editra.org>"
__cvsid__ = "$Id: Exp $"
__revision__ = "$Revision:  $"

#--------------------------------------------------------------------------#
# Dependancies
import sys
import os
try:
    import src as esrc
except ImportError:
    try:
        import Editra.src as esrc
    except ImportError, msg:
        print "There was an error while tring to import Editra"
        print ("Make sure that Editra is on your PYTHONPATH and that "
               "you have wxpython installed.")
        print "ERROR MSG: "
        print str(msg)
        exit()

#--------------------------------------------------------------------------#
# XXX plugins need to have the import paths of the libraries they use taken
#     care of in someway to allow for them to work regardless of where the
#     application is executed from.
#
#     i.e  from Editra/Editra (this script), or from Editra/src/Editra.py
#
#     For them to work from this script they need to import relative to this
#     script. (import src.plugin) as apposed to (import plugin), but visa versa
#     is required for the other main script. This is further complicated by the
#     fact that the location of this script is never guaranteed. If there is 
#     anyone that has a more clever way to deal with this I would like to 
#     listen.
#
# XXX Note for this to work the version of python on the path must be the one
#     that has all of Editra's dependancies installed on.
if __name__ == '__main__':
    SRC_DIR = os.path.dirname(esrc.__file__)
    CWD = os.getcwd()
    try:
        os.chdir(SRC_DIR)
    except OSError:
        print ("There was a problem finding the main script,"
              " try running Editra.py in the src dir")
    else:
        ARGS = u''
        if len(sys.argv) > 1:
            ARGS = " ".join(sys.argv[1:])
        RES = os.system("python Editra.py --oldPath=\"" + CWD + "\" " + ARGS)
        exit(RES)
