#!/usr/bin/env python
#
# Copyright (C) 2004,2005 by SICEm S.L.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2
# 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 Lesser 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 sys
import os
import os.path

import pygtk 
pygtk.require('2.0')
import gtk

# put gazpacho in sys.path so we don't need to update PYTHONPATH
currentdir = os.path.dirname(os.path.abspath(sys.argv[0]))
prefix = os.path.abspath(os.path.join(currentdir, '..'))
localmode = False
if 'setup.py' in os.listdir(prefix):
    if prefix not in sys.path:
        sys.path.insert(0, prefix)
    localmode = True
else:
    major, minor = sys.version_info[0], sys.version_info[1]
    dir = os.path.join(prefix, 'lib', 'python%d.%d' % (major, minor),
                       'site-packages')
    if dir not in sys.path:
        sys.path.append(dir)

if gtk.pygtk_version < (2,4,0):
    print 'PyGTK 2.4.0 or later required for Gazpacho'
    raise SystemExit

if localmode:
    if os.path.exists(os.path.join(prefix, 'gazpacho', 'path.py')):
        from gazpacho import path
        path.xml_dir = os.path.join(prefix, 'xml')
        path.pixmaps_dir = os.path.join(prefix, 'pixmaps')
        path.languages_dir = os.path.join(prefix, 'locale')
    else:
        print 'Generating the path.py file ... ',
        fd = file (os.path.join(prefix, 'gazpacho', 'path.py'), 'w')
        fd.write('pixmaps_dir = r"%s"\n' % os.path.join(prefix, 'pixmaps'))
        fd.write('languages_dir = r"%s"\n' % os.path.join(prefix, 'locale'))
        fd.write('catalogs_dir = r"%s"\n' % os.path.join(prefix, 'catalogs'))
        fd.close()
        print 'done'

from gazpacho.main import main

if __name__ == '__main__':
    sys.exit(main(sys.argv))
