#!/usr/bin/env python
license_string="""
    LUCI is an Univeral Configuration Interface
    Copyright  1999-2001 Jrme SAUTRET <Jerome.Sautret@netcourrier.com>

    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 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 General Public License
    along with this program; see the file COPYING.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
"""

VERSION="0.2.2"

copyright_string="""
    Copyright  1999-2001 Jrme SAUTRET <Jerome.Sautret@netcourrier.com>
    There is NO warranty.  You may redistribute this software
    under the terms of the GNU General Public License.
    For more information about these matters, type 'luci --license'
    or see the file named COPYING.
"""

usage_string="""
Usage:
luci [options] [description_file]

If no desc file is given, the navigator will be run.
 -h|--help     this help message
 -v|--version  display the current version of the program
 --license     display information about the license
 -d|--descdir  description files directory (default to /etc/luci)
 -f|--force    don't ask for confirmation for creating a new config file
"""

luci_module_path='/usr/local/lib/luci'

# import Python modules
import sys, getopt

# gui module is imported later when needed.

sys.path.append(luci_module_path)

debug=0


def display_version():
    print
    print "   LUCI version",VERSION
    print copyright_string
    raise SystemExit, 0

def display_usage():
    print usage_string
    raise SystemExit, 1

def display_license():
    print license_string
    raise SystemExit, 0

def init(argv):
    """
    Init the global params
    
    params:
      argv: command line
    return:
      dict of param/value

    """
    params={}
    params['desc_dir']='/etc/luci'
    params['luci_version']=VERSION
    try:
        optlist, args = getopt.getopt(argv[1:], 'hvfd:',
                                      ['force', 'descdir=', 'version',
                                       'help', 'license'])
    except getopt.error:
        usage()
    for i in optlist: 
        if i == ('--force','') or i == ('-f',''):
            params['param_force']='yes'
        elif i[0] == '--descdir' or i[0] == '-d':
            params['desc_dir']=i[1]
        elif i == ('--help','') or i == ('-h',''):
            display_usage()
        elif i == ('--version','') or i == ('-v',''):
            display_version()
        elif i == ('--license',''):
            display_license()
    try:
        params['desc_file_name']=args[0]
        return params
    except IndexError:
        return params

config={}
config.update(init(sys.argv))

# import luci module
import gui  # imported here because we don't need to initialize GTK before.

gui.main_window(config)
gui.main()
