Commit 21e34739 authored by Michael Murtaugh's avatar Michael Murtaugh

changes laptop

parent c26a1a01
......@@ -16,7 +16,8 @@ Install
To do
* (websockets-based) view to monitor output of make command
* add --js option to mixin custom javascript plugins (a la greasemonkey)
* add --saveable option to mixin saveable javascript
makewiki (aka cookbook)
......@@ -3,7 +3,8 @@ import sys, os, asyncio, json
from asyncio import create_subprocess_exec
from urllib.parse import urlparse, unquote as urlunquote, quote as urlquote
import argparse
from asyncio.subprocess import DEVNULL
from asyncio.subprocess import DEVNULL, STDOUT
import aiohttp
Todo: use proper http error responses for errors, see aiohttp/
......@@ -14,14 +15,19 @@ async def is_makeable (path, cwd=".", makefile="makefile"):
p = await create_subprocess_exec("make", "--question", "-f", makefile, rpath, cwd = cwd, stdout=DEVNULL, stderr=DEVNULL)
# retcode 0=file is up to date, 1=file needs remaking, 2=file is not makeable
ret = await p.wait() == 1
# print (f"is_makeable {path}: {ret}", file=sys.stderr)
print (f"is_makeable {path}: {ret}", file=sys.stderr)
await log(f"is_makeable {path}: {ret}")
return ret
async def make (path, cwd=".", makefile="makefile"):
rpath = os.path.relpath(path, cwd)
p = await create_subprocess_exec("make", "-f", makefile, rpath, cwd = cwd)
p = await create_subprocess_exec("make", "-f", makefile, rpath, stderr = STDOUT, cwd = cwd)
while True:
line = await p.stdout.readline()
ret = await p.wait() == 0
# print (f"make {path}: {ret}", file=sys.stderr)
print (f"make {path}: {ret}", file=sys.stderr)
await log(f"make {path}: {ret}")
return ret
textchars = bytearray({7,8,9,10,12,13,27} | set(range(0x20, 0x100)) - {0x7f})
......@@ -133,6 +139,34 @@ async def route_post (request):
return web.Response(text=f"post not allowed on {path}")
active_sockets = []
async def log (msg):
for ws in active_sockets:
await ws.send_str(msg)
async def websocket_handler(request):
print('Websocket connection starting')
ws = web.WebSocketResponse()
await ws.prepare(request)
print('Websocket connection ready')
async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT:
if == 'close':
await ws.close()
await ws.send_str( + '/answer')
print('Websocket connection closed')
return ws
def main ():
ap = argparse.ArgumentParser("make & serve")
ap.add_argument("--makefile", default="makefile")
......@@ -147,6 +181,7 @@ def main ():
app = web.Application()
app['makefile'] = args.makefile
app['editor'] = args.editor
app.router.add_route('GET', '/ws', websocket_handler)
app.add_routes([web.get('/{make:.*}', route_get)])
app.add_routes(['/{make:.*}', route_post)])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment