Trying to integrate html... One way or another

This commit is contained in:
Florian Mounier
2014-01-17 18:19:13 +01:00
parent ee00a5ef46
commit 105cc10843
3 changed files with 33 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import io
import sys
import struct
import fcntl
import mimetypes
import termios
import tornado.websocket
import tornado.process
@@ -20,6 +21,14 @@ class Index(Route):
return self.render('index.html')
@url(r'/file/(.+)')
class File(Route):
def get(self, file):
self.add_header('Content-Type', mimetypes.guess_type(file)[0])
with open(file, 'rb') as fd:
self.write(fd.read())
@url(r'/ws')
class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
@@ -43,6 +52,9 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
env["COLORTERM"] = "wsterm"
command = os.getenv('SHELL')
env["SHELL"] = command
env["PATH"] = "%s:%s" % (
os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', 'bin')), env["PATH"])
p = Popen(command, env=env)
p.wait()
self.log.info('Exiting...')

20
bin/ils Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env python
import os
import mimetypes
print('\x1b]99;')
out = ''
i = 0
for f in os.listdir(os.getcwd()):
if 'image' in (mimetypes.guess_type(f)[0] or ''):
out += '<img src="/file/%s" alt="%s" width="100px" height="100px" />' % (
os.path.abspath(f), f)
i += 1
if i % 5 == 0:
out += '\n'
print(out)
print('\x07')