#!/usr/local/bin/python2.5
# -*- python-mode -*-
"""Takes care of starting the main function
"""

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

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

def cola_init():
    """Provides access to the cola modules"""
    # 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 = os.path.dirname(os.path.abspath(__file__))
    if 'Contents/Resources' not in __file__:
        prefix = os.path.dirname(prefix)

    # Look for modules in the source and install trees
    paths_to_try = [prefix, os.path.join(prefix, 'share', 'git-cola', 'lib')]
    actual_paths = [p for p in paths_to_try if os.path.exists(p)]
    sys.path = actual_paths + sys.path

    import cola.resources

    # Setup the path so that git finds us when we run 'git cola'
    path_entries = os.environ.get('PATH').split(os.pathsep)
    bindir = os.path.dirname(os.path.abspath(__file__))
    path_entries.insert(0, bindir)
    path = os.pathsep.join(path_entries)
    os.environ['PATH'] = path
    os.putenv('PATH', path)


if __name__ == '__main__':
    # lights, cameras, action
    cola_init()
    import cola.main
    cola.main.main()
