import sys from AdminPage import AdminPage 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('

You are running the OneShot version of WebKit.' ' None of the options below are applicable.

') wr('''

''') modnames = sys.modules.keys() modnames.sort() wr('\n
Shut down the AppServer. You need to restart it manually afterwards.
Clear the class and instance caches of each servlet factory.
Reload the selected Python modules. Be careful!
') 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('' ' %s
' % (n, n)) wr('
\n
') elif action == "Clear cache": from WebKit.URLParser import ServletFactoryManager factories = filter(lambda f: f._classCache, ServletFactoryManager._factories) wr('

') for factory in factories: wr('Flushing cache of %s...
' % factory.name()) factory.flushCache() wr('

') wr('

The caches of all factories' ' have been flushed.

') wr('

Click here to view the Servlet cache:' ' Servlet Cache

') elif action == "Reload": wr('

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.

') reloadnames = req.field("reloads", None) if not type(reloadnames) == type([]): reloadnames = [reloadnames] wr('

') for n in reloadnames: m = sys.modules.get(n) if m: wr("Reloading %s...
" % self.htmlEncode(str(m))) try: reload(m) except Exception, e: wr('Could not reload, ' 'error was "%s".
' % e) wr('

') wr('

The selected modules' ' have been reloaded.

') elif action == "Shutdown": wr('

Shutting down the Application server...

') self.application().server().initiateShutdown() self.write('

Good Luck!

') else: wr('

Cannot perform "%s".

' % action)