#!/usr/bin/env python

'''
    Porthole
    A graphical frontend to Portage

    Copyright (C) 2003 - 2004 Fredrik Arnerup and Daniel G. Taylor

    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; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'''

# set data path for our glade and pixmap files
DATA_PATH = "/usr/share/porthole/"

# setup our path so we can load our custom modules
from sys import path
path.append('/usr/lib/porthole')

# Add path to portage module if 
# missing from path (ref bug # 924100)

PORTAGE_MOD_PATH = '/usr/lib/portage/pym'
try:
    path.index(PORTAGE_MOD_PATH) 
except ValueError:
    path.append(PORTAGE_MOD_PATH)

import utils
from sys import argv, exit, stderr
from mainwindow import MainWindow
import gtk
from getopt import getopt, GetoptError
from version import version

if __name__ == "__main__":
    try:
        opts, args = getopt(argv[1:], 'lvd', ["local", "version", "debug"])
    except GetoptError, e:
        print >>stderr, e.msg
        exit(1)
    for opt, arg in opts:
        if opt in ("-l", "--local"):
            # running a local version (i.e. not installed in /usr/*)
            from os import getcwd
            DATA_PATH = getcwd() + "/"
        elif opt in ("-v", "--version"):
            # print version info
            print "Porthole " + version
            exit(0)
        elif opt in ("-d", "--debug"):
            utils.debug = True
            utils.dprint("Debug printing is enabled")
    # make sure gtk lets threads run
    gtk.threads_init()
    # setup our app icon
    myicon = gtk.gdk.pixbuf_new_from_file(DATA_PATH + "pixmaps/porthole-icon.png")
    gtk.window_set_default_icon_list(myicon)
    # load prefs
    prefs = utils.PortholePreferences()
    prefs.DATA_PATH = DATA_PATH
    # load config info
    config = utils.PortholeConfiguration(DATA_PATH)
    # create the main window
    myapp = MainWindow(prefs, config)
    # start the program loop
    gtk.mainloop()
    # save the prefs to disk for next time
    prefs.save()
