~ubuntu-branches/ubuntu/maverick/libapache2-mod-python/maverick

« back to all changes in this revision

Viewing changes to dist/win32_postinstall.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ozarowski
  • Date: 2007-02-21 18:24:29 UTC
  • mfrom: (1.1.8 feisty)
  • Revision ID: james.westby@ubuntu.com-20070221182429-9okop7e0qpi24l85
Tags: 3.2.10-4
* Added XS-Vcs-Svn field
* Removed "db_purge" part from libapache2-mod-python.postrm
  (dh_installdebconf is generating a rule that will not fail if debconf is
  already removed)
* Added initial Spanish debconf translation from Manuel Porras Peralta.
  (closes: #411235)
* Added initial Portuguese debconf translation from Pedro Ribeiro.
  (closes: #411742)
* Added initial Galician debconf translation from Jacobo Tarrio.
  (closes: #411831)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 #
15
15
 # Originally developed by Gregory Trubetskoy.
16
16
 #
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 $
18
18
 #
19
19
 # this script runs at the end of windows install
20
20
 
21
21
 
22
22
import sys, os, shutil
23
 
 
24
 
 
25
 
def askForApacheDir():
 
23
import distutils.sysconfig
 
24
 
 
25
def getApacheDirOptions():
 
26
    """find potential apache directories in the registry..."""
 
27
    try:
 
28
        import win32api, win32con
 
29
        class nullregkey:
 
30
            """a registry key that doesn't exist..."""
 
31
            def childkey(self, subkeyname):
 
32
                return nullregkey()
 
33
            def subkeynames(self):
 
34
                return []
 
35
            def getvalue(self, valuename):
 
36
                raise AttributeError("Cannot access registry value %r: key does not exist" % (valuename))
 
37
        class regkey:
 
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):
 
42
               try:
 
43
                   return regkey(self.key, subkeyname)
 
44
               except win32api.error:
 
45
                   return nullregkey()
 
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):
 
50
               try:
 
51
                   return win32api.RegQueryValueEx(self.key, valuename)
 
52
               except win32api.error:
 
53
                   raise AttributeError("Cannot access registry value %r" % (valuename))
 
54
            def __del__(self):
 
55
               if hasattr(self, "key"):
 
56
                   win32api.RegCloseKey(self.key)
 
57
    except ImportError:
 
58
        return {}
 
59
    versions = {}
 
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():
 
64
            try:
 
65
                serverroot = apachekey.childkey(versionname).getvalue("ServerRoot")
 
66
            except AttributeError:
 
67
                continue
 
68
            versions[versionname] = serverroot[0]
 
69
    return versions
 
70
 
 
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()
 
76
        versionnames.sort()
 
77
        initialdir = apachediroptions[versionnames[-1]]
 
78
    else:
 
79
        initialdir="C:/Program Files/Apache Group/Apache2"
 
80
    # TODO: let the user select the name from a list, or click browse to choose...
27
81
    try:
28
82
        from tkFileDialog import askdirectory
29
83
        from Tkinter import Tk
30
84
        root = Tk()
31
85
        root.withdraw()
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)
35
89
        root.quit()
36
90
        root.destroy()
45
99
            return ""
46
100
 
47
101
# if we're called during removal, just exit
48
 
if len(sys.argv) == 0 or sys.argv[1] != "-remove":
49
 
 
50
 
    mp = os.path.join(sys.prefix, "mod_python.so")
51
 
 
52
 
    apachedir = askForApacheDir()
 
102
if len(sys.argv) == 1 or (len(sys.argv) > 1 and sys.argv[1] != "-remove"):
 
103
 
 
104
    mp = os.path.join(distutils.sysconfig.get_python_lib(), "mod_python_so.pyd")
 
105
 
 
106
    apachediroptions = getApacheDirOptions()
 
107
 
 
108
    apachedir = askForApacheDir(apachediroptions)
53
109
 
54
110
    if apachedir:
55
111
 
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)
 
118
        f.close()
58
119
        os.remove(mp)
59
120
 
60
121
        print """Important Note for Windows users, PLEASE READ!!!
92
153
           http://www.modpython.org/live/current/doc-html/inst-testing.html
93
154
 
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()
 
160
    f.close()
 
161
    os.remove(mod_python_so_path)
 
162
    os.remove(mod_python_uninstall_log)