Began working on a web remote plugin

This plugin will eventually allow me to control ocarina through a web
interface.  So far, it can serve up web pages located in
current_working_directory/HTML.
This commit is contained in:
Bryan Schumaker 2010-11-13 21:39:27 -05:00
parent 9167e6441c
commit dcdbab8e55
3 changed files with 74 additions and 0 deletions

9
html/index.html Normal file
View File

@ -0,0 +1,9 @@
<html>
<head>
<script type="app/javascript" src="test.js" />
</head>
<body onload=message()>
</body>
</html>

5
html/test.js Normal file
View File

@ -0,0 +1,5 @@
function message()
{
document.write("External javascript test!")
}

60
plugins/web_remote.py Normal file
View File

@ -0,0 +1,60 @@
# Bryan Schumaker (11/13/2010)
import ocarina
from libsaria import threads
path = ocarina.libsaria.path
exists = path.exists
join = path.join
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
html = join(path.cwd(), "html")
server = None
types = {".html":"html", ".js":"javascript"}
class HTTPRequest(BaseHTTPRequestHandler):
def do_GET(self):
global html
if self.path == "" or self.path == "/":
self.path = "/index.html"
try:
fpath = html + self.path
print fpath
if not exists(fpath):
raise IOError
base, ext = path.splitext(fpath)
self.send_response(200)
self.send_header('Content-type', 'text/%s' % types[ext])
self.end_headers()
f = open(fpath)
self.wfile.write(f.read())
f.close()
except IOError:
self.send_error(404, 'File Not Found: %s' % self.path)
def do_POST(self):
print self.path
print "Received a post request!"
def start_server():
global server
server = HTTPServer(('', 4242), HTTPRequest)
server.serve_forever()
def start():
threads.background(start_server)
def stop():
server.shutdown()
def check_version():
if ocarina.__major__ != 4:
return False
if ocarina.__minor__ >= 1:
return True
return False