#! /usr/bin/env python
import os
import sys
import optparse
import gtk


#find src path
bin_path = os.path.dirname(os.path.abspath(__file__))
if bin_path != "/usr/bin":
    sys.path.append(os.path.join(bin_path, "mtplastfm"))
    UI_DIR = os.path.join(bin_path, "glade")
else:
    UI_DIR = os.path.join("/usr", "share", "mtp-lastfm")
    
from mtplastfm import localisation
_ = localisation.set_get_text()
from mtplastfm.main import MTPLastfmGTK

__author__ = ("Daniel Woodhouse","Saku Laukkanen")
__version__ = "0.82.3"

parser = optparse.OptionParser(version="mtp-lastfm %s by %s" % (
    __version__,', '.join(__author__)))
parser.add_option('--error-log', '-e', action="store_true",
                  help=_("logs all stderr messages to ~/.mtp-lastfm/error.log")) 
parser.add_option('--test-mode', '-t', action="store_true",
                  help=_("disables connections to last.fm for offline debugging"))
options, args = parser.parse_args()

HOME_DIR = os.path.join(os.environ['HOME'], ".mtp-lastfm") + os.sep
try:
    os.mkdir(HOME_DIR)
except OSError:
    pass

if options.error_log:
    log_file = HOME_DIR + "errors.log"
    sys.stderr = open(log_file, 'a')
    print _('Error messages will be logged in %s') % log_file

GLADE = {"path" : UI_DIR + os.sep}
for glade_file in ["gui", "log", "tag"]:
    GLADE[glade_file] = os.path.join(UI_DIR, glade_file + ".glade")

mtp = MTPLastfmGTK(__author__, __version__, HOME_DIR, GLADE,
                   test_mode=options.test_mode)
gtk.main()


