AppControl.py :  » Web-Frameworks » Webware » Webware-1.0.2 » WebKit » Admin » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Webware 
Webware » Webware 1.0.2 » WebKit » Admin » AppControl.py
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>''')
      modnames = sys.modules.keys()
      modnames.sort()
      wr('<tr><td></td><td>')
      for n in modnames:
        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 type(reloadnames) == type([]):
        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)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.