Commit 923aa4ac authored by Michael Murtaugh's avatar Michael Murtaugh

initial commit

parents
build/
dist/
__pycache__/
Creating a venv
--------------------
python -m venv venv
Installing requirements
--------------------------
pip install aiohttp
#!/usr/bin/env python
from aiohttp import web
# from yarl import URL, unquote
import sys, os, asyncio
# from pathlib import Path
from asyncio import create_subprocess_exec
from urllib.parse import unquote as urlunquote
async def is_makeable (path, cwd=".", makefile="makefile"):
# print ("make_question {0} {1}".format(path, docroot))
# make --question return codes: 0 : file is up to date, 1 : file needs remaking, 2 : file is not makeable
rpath = os.path.relpath(path, cwd)
# print ("*make_question {0} {1} {2}".format(path, cwd, r))
p = await create_subprocess_exec("make", "--question", "-f", makefile, rpath, cwd = cwd)
ret = await p.wait() == 1
print (f"is_makeable {ret}", file=sys.stderr)
return ret
async def make (path, cwd=".", makefile="makefile"):
# print ("make_question {0} {1}".format(path, docroot))
# make --question return codes: 0 : file is up to date, 1 : file needs remaking, 2 : file is not makeable
rpath = os.path.relpath(path, cwd)
# print ("*make_question {0} {1} {2}".format(path, cwd, r))
p = await create_subprocess_exec("make", "-f", makefile, rpath, cwd = cwd)
ret = await p.wait() == 0
print (f"make {ret}", file=sys.stderr)
return ret
async def do_route(request):
# return FileResponse(filepath, chunk_size=self._chunk_size)
path = urlunquote(request.rel_url.raw_path.lstrip("/"))
print ("do_route", path, file=sys.stderr)
if await is_makeable(path):
await make(path)
if os.path.exists(path):
return web.FileResponse(path, chunk_size=256*1024)
else:
return web.Response(text=f"404 on path {path}")
def main ():
if sys.platform == 'win32':
# Folowing: https://docs.python.org/3/library/asyncio-subprocess.html
# On Windows, the default event loop is SelectorEventLoop which does not support subprocesses.
# ProactorEventLoop should be used instead.
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
app = web.Application()
app.add_routes([web.get('/{make:.*}', do_route)])
web.run_app(app)
if __name__ == "__main__":
main()
\ No newline at end of file
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="makeserver3",
version="3.0.0",
author="Michael Murtaugh",
author_email="mm@automatist.org",
description="Make & Serve",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/pypa/example-project",
packages=setuptools.find_packages(),
classifiers=(
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
),
entry_points={
'console_scripts': [
'makeserver3 = makeserver3:main',
]
}
)
\ No newline at end of file
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