makea-cli 0.2.27__py3-none-any.whl → 0.2.28__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.
makea_cli/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.2.27"
1
+ __version__ = "0.2.28"
@@ -11,6 +11,7 @@ from makea_cli.commands.directory.cmd import register as register_directory
11
11
  from makea_cli.commands.document.cmd import register as register_document
12
12
  from makea_cli.commands.email.cmd import register as register_email
13
13
  from makea_cli.commands.factory.cmd import register as register_factory
14
+ from makea_cli.commands.files.cmd import register as register_files
14
15
  from makea_cli.commands.flags.cmd import register as register_flags
15
16
  from makea_cli.commands.library.cmd import register as register_library
16
17
  from makea_cli.commands.metrics.cmd import register as register_metrics
@@ -38,6 +39,7 @@ def register_all(app: typer.Typer) -> None:
38
39
  register_email(app)
39
40
  register_library(app)
40
41
  register_factory(app)
42
+ register_files(app)
41
43
  register_brand(app)
42
44
  register_playbook(app)
43
45
  register_about(app)
File without changes
@@ -0,0 +1,84 @@
1
+ """``makea-cli <persona> get file PATH``: read a file a brand sent, locally.
2
+
3
+ Pattern DXF/RUL, Illustrator, EPS, Photoshop, embroidery (PES/DST/EMB), ZIP,
4
+ AVIF/TIFF/SVG. No API call: the file never leaves the machine. Pictures of what
5
+ the file draws are saved next to it so the caller can look at them (an agent
6
+ reads them with its image tool).
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import re
12
+ from pathlib import Path
13
+
14
+ import typer
15
+ from rich.console import Console
16
+
17
+ from makea_cli.commands._util import print_json_or_exit
18
+ from makea_cli.file_reader import read_path
19
+ from makea_cli.registry import command
20
+
21
+ console = Console()
22
+
23
+ _HELP = (
24
+ "Read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or "
25
+ "AVIF/TIFF file on this machine: what it states plus PNG pictures of what it draws."
26
+ )
27
+
28
+
29
+ def _slug(text: str) -> str:
30
+ return re.sub(r"[^A-Za-z0-9]+", "-", text).strip("-").lower()[:40] or "picture"
31
+
32
+
33
+ def read_file_payload(path: Path, pictures_dir: Path | None) -> dict:
34
+ if not path.is_file():
35
+ raise FileNotFoundError(f"{path} is not a file")
36
+ reading = read_path(str(path))
37
+ out_dir = pictures_dir or path.parent
38
+ saved = []
39
+ pictures = reading.all_pictures()
40
+ if pictures:
41
+ out_dir.mkdir(parents=True, exist_ok=True)
42
+ for i, pic in enumerate(pictures, 1):
43
+ target = out_dir / f"{path.stem}.{i}-{_slug(pic.label)}.png"
44
+ target.write_bytes(pic.png)
45
+ saved.append({"label": pic.label, "path": str(target)})
46
+ payload = {
47
+ "file": str(path),
48
+ "kind": reading.kind,
49
+ "format": reading.format,
50
+ "readable": reading.readable,
51
+ "readout": reading.markdown(),
52
+ "pictures": saved,
53
+ }
54
+ if saved:
55
+ payload["next"] = (
56
+ "Look at each picture to read what it shows; the readout lists only stated facts."
57
+ )
58
+ return payload
59
+
60
+
61
+ def register(app: typer.Typer) -> None:
62
+ for persona in ("designer", "supplier", "admin"):
63
+ _register_for(app, persona)
64
+
65
+
66
+ def _register_for(app: typer.Typer, persona: str) -> None:
67
+ @command(
68
+ app,
69
+ persona,
70
+ "get",
71
+ "file",
72
+ api="LOCAL file_reader",
73
+ external="local",
74
+ help=_HELP,
75
+ )
76
+ def get_file(
77
+ path: Path = typer.Argument(..., help="The file to read."),
78
+ pictures_dir: Path | None = typer.Option(
79
+ None,
80
+ "--pictures-dir",
81
+ help="Where to save the PNG pictures (default: next to the file).",
82
+ ),
83
+ ) -> None:
84
+ print_json_or_exit(console, lambda: read_file_payload(path, pictures_dir))