#!/usr/bin/python
# -*- Mode: Python; coding: iso-8859-1 -*-
# vi:si:et:sw=4:sts=4:ts=4

##
## Copyright (C) 2005 by Async Open Source 
##
## 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.
##
## Author(s):   Evandro Vale Miquelito      <evandro@async.com.br>
##              Johan Dahlin                <jdahlin@async.com.br>
##
"""
bin/stoq:

   Script to start application
"""

import os
import sys

# Required version of Python
REQUIRED_VERSION = (2, 4)

KIWI_REQUIRED = '1.9.2'

# Directory name, defaults to name of binary, it is relative to ..
# a, __init__.py and main.py is expected to be found there.
DIRNAME = None

# Application name, defaults to capitalized name of binary
APPNAME = None

# Do not modify code below this point
dirname = DIRNAME or os.path.split(sys.argv[0])[1]
appname = APPNAME or dirname.capitalize()

version_string = sys.version.split(' ')[0]
majmin = tuple(map(int, version_string.split('.')))
if majmin < REQUIRED_VERSION:
    raise SystemExit("ERROR: Python %s or higher is required to run %s, "
                     "%s found" % ('.'.join(map(str, REQUIRED_VERSION)),
                                   appname,
                                   version_string))

main_module = dirname + '.main'
try:
    from kiwi.environ import Application
except ImportError:
    raise SystemExit("Could not find kiwi, is a recent version %s installed?"
                      % KIWI_REQUIRED)

app = Application('stoq', path='stoq.main')
if app.uninstalled:
    app.add_global_resource('pixmaps', 'pixmaps')
    
    # Add stoq/gui/*/glade, perhaps we should move this into environ itself
    root = os.path.join(app.get_root(), 'stoq', 'gui')
    for name in os.listdir(root):
        dir = os.path.join(root, name, 'glade')
        if not os.path.isdir(dir):
            continue
        app.add_global_resource('glade', dir)
        
    app.add_resources(locale='locale',
                      basedir='.',
                      docs='docs')
app.enable_translation()
app.run()
try:
    sys.exit(main(sys.argv))
except KeyboardInterrupt:
    raise SystemExit
