From 105cc10843c0daf9b7f5b1e7f3286e3d40cb87db Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Fri, 17 Jan 2014 18:19:13 +0100 Subject: [PATCH] Trying to integrate html... One way or another --- app/routes.py | 12 ++++++++++++ app/static/javascripts/term.js | 2 +- bin/ils | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 bin/ils diff --git a/app/routes.py b/app/routes.py index c060aa0..4130851 100644 --- a/app/routes.py +++ b/app/routes.py @@ -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...') diff --git a/app/static/javascripts/term.js b/app/static/javascripts/term.js index 948b0e5..1db56ba 160000 --- a/app/static/javascripts/term.js +++ b/app/static/javascripts/term.js @@ -1 +1 @@ -Subproject commit 948b0e52a2e36e843ef99a2a2821899fb60d670c +Subproject commit 1db56ba64e90518c93ebaf4448d83a51a43b390b diff --git a/bin/ils b/bin/ils new file mode 100755 index 0000000..daa65b4 --- /dev/null +++ b/bin/ils @@ -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 += '%s' % ( + os.path.abspath(f), f) + i += 1 + if i % 5 == 0: + out += '\n' + +print(out) + +print('\x07')