runtimepy 5.15.5__py3-none-any.whl → 5.15.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
runtimepy/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
1
  # =====================================
2
2
  # generator=datazen
3
3
  # version=3.2.3
4
- # hash=8ce7abe0f8c0e64d9afc0b5e4de6e2ad
4
+ # hash=08c1dda8bd5fefe13af6a8eb49063498
5
5
  # =====================================
6
6
 
7
7
  """
@@ -10,7 +10,7 @@ Useful defaults and other package metadata.
10
10
 
11
11
  DESCRIPTION = "A framework for implementing Python services."
12
12
  PKG_NAME = "runtimepy"
13
- VERSION = "5.15.5"
13
+ VERSION = "5.15.6"
14
14
 
15
15
  # runtimepy-specific content.
16
16
  METRICS_NAME = "metrics"
@@ -4,10 +4,12 @@ A module implementing web server markdown interfaces.
4
4
 
5
5
  # built-in
6
6
  from io import StringIO
7
+ import mimetypes
7
8
  from pathlib import Path
8
9
  from typing import Iterable, cast
9
10
 
10
11
  # third-party
12
+ from svgen.element.html import div
11
13
  from vcorelib.io.file_writer import IndentedFileWriter
12
14
  from vcorelib.math.time import byte_count_str
13
15
  from vcorelib.paths import rel
@@ -17,6 +19,58 @@ LOGO_MARKDOWN = "[![logo](/static/png/chip-circle-bootstrap/128x128.png)](/)"
17
19
  DIR_FILE = "dir.html"
18
20
 
19
21
 
22
+ def file_preview(path: Path, link: Path) -> str:
23
+ """Get possible preview text for a file."""
24
+
25
+ preview = ""
26
+
27
+ if path.is_file():
28
+ mime, _ = mimetypes.guess_type(path, strict=False)
29
+ if mime and mime.startswith("image"):
30
+ preview = div(tag="img", src=f"/{link}", alt=str(link)).encode_str(
31
+ newlines=False
32
+ )
33
+
34
+ return preview
35
+
36
+
37
+ def write_markdown_dir(
38
+ writer: IndentedFileWriter, path: Path, base: Path
39
+ ) -> None:
40
+ """Write markdown contents for a single directory."""
41
+
42
+ curr_dir = rel(path, base=base)
43
+
44
+ line = f"### `{base.name}/{curr_dir}`"
45
+
46
+ # Link to go up a directory.
47
+ if curr_dir != Path():
48
+ line += f" ([..](/{curr_dir.parent}/{DIR_FILE}))"
49
+
50
+ writer.write(line)
51
+ writer.empty()
52
+
53
+ writer.write("| name | size | preview |")
54
+ writer.write("|------|------|---------|")
55
+
56
+ for item in sorted(path.iterdir()):
57
+ curr = rel(item, base=base)
58
+
59
+ name = f"`{curr.name}`"
60
+ if item.is_dir():
61
+ name = f"**{name}**"
62
+
63
+ stats = _stats(item)
64
+ assert stats
65
+ size_str = byte_count_str(stats.st_size) if item.is_file() else ""
66
+
67
+ writer.write(
68
+ f"| [{name}](/{curr}) | {size_str} | {file_preview(item, curr)} |"
69
+ )
70
+
71
+ writer.empty()
72
+
73
+
20
74
  def markdown_for_dir(
21
75
  paths_bases: Iterable[tuple[Path, Path]],
22
76
  extra_links: dict[str, Iterable[str]] = None,
@@ -40,31 +94,7 @@ def markdown_for_dir(
40
94
  writer.empty()
41
95
 
42
96
  for path, base in paths_bases:
43
- curr_dir = rel(path, base=base)
44
- writer.write(f"### `{base.name}/{curr_dir}`")
45
- writer.empty()
46
-
47
- # Link to go up a directory.
48
- if curr_dir != Path():
49
- writer.write(f"* [..](/{curr_dir.parent}/{DIR_FILE})")
50
-
51
- writer.write("| name | size |")
52
- writer.write("|------|------|")
53
- for item in sorted(path.iterdir()):
54
- curr = rel(item, base=base)
55
-
56
- name = f"`{curr.name}`"
57
- if item.is_dir():
58
- name = f"**{name}**"
59
-
60
- stats = _stats(item)
61
- assert stats
62
- size_str = (
63
- byte_count_str(stats.st_size) if item.is_file() else ""
64
- )
65
- writer.write(f"| [{name}](/{curr}) | {size_str} |")
66
-
67
- writer.empty()
97
+ write_markdown_dir(writer, path, base)
68
98
 
69
99
  result: str = cast(StringIO, writer.stream).getvalue()
70
100
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: runtimepy
3
- Version: 5.15.5
3
+ Version: 5.15.6
4
4
  Summary: A framework for implementing Python services.
5
5
  Home-page: https://github.com/libre-embedded/runtimepy
6
6
  Author: Libre Embedded
@@ -17,11 +17,11 @@ Classifier: Development Status :: 5 - Production/Stable
17
17
  Requires-Python: >=3.12
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
- Requires-Dist: psutil
21
- Requires-Dist: svgen>=0.8.0
22
20
  Requires-Dist: aiofiles
23
- Requires-Dist: vcorelib>=3.6.4
21
+ Requires-Dist: svgen>=0.8.0
24
22
  Requires-Dist: websockets
23
+ Requires-Dist: psutil
24
+ Requires-Dist: vcorelib>=3.6.4
25
25
  Provides-Extra: test
26
26
  Requires-Dist: pylint; extra == "test"
27
27
  Requires-Dist: flake8; extra == "test"
@@ -51,11 +51,11 @@ Dynamic: requires-python
51
51
  =====================================
52
52
  generator=datazen
53
53
  version=3.2.3
54
- hash=fd0e57419cf9437a64c4f82cae3625f0
54
+ hash=0f8ffdbd46445346cb834d066f58e765
55
55
  =====================================
56
56
  -->
57
57
 
58
- # runtimepy ([5.15.5](https://pypi.org/project/runtimepy/))
58
+ # runtimepy ([5.15.6](https://pypi.org/project/runtimepy/))
59
59
 
60
60
  [![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/)
61
61
  ![Build Status](https://github.com/libre-embedded/runtimepy/workflows/Python%20Package/badge.svg)
@@ -1,4 +1,4 @@
1
- runtimepy/__init__.py,sha256=wVKBUb0d3kdEu2RAyDqlguPD6weDDr_KQAXrx0YQlCY,391
1
+ runtimepy/__init__.py,sha256=qAS3P1hKgQCdNqiMTEqhiSnIM9BIwdZqBvOQfrZCBC4,391
2
2
  runtimepy/__main__.py,sha256=IKioH2xOtsXwrwb9zABDQEJvuAX--Lnh84TeSz0XSs0,332
3
3
  runtimepy/app.py,sha256=Er1ZKKrG9U0FV0gQg_GYF9xDb89HgYnVzS5SjxGa2Tg,970
4
4
  runtimepy/dev_requirements.txt,sha256=VZhW6bJ5YbwaoN4d_XxZFuN5BbDLaG7ngKrGnugVPRw,245
@@ -205,7 +205,7 @@ runtimepy/net/http/version.py,sha256=mp6rgIM7-VUVKLCA0Uw96CmBkL0ET860lDVVEewpZ7w
205
205
  runtimepy/net/server/__init__.py,sha256=ppfMgymYGRz13MvHvwXyy9WAos2wWgaZDf1TW8D1ILU,11813
206
206
  runtimepy/net/server/html.py,sha256=OB2K37kA7MHtcKqp0pZE1q_XgiyvfooigzS0-OQFCCM,1900
207
207
  runtimepy/net/server/json.py,sha256=AaMPw-G-7xX67mf1LvQAipNdwrnmbLDunVlkWf6iOz0,2526
208
- runtimepy/net/server/markdown.py,sha256=UIJ9R9WM5XodPs8WEevFNJ3LX9tMevhUe8QKKdeY4ak,2143
208
+ runtimepy/net/server/markdown.py,sha256=KuPKYh7nj5oy70Ff8LRAXwr_Ga4r8_3KksvDfPfFqYM,2690
209
209
  runtimepy/net/server/mux.py,sha256=ejET7NpJzzJjkVwR8laSuZYR79DOT3XazmAIm6rENSE,598
210
210
  runtimepy/net/server/app/__init__.py,sha256=0eCcqYvmby_wQTGqAiGbGM5LCxKM2qpjuIT0gLHsoDU,3157
211
211
  runtimepy/net/server/app/base.py,sha256=46aOqZwRss_nh_WfEH1cMJ9GUVoLJjERd7cTRFu6mXE,1878
@@ -311,9 +311,9 @@ runtimepy/tui/channels/__init__.py,sha256=evDaiIn-YS9uGhdo8ZGtP9VK1ek6sr_P1nJ9Ju
311
311
  runtimepy/ui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
312
312
  runtimepy/ui/button.py,sha256=8MXnhqmVvANwbbTA8gu3b8N4IIvRYicnwxFQD6SZy3U,2045
313
313
  runtimepy/ui/controls.py,sha256=L55Af-4vGq6ZHewdoA7C_mAYq35WXl8NzOdcsmQIo7M,1868
314
- runtimepy-5.15.5.dist-info/licenses/LICENSE,sha256=yKBRwbO-cOPBrlpsZmJkkSa33DfY31aE8t7lZ0DwlUo,1071
315
- runtimepy-5.15.5.dist-info/METADATA,sha256=zAY7eYIZrG229MNSE6k3wZUyz7nVDQ78DJPS4nlPFGA,9268
316
- runtimepy-5.15.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
317
- runtimepy-5.15.5.dist-info/entry_points.txt,sha256=-btVBkYv7ybcopqZ_pRky-bEzu3vhbaG3W3Z7ERBiFE,51
318
- runtimepy-5.15.5.dist-info/top_level.txt,sha256=0jPmh6yqHyyJJDwEID-LpQly-9kQ3WRMjH7Lix8peLg,10
319
- runtimepy-5.15.5.dist-info/RECORD,,
314
+ runtimepy-5.15.6.dist-info/licenses/LICENSE,sha256=yKBRwbO-cOPBrlpsZmJkkSa33DfY31aE8t7lZ0DwlUo,1071
315
+ runtimepy-5.15.6.dist-info/METADATA,sha256=MoIujpmp5ifEdr-DxKZrNXyHuFSUoeS6iX0iIyqdW2w,9268
316
+ runtimepy-5.15.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
317
+ runtimepy-5.15.6.dist-info/entry_points.txt,sha256=-btVBkYv7ybcopqZ_pRky-bEzu3vhbaG3W3Z7ERBiFE,51
318
+ runtimepy-5.15.6.dist-info/top_level.txt,sha256=0jPmh6yqHyyJJDwEID-LpQly-9kQ3WRMjH7Lix8peLg,10
319
+ runtimepy-5.15.6.dist-info/RECORD,,