ocarina/plugins/web_remote.py

61 lines
1.2 KiB
Python

# 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