Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:

- run: |
mk python-release owner=libre-embedded \
repo=runtimepy version=5.15.5
repo=runtimepy version=5.15.6
if: |
matrix.python-version == '3.12'
&& matrix.system == 'ubuntu-latest'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.2.3
hash=fd0e57419cf9437a64c4f82cae3625f0
hash=0f8ffdbd46445346cb834d066f58e765
=====================================
-->

# runtimepy ([5.15.5](https://pypi.org/project/runtimepy/))
# runtimepy ([5.15.6](https://pypi.org/project/runtimepy/))

[![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/)
![Build Status](https://github.com/libre-embedded/runtimepy/workflows/Python%20Package/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 5
minor: 15
patch: 5
patch: 6
entry: runtimepy
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "runtimepy"
version = "5.15.5"
version = "5.15.6"
description = "A framework for implementing Python services."
readme = "README.md"
requires-python = ">=3.12"
Expand Down
4 changes: 2 additions & 2 deletions runtimepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.2.3
# hash=8ce7abe0f8c0e64d9afc0b5e4de6e2ad
# hash=08c1dda8bd5fefe13af6a8eb49063498
# =====================================

"""
Expand All @@ -10,7 +10,7 @@

DESCRIPTION = "A framework for implementing Python services."
PKG_NAME = "runtimepy"
VERSION = "5.15.5"
VERSION = "5.15.6"

# runtimepy-specific content.
METRICS_NAME = "metrics"
Expand Down
80 changes: 55 additions & 25 deletions runtimepy/net/server/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

# built-in
from io import StringIO
import mimetypes
from pathlib import Path
from typing import Iterable, cast

# third-party
from svgen.element.html import div
from vcorelib.io.file_writer import IndentedFileWriter
from vcorelib.math.time import byte_count_str
from vcorelib.paths import rel
Expand All @@ -17,6 +19,58 @@
DIR_FILE = "dir.html"


def file_preview(path: Path, link: Path) -> str:
"""Get possible preview text for a file."""

preview = ""

if path.is_file():
mime, _ = mimetypes.guess_type(path, strict=False)
if mime and mime.startswith("image"):
preview = div(tag="img", src=f"/{link}", alt=str(link)).encode_str(
newlines=False
)

return preview


def write_markdown_dir(
writer: IndentedFileWriter, path: Path, base: Path
) -> None:
"""Write markdown contents for a single directory."""

curr_dir = rel(path, base=base)

line = f"### `{base.name}/{curr_dir}`"

# Link to go up a directory.
if curr_dir != Path():
line += f" ([..](/{curr_dir.parent}/{DIR_FILE}))"

writer.write(line)
writer.empty()

writer.write("| name | size | preview |")
writer.write("|------|------|---------|")

for item in sorted(path.iterdir()):
curr = rel(item, base=base)

name = f"`{curr.name}`"
if item.is_dir():
name = f"**{name}**"

stats = _stats(item)
assert stats
size_str = byte_count_str(stats.st_size) if item.is_file() else ""

writer.write(
f"| [{name}](/{curr}) | {size_str} | {file_preview(item, curr)} |"
)

writer.empty()


def markdown_for_dir(
paths_bases: Iterable[tuple[Path, Path]],
extra_links: dict[str, Iterable[str]] = None,
Expand All @@ -40,31 +94,7 @@ def markdown_for_dir(
writer.empty()

for path, base in paths_bases:
curr_dir = rel(path, base=base)
writer.write(f"### `{base.name}/{curr_dir}`")
writer.empty()

# Link to go up a directory.
if curr_dir != Path():
writer.write(f"* [..](/{curr_dir.parent}/{DIR_FILE})")

writer.write("| name | size |")
writer.write("|------|------|")
for item in sorted(path.iterdir()):
curr = rel(item, base=base)

name = f"`{curr.name}`"
if item.is_dir():
name = f"**{name}**"

stats = _stats(item)
assert stats
size_str = (
byte_count_str(stats.st_size) if item.is_file() else ""
)
writer.write(f"| [{name}](/{curr}) | {size_str} |")

writer.empty()
write_markdown_dir(writer, path, base)

result: str = cast(StringIO, writer.stream).getvalue()

Expand Down