-
Notifications
You must be signed in to change notification settings - Fork 3
/
__main__.py
54 lines (37 loc) · 1.43 KB
/
__main__.py
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
"""Github-like download interface"""
import typing
from pathlib import Path
from uuid import uuid4
from quart import Quart, send_from_directory, Response
app = Quart("rhasspy")
app.secret_key = str(uuid4())
# -----------------------------------------------------------------------------
profile_dirs: typing.Dict[str, Path] = {}
for check_dir in Path(".").glob("*"):
if not check_dir.is_dir():
continue
for profile_dir in check_dir.glob("*"):
if not profile_dir.is_dir():
continue
profile_yml = profile_dir / "profile.yml"
if profile_yml.is_file():
profile_dirs[profile_dir.name] = profile_dir
# -----------------------------------------------------------------------------
@app.route("/<path:path>")
async def download_raw(path: str) -> Response:
components = path.split("/")
if components[0] in ("synesthesiam", "rhasspy"):
components = components[1:]
profile = components[0]
if components[1] == "raw":
# /raw/master/{file}
artifact = "/".join(components[3:])
else:
# /{commit}/{file}
artifact = "/".join(components[2:])
profile_dir = profile_dirs.get(profile)
assert profile_dir, f"Missing directory for {profile}"
return await send_from_directory(profile_dir, artifact)
# -----------------------------------------------------------------------------
if __name__ == "__main__":
app.run(host="0.0.0.0")