Skip to content

Commit

Permalink
support arbitrary eda files
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-goeldi committed Aug 31, 2023
1 parent 3ccf73b commit b8f7f87
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/kweb/api/browser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from itertools import chain
from pathlib import Path

from fastapi import APIRouter, Request
Expand All @@ -20,7 +21,9 @@ async def file_browser(
request: Request,
) -> _TemplateResponse:
settings: Config = router.dependencies[0].dependency() # type: ignore[misc]
files = settings.fileslocation.glob("**/*.gds")
files = chain(
settings.fileslocation.glob("**/*.gds"), settings.fileslocation.glob("**/*.oas")
)
return templates.TemplateResponse(
"browser.html",
{
Expand Down
28 changes: 27 additions & 1 deletion src/kweb/api/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ async def gds_view_static(
return await show_file(request, gds_file, layer_props, cell)


@router.get("/file/{file_name:path}", response_class=HTMLResponse)
async def file_view_static(
request: Request,
file_name: str,
layer_props: str | None = None,
cell: str | None = None,
) -> _TemplateResponse:
settings = router.dependencies[0].dependency() # type: ignore[misc]
file = settings.fileslocation / f"{file_name}"

exists = (
file.exists()
and file.is_file()
and file.stat().st_mode # type: ignore[misc, operator]
)

if not exists:
raise HTTPException(
status_code=404,
detail=f'No file found with name "{file_name}".'
" It doesn't exist or is not accessible",
)

return await show_file(request, file, layer_props, cell)


async def show_file(
request: Request,
file: Path,
Expand Down Expand Up @@ -67,7 +93,7 @@ async def show_file(
template_params = {
"request": request,
"url": url,
"gds_file": file,
"file": file,
"layer_props": layer_props,
}

Expand Down
2 changes: 1 addition & 1 deletion src/kweb/layout_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
key, value = _param.split("=")
params[key] = value

self.url = params["gds_file"]
self.url = params["file"]
self.layer_props = params.get("layer_props", None)
self.initial_cell: str | None = None
if "cell" in params:
Expand Down
4 changes: 2 additions & 2 deletions src/kweb/static/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ ws_url = ws_url.replace("https://","wss://");

let url;
if (cell) {
url = ws_url + '/ws?' + "gds_file=" + gds_file + "&layer_props=" + layer_props + "&cell=" + cell;
url = ws_url + '/ws?' + "file=" + file + "&layer_props=" + layer_props + "&cell=" + cell;
} else {
url = ws_url + '/ws?' + "gds_file=" + gds_file + "&layer_props=" + layer_props;
url = ws_url + '/ws?' + "file=" + file + "&layer_props=" + layer_props;
}

let canvas = document.getElementById("layout_canvas");
Expand Down
2 changes: 1 addition & 1 deletion src/kweb/templates/browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="container-fluid w-100 overflow-scroll" id="files-panel">
{% for file in folder_files %}
<div class="d-flex flex-row p-2">
<a href="/gds/{{ file }}"" class="btn btn-primary text-start">{{file}}</a>
<a href="/file/{{ file }}"" class="btn btn-primary text-start">{{file}}</a>
</div>
{% endfor %}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/kweb/templates/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
</div>
</div>
{% if cell is defined %}
<script>var ws_url="{{ url }}"; var layer_props="{{ layer_props }}"; var gds_file="{{ gds_file }}"; var cell="{{ cell }}"</script>
<script>var ws_url="{{ url }}"; var layer_props="{{ layer_props }}"; var file="{{ file }}"; var cell="{{ cell }}"</script>
{% else %}
<script>var ws_url="{{ url }}"; var layer_props="{{ layer_props }}"; var gds_file="{{ gds_file }}"; var cell=null</script>
<script>var ws_url="{{ url }}"; var layer_props="{{ layer_props }}"; var file="{{ file }}"; var cell=null</script>
{% endif %}
<script type="text/javascript" src="{{ url_for("kweb_static", path="viewer.js") }}"></script>
<script type="text/javascript" src={{ url_for("kweb_static", path="/bootstrap/bootstrap.bundle.min.js") }}></script>
Expand Down

0 comments on commit b8f7f87

Please sign in to comment.