root/mail-onna-stick/trunk/lib/mosweb/twillscripts.py

Revision 270, 1.2 kB (checked in by t, 11 years ago)

fixed twill runscript stuff; updated selenium coverage reporting, etc.

Line 
1 """
2 Code to run twill scripts inside of MOS.
3 """
4 import os
5 from cStringIO import StringIO
6
7 import twill
8
9 from html import htmlescape
10
11 class TwillTop:
12     def index(self):
13         return "<a href='./runscript'>runscript</a>"
14     index.exposed = True
15    
16     def runscript(self, scriptname):
17         if '/' in scriptname:           # security measure ;)
18             return "cannot run this"
19
20         # redirect output into our own object
21         output_fp = StringIO()
22         twill.set_output(output_fp)
23
24         thisdir = os.path.dirname(__file__)
25         twillscriptsdir = os.path.join(thisdir, 'static/twill')
26         twillscript = os.path.join(twillscriptsdir, scriptname)
27         twillscript = os.path.abspath(twillscript)
28
29         # build top URL
30         import cherrypy.config
31         port = cherrypy.config.get('server.socketPort')
32         top_url = 'http://localhost:%s/' % (port,)
33
34         # execute script
35         twill.execute_file(twillscript, initial_url=top_url)
36
37         # grab the output & display it.
38         output = output_fp.getvalue()
39         output = htmlescape(output)
40
41         return "Ran twill script <tt>%s</tt>.<p>Output:<blockquote><pre>%s</pre></blockquote>" % (htmlescape(scriptname), output,)
42
43     runscript.exposed = True
Note: See TracBrowser for help on using the browser.