#!/usr/bin/env python
# -*- python-mode -*-
"""Takes care of starting the main function
"""

__copyright__ = """
Copyright (C) 2008, David Aguilar <davvid@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.

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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""

import os
import sys

# Put sys.path[0] in our path so that we can find our custom git-* commands
path_entries = os.getenv('PATH', '').split(os.pathsep)
if sys.path[0] not in path_entries:
    path_entries.insert(0, sys.path[0])
    path = os.pathsep.join(path_entries)
    os.environ['PATH'] = path

# Try to detect where it is run from and set prefix and the search path.
# It is assumed that the user installed Cola using the --prefix= option
prefix, bin = os.path.split(sys.path[0])

# Scripts is win32
if bin in ('bin', 'Scripts') and prefix != sys.prefix:
    sys.prefix = prefix
    sys.exec_prefix = prefix

    paths_to_try = [
        os.path.join(prefix, 'lib', 'python2.6', 'site-packages'),
        os.path.join(prefix, 'lib', 'python2.5', 'site-packages'),
        os.path.join(prefix, 'lib', 'python2.4', 'site-packages'),
        prefix,
        os.getcwd(),
        ]

    local_path = [p for p in paths_to_try if os.path.exists(p)]
    sys.path = local_path + sys.path

from cola.main import main

if __name__ == '__main__':
    main()
