#!/usr/bin/python
# Copyright (c) 2001-2003 Alexander Kanavin. All rights reserved.

"""
Contact info:
ak@sensi.org
"""

def checkenv():

    import sys,string
    ver = sys.version_info[0]*100+sys.version_info[1]*10+sys.version_info[2]
    if ver < 220:
        return """You're using an old version of Python interpreter (%s).
You should install Python 2.2.0 or newer.""" %(string.split(sys.version)[0])

    try:
	import pysoulseek
    except ImportError,e:
	return """Can not find PySoulSeek modules. 
Perhaps they're installed in a directory which is not 
in an interpreter's module search path. 
(there could be a version mismatch between 
what version of python was used to build the PySoulSeek 
binary package and what you try to run PySoulSeek with.)"""

    try:
	import wxPython.wx    	
    except:
	import sys
	return """Can not find wxPython modules. Either wxPython is not
installed, or it's not in Python's module search path (it could be built 
for a different version of python interpreter for example). The current 
search path is \n%s""" %(sys.path)

    major = wxPython.wx.wxMAJOR_VERSION
    minor = wxPython.wx.wxMINOR_VERSION
    rel = wxPython.wx.wxRELEASE_NUMBER

    oldwx = """You're using an old version of wxPython libraries (%i.%i.%i).
You should install wxPython 2.4.1 or newer.""" %(major,minor,rel)
    ver = major*100+minor*10+rel
    if ver < 241:
	return oldwx

    try:
	import ogg.vorbis
    except:
	print """You do not have Python Vorbis bindings installed. 
Others will not be able to see the lengths and the bitrates 
of Ogg Vorbis files that you share. Get binary RPMS from the pyslsk homepage 
or the source from http://www.andrewchatham.com/pyogg/. 
If you're using Debian, install the python-pyvorbis package."""
    return None

def usage():
    print """Usage: pyslsk [OPTION]...
  -c file,	--config=file	Use non-default configuration file
  -h,		--help		Display this help and exit

Report bugs to <ak@sensi.org>""" 	

if __name__ == '__main__':
    import sys, getopt, os.path
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hc:", ["help", "config="])
    except getopt.GetoptError:
        # print help information and exit:
        usage()
        sys.exit(2)

    config = os.path.join(os.path.expanduser("~"),'.pyslsk')
    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o in ("-c", "--config"):
            config = a
    result = checkenv()
    if result is None:
	from pysoulseek.wxgui import frame
	import locale
	try:
	    locale.setlocale(locale.LC_ALL, '')
	except:
	    print "Cannot set locale"
        app = frame.MainApp(config)
        app.MainLoop()
    else:
        print result
