15
15
# Originally developed by Gregory Trubetskoy.
17
# $Id: win32_postinstall.py,v 1.5 2004/02/16 19:47:27 grisha Exp $
17
# $Id: win32_postinstall.py 160939 2005-04-11 19:20:52Z nlehuen $
19
19
# this script runs at the end of windows install
22
22
import sys, os, shutil
25
def askForApacheDir():
23
import distutils.sysconfig
25
def getApacheDirOptions():
26
"""find potential apache directories in the registry..."""
28
import win32api, win32con
30
"""a registry key that doesn't exist..."""
31
def childkey(self, subkeyname):
33
def subkeynames(self):
35
def getvalue(self, valuename):
36
raise AttributeError("Cannot access registry value %r: key does not exist" % (valuename))
38
"""simple wrapper for registry functions that closes keys nicely..."""
39
def __init__(self, parent, subkeyname):
40
self.key = win32api.RegOpenKey(parent, subkeyname)
41
def childkey(self, subkeyname):
43
return regkey(self.key, subkeyname)
44
except win32api.error:
46
def subkeynames(self):
47
numsubkeys = win32api.RegQueryInfoKey(self.key)[0]
48
return [win32api.RegEnumKey(self.key, index) for index in range(numsubkeys)]
49
def getvalue(self, valuename):
51
return win32api.RegQueryValueEx(self.key, valuename)
52
except win32api.error:
53
raise AttributeError("Cannot access registry value %r" % (valuename))
55
if hasattr(self, "key"):
56
win32api.RegCloseKey(self.key)
60
hklm_key = regkey(win32con.HKEY_LOCAL_MACHINE, "Software").childkey("Apache Group").childkey("Apache")
61
hkcu_key = regkey(win32con.HKEY_CURRENT_USER, "Software").childkey("Apache Group").childkey("Apache")
62
for apachekey in (hklm_key, hkcu_key):
63
for versionname in apachekey.subkeynames():
65
serverroot = apachekey.childkey(versionname).getvalue("ServerRoot")
66
except AttributeError:
68
versions[versionname] = serverroot[0]
71
def askForApacheDir(apachediroptions):
26
72
# try to ask for Apache directory
73
if len(apachediroptions) > 0:
74
# get the most recent version...
75
versionnames = apachediroptions.keys()
77
initialdir = apachediroptions[versionnames[-1]]
79
initialdir="C:/Program Files/Apache Group/Apache2"
80
# TODO: let the user select the name from a list, or click browse to choose...
28
82
from tkFileDialog import askdirectory
29
83
from Tkinter import Tk
32
86
path = askdirectory(title="Where is Apache installed?",
33
initialdir="C:/Program Files/Apache Group/Apache2",
87
initialdir=initialdir,
34
88
mustexist=1, master=root)
47
101
# if we're called during removal, just exit
48
if len(sys.argv) == 0 or sys.argv[1] != "-remove":
50
mp = os.path.join(sys.prefix, "mod_python.so")
52
apachedir = askForApacheDir()
102
if len(sys.argv) == 1 or (len(sys.argv) > 1 and sys.argv[1] != "-remove"):
104
mp = os.path.join(distutils.sysconfig.get_python_lib(), "mod_python_so.pyd")
106
apachediroptions = getApacheDirOptions()
108
apachedir = askForApacheDir(apachediroptions)
56
112
# put mod_python.so there
57
shutil.copy2(mp, os.path.join(apachedir, "modules"))
113
mod_python_so_path = os.path.join(apachedir, "modules", "mod_python.so")
114
mod_python_uninstall_log = os.path.join(distutils.sysconfig.get_python_lib(), 'mod_python_uninstall.log')
115
shutil.copy2(mp, mod_python_so_path)
116
f = file(mod_python_uninstall_log, 'wb')
117
f.write(mod_python_so_path)
60
121
print """Important Note for Windows users, PLEASE READ!!!
92
153
http://www.modpython.org/live/current/doc-html/inst-testing.html
94
155
""" % (mp, os.path.join(apachedir, "conf", "httpd.conf"))
156
elif len(sys.argv) > 1 and sys.argv[1] == "-remove":
157
mod_python_uninstall_log = os.path.join(distutils.sysconfig.get_python_lib(), 'mod_python_uninstall.log')
158
f = file(mod_python_uninstall_log, 'rb')
159
mod_python_so_path = f.read()
161
os.remove(mod_python_so_path)
162
os.remove(mod_python_uninstall_log)