
"""pygtk is now installed on your machine.

Local configuration files were successfully updated."""

import os, os.path, re, sys
import distutils.sysconfig
import distutils.file_util
import distutils.errors

pkgconfig_file = os.path.normpath(
    os.path.join(sys.prefix,
                 'lib/pkgconfig/pygtk-2.0.pc'))

prefix_pattern=re.compile("^prefix=.*")
exec_pattern=re.compile("^exec\s.*")
codegendir_pattern=re.compile("^codegendir=.*")
version_pattern=re.compile("Version: ([0-9]+\.[0-9]+\.[0-9]+)")

def replace_prefix(s):
    if prefix_pattern.match(s):
        s='prefix='+sys.prefix.replace("\\","/")+'\n'
    if exec_pattern.match(s):
        s=('exec '+sys.prefix+'\\python.exe '+
           '$codegendir/codegen.py \"$@\"\n').replace("\\","/")
    if codegendir_pattern.match(s):
        s=('codegendir='
           +distutils.sysconfig.get_python_lib().replace("\\","/")+
           '/gtk-2.0/codegen' + '\n')
    return s

def get_doc_url(pkgconfig_file, base_url):
    try:
        f = open(pkgconfig_file).read()
        ver = version_pattern.search(f).groups()[0]
        majv,minv,micv = ver.split('.')
        doc_url = "%s/%s.%s/" % (base_url,majv,minv)
    except:
        doc_url = base_url + "/stable/"
    return doc_url

# TODO : Check that shortcuts are created system-wide when the user
# has admin rights (hint: see pywin32 postinstall)
def create_shortcuts():
    progs_folder= get_special_folder_path("CSIDL_COMMON_PROGRAMS")
    site_packages_dir = os.path.join(sys.prefix , 'lib','site-packages')
   
    pygtk_shortcuts = os.path.join(progs_folder, 'PyGTK')
    if not os.path.isdir(pygtk_shortcuts):
        os.mkdir(pygtk_shortcuts)

    # link to specific documentation version by parsing the
    # pkgconfig file
    doc_url = get_doc_url(pkgconfig_file,
                          "http://library.gnome.org/devel/pygtk")
    pygtk_doc_link=os.path.join(pygtk_shortcuts,
                                    'PyGTK Documentation.lnk')
    if os.path.isfile(pygtk_doc_link):   
        os.remove(pygtk_doc_link)
    create_shortcut(doc_url,'PyGTK Documentation',pygtk_doc_link)
    file_created(pygtk_doc_link)
   
    homepage_link = os.path.join(pygtk_shortcuts,
                                 "PyGTK Home.lnk")
    if os.path.isfile(homepage_link):   
        os.remove(homepage_link)
    create_shortcut("http://www.pygtk.org",'PyGTK Homepage',homepage_link)
    file_created(homepage_link)

if len(sys.argv) == 2:
    if sys.argv[1] == "-install":
        # fixup the pkgconfig file
        lines=open(pkgconfig_file).readlines()
        open(pkgconfig_file, 'w').writelines(map(replace_prefix,lines))
        # TODO: Add an installer option for shortcut creation 
        # create_shortcuts()
        print __doc__


@@ -940,1502 +940,8 @@
  s%0A%0A
-def get_doc_url(pkgconfig_file, base_url):%0A    try:%0A        f = open(pkgconfig_file).read()%0A        ver = version_pattern.search(f).groups()%5B0%5D%0A        majv,minv,micv = ver.split('.')%0A        doc_url = %22%25s/%25s.%25s/%22 %25 (base_url,majv,minv)%0A    except:%0A        doc_url = base_url + %22/stable/%22%0A    return doc_url%0A%0A# TODO : Check that shortcuts are created system-wide when the user%0A# has admin rights (hint: see pywin32 postinstall)%0Adef create_shortcuts():%0A    progs_folder= get_special_folder_path(%22CSIDL_COMMON_PROGRAMS%22)%0A    site_packages_dir = os.path.join(sys.prefix , 'lib','site-packages')%0A   %0A    pygtk_shortcuts = os.path.join(progs_folder, 'PyGTK')%0A    if not os.path.isdir(pygtk_shortcuts):%0A        os.mkdir(pygtk_shortcuts)%0A%0A    # link to specific documentation version by parsing the%0A    # pkgconfig file%0A    doc_url = get_doc_url(pkgconfig_file,%0A                          %22http://library.gnome.org/devel/pygtk%22)%0A    pygtk_doc_link=os.path.join(pygtk_shortcuts,%0A                                    'PyGTK Documentation.lnk')%0A    if os.path.isfile(pygtk_doc_link):   %0A        os.remove(pygtk_doc_link)%0A    create_shortcut(doc_url,'PyGTK Documentation',pygtk_doc_link)%0A    file_created(pygtk_doc_link)%0A   %0A    homepage_link = os.path.join(pygtk_shortcuts,%0A                                 %22PyGTK Home.lnk%22)%0A    if os.path.isfile(homepage_link):   %0A        os.remove(homepage_link)%0A    create_shortcut(%22http://www.pygtk.org%22,'PyGTK Homepage',homepage_link)%0A    file_created(homepage_link)%0A
 %0Aif 
@@ -1152,100 +1152,8 @@
 s))%0A
-        # TODO: Add an installer option for shortcut creation %0A        # create_shortcuts()%0A
     

remove shortcut creation