home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-python-addon-1.4.9-installer.exe / win32_postinstall.py < prev    next >
Encoding:
Python Source  |  2004-03-05  |  4.8 KB  |  131 lines

  1.  # Copyright 2004 Apache Software Foundation
  2.  #
  3.  #  Licensed under the Apache License, Version 2.0 (the "License");
  4.  #  you may not use this file except in compliance with the License.
  5.  #  You may obtain a copy of the License at
  6.  #
  7.  #      http://www.apache.org/licenses/LICENSE-2.0
  8.  #
  9.  #  Unless required by applicable law or agreed to in writing, software
  10.  #  distributed under the License is distributed on an "AS IS" BASIS,
  11.  #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12.  #  See the License for the specific language governing permissions and
  13.  #  limitations under the License.
  14.  #
  15.  # Originally developed by Gregory Trubetskoy.
  16.  #
  17.  # $Id: win32_postinstall.py,v 1.5 2004/02/16 19:47:27 grisha Exp $
  18.  #
  19.  # this script runs at the end of windows install
  20.  
  21.  
  22. import sys, os, shutil
  23. import distutils.sysconfig
  24.  
  25. def getApacheDirOptions():
  26.     """find potential apache directories in the registry..."""
  27.     try:
  28.         import win32api, win32con
  29.         class regkey:
  30.             """simple wrapper for registry functions that closes keys nicely..."""
  31.             def __init__(self, parent, subkeyname):
  32.                  self.key = win32api.RegOpenKey(parent, subkeyname)
  33.             def childkey(self, subkeyname):
  34.                  return regkey(self.key, subkeyname)
  35.             def subkeynames(self):
  36.                  numsubkeys = win32api.RegQueryInfoKey(self.key)[0]
  37.                  return [win32api.RegEnumKey(self.key, index) for index in range(numsubkeys)]
  38.             def getvalue(self, valuename):
  39.                  return win32api.RegQueryValueEx(self.key, valuename)
  40.             def __del__(self):
  41.                  win32api.RegCloseKey(self.key)
  42.     except ImportError:
  43.         return {}
  44.     versions = {}
  45.     apachekey = regkey(win32con.HKEY_LOCAL_MACHINE, "Software").childkey("Apache Group").childkey("Apache")
  46.     for versionname in apachekey.subkeynames():
  47.         serverroot = apachekey.childkey(versionname).getvalue("ServerRoot")
  48.         versions[versionname] = serverroot[0]
  49.     return versions
  50.  
  51. def askForApacheDir(apachediroptions):
  52.     # try to ask for Apache directory
  53.     if len(apachediroptions) > 0:
  54.         # get the most recent version...
  55.         versionnames = apachediroptions.keys()
  56.         versionnames.sort()
  57.         initialdir = apachediroptions[versionnames[-1]]
  58.     else:
  59.         initialdir="C:/Program Files/Apache Group/Apache2"
  60.     # TODO: let the user select the name from a list, or click browse to choose...
  61.     try:
  62.         from tkFileDialog import askdirectory
  63.         from Tkinter import Tk
  64.         root = Tk()
  65.         root.withdraw()
  66.         path = askdirectory(title="Where is Apache installed?",
  67.                             initialdir=initialdir,
  68.                             mustexist=1, master=root)
  69.         root.quit()
  70.         root.destroy()
  71.         return path
  72.     except ImportError:
  73.         try:
  74.             from win32com.shell import shell
  75.             pidl, displayname, imagelist = shell.SHBrowseForFolder(0, None, "Where is Apache installed?")
  76.             path = shell.SHGetPathFromIDList(pidl)
  77.             return path
  78.         except ImportError:
  79.             return ""
  80.  
  81. # if we're called during removal, just exit
  82. if len(sys.argv) == 0 or sys.argv[1] != "-remove":
  83.  
  84.     mp = os.path.join(distutils.sysconfig.get_python_lib(), "mod_python_so.pyd")
  85.  
  86.     apachediroptions = getApacheDirOptions()
  87.  
  88.     apachedir = askForApacheDir(apachediroptions)
  89.  
  90.     if apachedir:
  91.  
  92.         # put mod_python.so there
  93.         shutil.copy2(mp, os.path.join(apachedir, "modules", "mod_python.so"))
  94.         os.remove(mp)
  95.  
  96.         print """Important Note for Windows users, PLEASE READ!!!
  97.  
  98.         1. This script does not attempt to modify Apache configuration,
  99.            you must do it manually:
  100.  
  101.            Edit %s,
  102.            find where other LoadModule lines are and add this:
  103.                 LoadModule python_module modules/mod_python.so
  104.  
  105.         2. Now test your installation using the instructions at this link:
  106.            http://www.modpython.org/live/current/doc-html/inst-testing.html
  107.  
  108.         """ % os.path.join(apachedir, "conf", "httpd.conf")
  109.  
  110.     else:
  111.  
  112.         print """Important Note for Windows users, PLEASE READ!!!
  113.  
  114.         1. It appears that you do not have Tkinter installed,
  115.            which is required for a part of this installation.
  116.            Therefore you must manually take
  117.            "%s"
  118.            and copy it to your Apache modules directory.
  119.  
  120.         2. This script does not attempt to modify Apache configuration,
  121.            you must do it manually:
  122.  
  123.            Edit %s,
  124.            find where other LoadModule lines and add this:
  125.                 LoadModule python_module modules/mod_python.so
  126.  
  127.         3. Now test your installation using the instructions at this link:
  128.            http://www.modpython.org/live/current/doc-html/inst-testing.html
  129.  
  130.         """ % (mp, os.path.join(apachedir, "conf", "httpd.conf"))
  131.