#!/usr/bin/python
### Copyright (C) 2007 Peter Williams <peter_ono@users.sourceforge.net>

### 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; version 2 of the License only.

### 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 sys, os, getopt

# read required directory from the command line

def usage():
    print "Usage: gwsmhg [dir]"

try:
    option_list, arg_list = getopt.getopt(sys.argv[1:], "")
except getopt.GetoptError, err:
    sys.stderr.write(str(err) + os.linesep)
    usage()
    sys.exit(1)

if len(arg_list) > 1:
    usage()
    sys.exit(1)

dir_specified = False

if len(arg_list) == 1:
    try:
        os.chdir(sys.argv[1])
        dir_specified = True
    except OSError, msg:
        sys.stderr.write(str(msg) + os.linesep)
        sys.exit(2)

from gwsmhg_pkg import ifce, hg_mq_ifce

ifce.init(hg_mq_ifce)

import gtk
from gwsmhg_pkg import gwsm

try:
    app = gwsm.gwsm(dir_specified)
    app.show()
    gtk.main()
except SystemExit:
    pass
except:
    from gwsmhg_pkg import dialogue
    dialogue.report_exception(sys.exc_info())
    sys.exit(3)
