You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2004/04/30 21:35:37 UTC
cvs commit: httpd-python/dist win32_postinstall.py
grisha 2004/04/30 12:35:37
Modified: dist win32_postinstall.py
Log:
added code to win32_postinstall to automatically detect
the currently installed versions of Apache from the registry. It would
be nice to let the user choose one of these. As a start, it just selects
the latest version as the starting point for the tkinter file selection
dialog (the win32 shell classes don't seem to let you do this...)
Submitted by: David Fraser
Revision Changes Path
1.6 +42 -7 httpd-python/dist/win32_postinstall.py
Index: win32_postinstall.py
===================================================================
RCS file: /home/cvs/httpd-python/dist/win32_postinstall.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- win32_postinstall.py 16 Feb 2004 19:47:27 -0000 1.5
+++ win32_postinstall.py 30 Apr 2004 19:35:37 -0000 1.6
@@ -18,19 +18,52 @@
#
# this script runs at the end of windows install
-
import sys, os, shutil
+import distutils.sysconfig
+def getApacheDirOptions():
+ """find potential apache directories in the registry..."""
+ try:
+ import win32api, win32con
+ class regkey:
+ """simple wrapper for registry functions that closes keys nicely..."""
+ def __init__(self, parent, subkeyname):
+ self.key = win32api.RegOpenKey(parent, subkeyname)
+ def childkey(self, subkeyname):
+ return regkey(self.key, subkeyname)
+ def subkeynames(self):
+ numsubkeys = win32api.RegQueryInfoKey(self.key)[0]
+ return [win32api.RegEnumKey(self.key, index) for index in range(numsubkeys)]
+ def getvalue(self, valuename):
+ return win32api.RegQueryValueEx(self.key, valuename)
+ def __del__(self):
+ win32api.RegCloseKey(self.key)
+ except ImportError:
+ return {}
+ versions = {}
+ apachekey = regkey(win32con.HKEY_LOCAL_MACHINE, "Software").childkey("Apache Group").childkey("Apache")
+ for versionname in apachekey.subkeynames():
+ serverroot = apachekey.childkey(versionname).getvalue("ServerRoot")
+ versions[versionname] = serverroot[0]
+ return versions
-def askForApacheDir():
+def askForApacheDir(apachediroptions):
# try to ask for Apache directory
+ if len(apachediroptions) > 0:
+ # get the most recent version...
+ versionnames = apachediroptions.keys()
+ versionnames.sort()
+ initialdir = apachediroptions[versionnames[-1]]
+ else:
+ initialdir="C:/Program Files/Apache Group/Apache2"
+ # TODO: let the user select the name from a list, or click browse to choose...
try:
from tkFileDialog import askdirectory
from Tkinter import Tk
root = Tk()
root.withdraw()
path = askdirectory(title="Where is Apache installed?",
- initialdir="C:/Program Files/Apache Group/Apache2",
+ initialdir=initialdir,
mustexist=1, master=root)
root.quit()
root.destroy()
@@ -47,14 +80,16 @@
# if we're called during removal, just exit
if len(sys.argv) == 0 or sys.argv[1] != "-remove":
- mp = os.path.join(sys.prefix, "mod_python.so")
+ mp = os.path.join(distutils.sysconfig.get_python_lib(), "mod_python_so.pyd")
+
+ apachediroptions = getApacheDirOptions()
- apachedir = askForApacheDir()
+ apachedir = askForApacheDir(apachediroptions)
if apachedir:
# put mod_python.so there
- shutil.copy2(mp, os.path.join(apachedir, "modules"))
+ shutil.copy2(mp, os.path.join(apachedir, "modules", "mod_python.so"))
os.remove(mp)
print """Important Note for Windows users, PLEASE READ!!!