#! /usr/bin/python
# $Id$
##
##  This file is part of pyFormex 0.9.1  (Tue Oct 15 21:05:25 CEST 2013)
##  pyFormex is a tool for generating, manipulating and transforming 3D
##  geometrical models by sequences of mathematical operations.
##  Home page: http://pyformex.org
##  Project page:  http://savannah.nongnu.org/projects/pyformex/
##  Copyright 2004-2013 (C) Benedict Verhegghe (benedict.verhegghe@ugent.be)
##  Distributed under the GNU General Public License version 3 or later.
##
##  This program 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 3 of the License, or
##  (at your option) any later version.
##
##  This program 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, see http://www.gnu.org/licenses/.
##
"""pyFormex, a free program for creating and manipulating 3D geometry.

pyFormex is a powerful tool for generating, manipulating, transforming and
displaying large structural models of 3D geometry.
Based on a powerful scripting language, pyFormex is exceptionally suited for
generating parametric models and for the automization of tedious and recurring
tasks in the handling of geometrical models.
Built around a fully open architecture pyFormex allows the user to combine the
program with nearly any other software and to extend the program to suit his
own needs.

pyFormex is being developed at the IBiTech, Ghent University, and can be
distributed under the GNU General Public License, version 3 or later.
(C) 2004-2012 Benedict Verhegghe (benedict.verhegghe@ugent.be))
"""

# Get the pyformex dir and put it on the head of sys.path
import sys,os
_bindir = sys.path[0]

# In case we execute the pyformex script from inside the
# pyformex package dir: add the parent to the front of sys.path
# to pick up the package here instead of from default path

if _bindir.endswith('pyformex'):
    sys.path[:0] = [ os.path.dirname(_bindir) ]

try:
    import pyformex
except:
    print("Could not import pyformex.")
    print("This probably means that pyFormex was not properly installed.")
    raise

# Remember where we got started
pyformex.bindir = _bindir

# Installation type. Should be one of:
# 'R(elease)': installed from a released tarball with the included install
#              procedure. This is the default.
# 'S(ource)' : running directly from the checked out source tree. This is set
#              during startup after detection.
# 'D(istribution)': installed from a distribution package. The packager should
#                   set this to 'D' before packaging the files.
pyformex.installtype = 'R'

# Put the pyformex module path in front to avoid picking up modules
# from other packages installed next to pyformex.
pyformex_path = pyformex.__path__[0]

if pyformex_path == _bindir:
    # pyformex path is second, its parent is first: exchange the two
    sys.path[:2] = sys.path[1::-1]
else:
    # pointless _bindir parent is first: it can be removed
    # pyformex path is not there: add it at the front
    # so, just overwrite first path
    sys.path[0] = pyformex_path

TEST=0
if len(sys.argv) > 1:
    if sys.argv[1] == "--testpyf":
        from pyformex.main import run
        TEST=1
    elif sys.argv[1] == "--testnopyf":
        from main import run
        TEST=2
if TEST:
    for m in sys.modules:
        try:
            print "MODULE %s: %s" % (m,sys.modules[m].__path__)
        except:
            print "MODULE %s: " % (m)
    sys.exit()

if __name__ == "__main__":
    from main import run
    sys.exit(run(sys.argv[1:]))

# End
