1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
from pathlib import Path
from hat import aio
import aiohttp.web
from hatter import common
import hatter.server
static_dir: Path = common.package_path / 'ui'
async def create(host: str,
port: int,
server: hatter.server.Server
) -> 'UI':
ui = UI()
ui._server = server
ui._async_group = aio.Group()
app = aiohttp.web.Application()
app.add_routes([
aiohttp.web.get('/', ui._get_root_handler),
aiohttp.web.get('/repo/{repo}', server._get_repo_handler),
aiohttp.web.get('/repo/{repo}/commit/{commit}',
server._get_commit_handler),
aiohttp.web.post('/repo/{repo}/webhook',
server._post_webhook_handler),
aiohttp.web.post('/repo/{repo}/commit/{commit}/run',
server._post_run_handler),
aiohttp.web.post('/repo/{repo}/commit/{commit}/remove',
server._post_remove_handler),
aiohttp.web.static('/', static_dir)])
runner = aiohttp.web.AppRunner(app)
await runner.setup()
ui.async_group.spawn(aio.call_on_cancel, runner.cleanup)
try:
site = aiohttp.web.TCPSite(runner=runner,
host=host,
port=port,
shutdown_timeout=0.1,
reuse_address=True)
await site.start()
except BaseException:
await aio.uncancellable(ui.async_group.async_close())
raise
return ui
class UI(aio.Resource):
@property
def async_group(self):
return self._async_group
async def _get_root_handler(self, request):
pass
async def _get_repo_handler(self, request):
pass
async def _get_commit_handler(self, request):
pass
async def _post_webhook_handler(self, request):
pass
async def _post_run_handler(self, request):
pass
async def _post_remove_handler(self, request):
pass
|