-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppControl.py
More file actions
80 lines (71 loc) · 3.37 KB
/
Copy pathAppControl.py
File metadata and controls
80 lines (71 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import sys
from AdminSecurity import AdminSecurity
class AppControl(AdminSecurity):
def writeContent(self):
req = self.request()
wr = self.writeln
action = self.request().field("action", None)
if action is None:
if not self.application().server().isPersistent():
wr('<p><b>You are running the <i>OneShot</i> version of WebKit.'
' None of the options below are applicable.</b><p>')
wr('''<form action="AppControl" method="post">
<table cellspacing="4" cellpadding="4">
<tr><td><input type="submit" name="action" value="Shutdown"></td>
<td>Shut down the AppServer. You need to restart it manually afterwards.</td>
</tr><tr>
<td><input type="submit" name="action" value="Clear cache"></td>
<td>Clear the class and instance caches of each servlet factory.</td>
</tr><tr>
<td><input type="submit" name="action" value="Reload"></td>
<td>Reload the selected Python modules. Be careful!</td></tr>''')
wr('<tr><td></td><td>')
for n in sorted(sys.modules):
m = sys.modules[n]
if (not n.endswith('__init__') and not hasattr(m, '__path__')
and not hasattr(m, '__orig_file__')):
# show only the easily reloadable modules
wr('<input type="checkbox" name="reloads" value="%s">'
' %s<br>' % (n, n))
wr('</td></tr>\n</table>\n</form>')
elif action == "Clear cache":
from WebKit.URLParser import ServletFactoryManager
factories = filter(lambda f: f._classCache,
ServletFactoryManager._factories)
wr('<p>')
for factory in factories:
wr('Flushing cache of %s...<br>' % factory.name())
factory.flushCache()
wr('</p>')
wr('<p style="color:green">The caches of all factories'
' have been flushed.</p>')
wr('<p>Click here to view the Servlet cache:'
' <a href="ServletCache">Servlet Cache</a></p>')
elif action == "Reload":
wr('<p>Reloading selected modules. Any existing classes'
' will continue to use the old module definitions,'
' as will any functions/variables imported using "from".'
' Use "Clear Cache" to clean out any servlets'
' in this condition.<p>')
reloadnames = req.field("reloads", None)
if not isinstance(reloadnames, list):
reloadnames = [reloadnames]
wr('<p>')
for n in reloadnames:
m = sys.modules.get(n)
if m:
wr("Reloading %s...<br>" % self.htmlEncode(str(m)))
try:
reload(m)
except Exception, e:
wr('<span style="color:red">Could not reload, '
'error was "%s".</span><br>' % e)
wr('</p>')
wr('<p style="color:green">The selected modules'
' have been reloaded.</p>')
elif action == "Shutdown":
wr('<p>Shutting down the Application server...</p>')
self.application().server().initiateShutdown()
self.write('<p style="color:green"><b>Good Luck!</b></p>')
else:
wr('<p>Cannot perform "%s".</p>' % action)