lf-toolbox 1.10.3__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.
cli.py ADDED
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env python3
2
+ """Toolbox CLI entry point.
3
+
4
+ This aggregates subcommands from the tools/ package using Typer.
5
+
6
+ Subcommands:
7
+ - tree: filesystem tree viewer + batch processor
8
+ - youtube: youtube/yt-dlp helpers
9
+ - clock: seven-segment clock, timer, countdown
10
+ - cheque: HK cheque wording (Traditional Chinese + English)
11
+ - plot: CSV plotting with pyqtgraph subplots
12
+
13
+ Examples:
14
+ python cli.py clock # full-screen clock
15
+ python cli.py clock -s large # choose size preset
16
+ python cli.py clock timer # stopwatch (counts up)
17
+ python cli.py clock countdown 10 # 10 seconds
18
+ python cli.py clock countdown 1 10 # 1 minute 10 seconds
19
+ python cli.py cheque 123.45 # cheque wording with cents
20
+ python cli.py plot data.csv # CSV plotting
21
+ """
22
+
23
+ from __future__ import annotations
24
+
25
+ from importlib.metadata import PackageNotFoundError, version
26
+
27
+ import typer
28
+
29
+ from tools import TOOL_COMMANDS
30
+ from tools._cli_common import new_typer_app
31
+
32
+
33
+ # Root Typer app; expose -h/--help on all levels
34
+ app = new_typer_app()
35
+
36
+
37
+ def _toolbox_version() -> str:
38
+ """Return installed package version string."""
39
+ try:
40
+ return version("lf-toolbox")
41
+ except PackageNotFoundError:
42
+ return "unknown"
43
+
44
+
45
+ def _version_callback(show_version: bool) -> None:
46
+ """Print CLI version and exit early when requested."""
47
+ if show_version:
48
+ typer.echo(_toolbox_version())
49
+ raise typer.Exit()
50
+
51
+
52
+ @app.callback()
53
+ def _root_callback(
54
+ version_opt: bool = typer.Option(
55
+ False,
56
+ "--version",
57
+ "-v",
58
+ help="Show toolbox version and exit.",
59
+ callback=_version_callback,
60
+ is_eager=True,
61
+ ),
62
+ ) -> None:
63
+ """Root callback for global options."""
64
+ _ = version_opt
65
+
66
+
67
+ # Mount sub-apps under their command names. With invoke_without_command=True,
68
+ # running, e.g., `python cli.py clock` executes clock's default callback.
69
+ for command in TOOL_COMMANDS:
70
+ app.add_typer(
71
+ command.app,
72
+ name=command.name,
73
+ invoke_without_command=command.invoke_without_command,
74
+ )
75
+
76
+
77
+ if __name__ == "__main__":
78
+ # Delegate to Typer's CLI runner
79
+ app()
@@ -0,0 +1,447 @@
1
+ Metadata-Version: 2.4
2
+ Name: lf-toolbox
3
+ Version: 1.10.3
4
+ Summary: CLI toolbox with tree/work, YouTube helpers, terminal clock, cheque wording, and CSV plotting.
5
+ Author: lf
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/o0fung/toolbox
8
+ Project-URL: Repository, https://github.com/o0fung/toolbox
9
+ Project-URL: Issues, https://github.com/o0fung/toolbox/issues
10
+ Keywords: cli,toolbox,typer,utilities,productivity
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Environment :: Console
14
+ Classifier: Topic :: Utilities
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: numpy>=2.0.0
19
+ Requires-Dist: PyQt6>=6.7.0
20
+ Requires-Dist: pyqtgraph>=0.13.7
21
+ Requires-Dist: rich>=14.0.0
22
+ Requires-Dist: typer>=0.16.0
23
+ Requires-Dist: yt-dlp>=2025.8.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
26
+ Provides-Extra: publish
27
+ Requires-Dist: build>=1.2.2; extra == "publish"
28
+ Requires-Dist: twine>=6.1.0; extra == "publish"
29
+ Provides-Extra: plot
30
+ Requires-Dist: python-dateutil>=2.9.0.post0; extra == "plot"
31
+ Dynamic: license-file
32
+
33
+
34
+ # lf-toolbox
35
+
36
+ A set of useful command-line tools for enhancing productivity.
37
+
38
+ ## Features
39
+
40
+ - **tree**: Display a directory tree with optional depth/hidden skipping, plus a flexible batch file processor that imports your function from a sibling Python file.
41
+ - **youtube**: Download YouTube videos, audio, and subtitles, or display video metadata.
42
+ - **clock**: Full-screen seven-segment terminal clock with stopwatch and countdown.
43
+ - **cheque**: Convert HKD amounts (supports cents) to formal HK cheque wording in Traditional Chinese and English.
44
+ - **plot**: Plot CSV data with pyqtgraph subplots.
45
+
46
+ ## Installation
47
+
48
+ Install from PyPI (recommended):
49
+ ```sh
50
+ pipx install lf-toolbox
51
+ ```
52
+
53
+ Or via pip:
54
+ ```sh
55
+ pip install lf-toolbox
56
+ ```
57
+
58
+ Install from GitHub:
59
+ ```sh
60
+ pip install "git+https://github.com/o0fung/toolbox.git"
61
+ ```
62
+
63
+ For local development:
64
+ ```sh
65
+ git clone https://github.com/o0fung/toolbox.git
66
+ cd toolbox
67
+ python -m venv .venv
68
+ source .venv/bin/activate
69
+ python -m pip install -U pip
70
+ python -m pip install -e ".[dev]"
71
+ ```
72
+
73
+ ## Upgrade
74
+
75
+ Upgrade a pipx install:
76
+ ```sh
77
+ pipx upgrade lf-toolbox
78
+ ```
79
+
80
+ Upgrade a pip install:
81
+ ```sh
82
+ pip install -U lf-toolbox
83
+ ```
84
+
85
+ Upgrade from GitHub:
86
+ ```sh
87
+ pip install -U "git+https://github.com/o0fung/toolbox.git"
88
+ ```
89
+
90
+ If pip says it's already satisfied or the version hasn't changed, force a reinstall:
91
+ ```sh
92
+ pip install -U --force-reinstall "git+https://github.com/o0fung/toolbox.git"
93
+ ```
94
+
95
+ ## Publish to PyPI
96
+
97
+ See `RELEASING.md` for the GitHub Release -> GitHub Actions -> PyPI publish checklist.
98
+
99
+ ## Usage
100
+
101
+ Run the installed CLI:
102
+ ```sh
103
+ lf --help
104
+ ```
105
+
106
+ Or run via Python entry point in this repo:
107
+ ```sh
108
+ python cli.py [COMMAND] [OPTIONS]
109
+ ```
110
+
111
+
112
+ ---
113
+
114
+ ## 🚩 tree
115
+
116
+ Display a directory tree.
117
+
118
+ **Usage:**
119
+ ```sh
120
+ python cli.py tree show PATH [--depth DEPTH] [--skip-hidden]
121
+ ```
122
+
123
+ - `PATH`: Root directory to display.
124
+ - `--depth`, `-d`: Maximum depth to display (default: unlimited).
125
+ - `--skip-hidden`, `-s`: Skip hidden files and directories.
126
+
127
+ ### Batch file processor
128
+
129
+ Import and execute a function from a Python module located in the same folder as the target file/folder. The function will be called for each discovered file.
130
+
131
+ Usage:
132
+ ```sh
133
+ # Installed entrypoint
134
+ lf tree work PATH [-d DEPTH] [--skip-hidden] [-m MODULE] [-f FUNC]
135
+
136
+ # From the repo
137
+ python cli.py tree work PATH [-d DEPTH] [--skip-hidden] [-m MODULE] [-f FUNC]
138
+ ```
139
+
140
+ Options:
141
+ - `PATH` (required): A file or a directory. If a directory, items are processed up to the specified depth.
142
+ - `-d, --depth` (default: 1): Maximum depth when displaying/processing.
143
+ - `-s, --skip-hidden`: Skip hidden/special files (dot- or underscore-prefixed).
144
+ - `-m, --module` (default: `_script`): Python module name (without `.py`) in the same folder as `PATH` to import.
145
+ - `-f, --func` (default: `_test`): Function name to call inside the module. It should accept a single `filepath: str` argument. If the function returns a non-None string, it will be shown on that file’s line.
146
+
147
+ Behavior niceties:
148
+ - If the module file doesn’t exist, a template is copied from `tools/_script.py` to help you start quickly.
149
+ - If the function doesn’t exist in the module, a stub will be appended automatically so you can fill it in.
150
+
151
+ Example stub and runs:
152
+ ```py
153
+ # In the same folder as your files, create _script.py with:
154
+ from pathlib import Path
155
+
156
+ def _test(filepath: str):
157
+ p = Path(filepath)
158
+ if p.suffix.lower() == ".txt":
159
+ new = p.with_name(p.stem + "_bak" + p.suffix)
160
+ p.rename(new)
161
+ return f"Renamed: {p.name} -> {new.name}"
162
+ ```
163
+
164
+ ```sh
165
+ # Rename .txt files in a folder (depth 1)
166
+ lf tree work ~/docs -m _script -f _test
167
+
168
+ # Show tree only
169
+ lf tree show ~/docs -d 2 -s
170
+ ```
171
+
172
+ ---
173
+
174
+ ## 🚩 youtube
175
+
176
+ Download YouTube content, list formats, or show metadata (powered by `yt-dlp`).
177
+
178
+ **Basic Usage:**
179
+ ```sh
180
+ python cli.py youtube URL [options]
181
+ ```
182
+
183
+ If no download-related flags are given, metadata only is displayed.
184
+
185
+ **Common Flags:**
186
+ - `URL` (positional): YouTube video URL.
187
+ - `--video`, `-v`: Download best video (mp4-preferred) with audio using smart fallback formats.
188
+ - `--audio`, `-a`: Download best audio and convert to mp3 (192 kbps) via ffmpeg.
189
+ - `--subtitle`, `-s`: Download English subtitles (manual + auto). Use with other modes or alone (metadata + subs).
190
+ - `--list`: List all available formats (no download) in a compact table.
191
+ - `--fmt FORMAT_EXPR`: Explicit yt-dlp format selector (e.g. `251`, `137+251`, `bestvideo[height<=720]+bestaudio/best`). Overrides `-v/-a` logic.
192
+ - `--out DIR`: Output directory (default: `~/Desktop`). Created if missing.
193
+
194
+ **Format Fallback Logic (when using `-v` without `--fmt`):**
195
+ 1. `bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]`
196
+ 2. `bestvideo*+bestaudio*/bestvideo+bestaudio`
197
+ 3. `best`
198
+
199
+ Each failed attempt logs a warning and moves to the next expression. On total failure you'll be prompted to run `--list` and choose a format via `--fmt`.
200
+
201
+ **Examples:**
202
+ ```sh
203
+ # Show metadata only
204
+ python cli.py youtube https://www.youtube.com/watch?v=ID
205
+
206
+ # List formats
207
+ python cli.py youtube https://www.youtube.com/watch?v=ID --list
208
+
209
+ # Download best mp4 (auto fallback) to Desktop
210
+ python cli.py youtube https://www.youtube.com/watch?v=ID -v
211
+
212
+ # Download audio only as mp3 to a custom folder
213
+ python cli.py youtube https://www.youtube.com/watch?v=ID -a --out ~/Media/audio
214
+
215
+ # Download subtitles only (no media)
216
+ python cli.py youtube https://www.youtube.com/watch?v=ID -s
217
+
218
+ # Explicit format combine 1080p video (137) + opus audio (251)
219
+ python cli.py youtube https://www.youtube.com/watch?v=ID --fmt 137+251 --out ./downloads
220
+
221
+ # Constrain height (yt-dlp expression)
222
+ python cli.py youtube https://www.youtube.com/watch?v=ID --fmt "bestvideo[height<=720]+bestaudio/best[height<=720]"
223
+ ```
224
+
225
+ **Notes:**
226
+ - Filenames are the video title; adjust or sanitize as needed manually for now.
227
+ - Subtitles default language: English (`--subtitle` enables both manual + auto if available).
228
+ - Use `--fmt` for full control; all yt-dlp format selectors are supported.
229
+ - Output directory is echoed at start: `[info] Output directory: /path/...`
230
+ - When all format attempts fail you will see a hint to run `--list`.
231
+
232
+ ---
233
+
234
+ ## 🚩 clock
235
+
236
+ Full-screen digital clock rendered with block characters using Rich. Updates every second.
237
+
238
+ **Usage:**
239
+ ```sh
240
+ # Clock (from the repo)
241
+ python cli.py clock [-c COLOR] [-s SIZE]
242
+
243
+ # Stopwatch (counts up)
244
+ python cli.py clock timer [-c COLOR] [-s SIZE]
245
+
246
+ # Countdown (flexible input)
247
+ # S -> seconds
248
+ # H M -> hours minutes
249
+ # H M S -> hours minutes seconds
250
+ # Non-digit separators like spaces, ':', ',', '/' are accepted.
251
+ python cli.py clock countdown 45 // 45 seconds
252
+ python cli.py clock countdown 1 10 // 1 minute 10 seconds
253
+ python cli.py clock countdown 1 0 1 // 1 hour and 1 second
254
+ python cli.py clock countdown 2:15:00 -s xlarge -c magenta // 2 hours 15 minutes
255
+ ```
256
+
257
+ - Press `Ctrl+C` to quit.
258
+
259
+ Options:
260
+ - `--color`, `-c`: Rich color style for digits (e.g., cyan, magenta, "#00ff00").
261
+ - `--size`, `-s`: Size preset. One of: `small`, `medium`, `large`, `xlarge`, `xxlarge`, `xxxlarge`.
262
+
263
+ Notes:
264
+ - When running `clock` without a subcommand, the live clock UI starts.
265
+ - When running a subcommand (`timer`, `countdown`), the clock UI callback does not run.
266
+ - The countdown holds at `00:00:00` until you press `Ctrl+C`.
267
+
268
+ ---
269
+
270
+ ## 🚩 cheque
271
+
272
+ Render HKD amounts (dollars + optional cents) as formal wording for Hong Kong cheques in both Traditional Chinese and English.
273
+
274
+ Usage:
275
+ ```sh
276
+ # From the repo
277
+ python cli.py cheque AMOUNT
278
+ ```
279
+
280
+ - `AMOUNT`: Non-negative numeric amount with up to 2 decimal places. Examples: `0`, `10`, `1234567`, `123.45`, `0.05`.
281
+
282
+ Output format:
283
+ - Chinese:
284
+ - cents is zero: `中文:港幣<FINANCIAL_UPPERCASE>元正`
285
+ - cents exists: `中文:港幣<FINANCIAL_UPPERCASE>元<角分>`
286
+ - English: `English: Hong Kong Dollars <words> only`
287
+
288
+ Rules implemented:
289
+ - Chinese uses financial uppercase numerals (壹貳叁肆伍陸柒捌玖零) with units: 仟佰拾 within each group and 萬/億/兆 across groups.
290
+ - Inserts a single `零` where a unit gap is present (e.g., 1001 -> 壹仟零壹;1000001 -> 壹佰萬零壹)。
291
+ - Chinese cents are rendered with `角`/`分` (e.g., `0.05` -> `零伍分`).
292
+ - English follows British/HK style:
293
+ - Uses "and" within hundreds (e.g., one hundred and two).
294
+ - Uses "and" between the last group (<100) and a higher group (e.g., one thousand and ten).
295
+ - Hyphenates 21–99 (e.g., twenty-one).
296
+ - Cents are rendered in words (e.g., `123.45` -> `... and forty-five cents only`).
297
+
298
+ Examples:
299
+ ```text
300
+ python cli.py cheque 0
301
+ 中文:港幣零元正
302
+ English: Hong Kong Dollars Zero only
303
+
304
+ python cli.py cheque 1001
305
+ 中文:港幣壹仟零壹元正
306
+ English: Hong Kong Dollars One thousand and one only
307
+
308
+ python cli.py cheque 1000001
309
+ 中文:港幣壹佰萬零壹元正
310
+ English: Hong Kong Dollars One million and one only
311
+
312
+ python cli.py cheque 120034
313
+ 中文:港幣壹拾貳萬零叁拾肆元正
314
+ English: Hong Kong Dollars One hundred and twenty thousand and thirty-four only
315
+
316
+ python cli.py cheque 123.45
317
+ 中文:港幣壹佰貳拾叁元肆角伍分
318
+ English: Hong Kong Dollars One hundred and twenty-three and forty-five cents only
319
+
320
+ python cli.py cheque 0.05
321
+ 中文:港幣零元零伍分
322
+ English: Hong Kong Dollars Zero and five cents only
323
+ ```
324
+
325
+ Notes:
326
+ - Extend English scales beyond trillion by editing `tools/cheque.py` if needed.
327
+
328
+ ---
329
+
330
+ ## 🚩 plot
331
+
332
+ **Usage:**
333
+ ```sh
334
+ # From the repo
335
+ python cli.py plot FILE [options]
336
+
337
+ # Installed entrypoint
338
+ lf plot FILE [options]
339
+ ```
340
+
341
+ **Key Options:**
342
+ - `FILE` (required): CSV/TSV file path.
343
+ - `-d, --delimiter DELIM`: Force delimiter (auto-sniff if omitted across , \t ; | space).
344
+ - `-t, --title TEXT`: Window title.
345
+ - `-x, --xcol NAME|INDEX`: Column to use as X axis (time-like, numeric, or fallback to row indices). Default: first column.
346
+ - `-y, --ycols COLS`: Comma-separated list of Y columns (names or indices). Default: all numeric except the chosen x column.
347
+ - `--xlim start,end`: Row index slice (inclusive) before plotting. Accepts comma or colon: `--xlim 200,300` or `--xlim 200:300`. Empty start/end allowed (`,500` or `500,`).
348
+ - `-s, --save`: Export a high‑resolution PNG (ImageExporter; independent of window size) next to the CSV (same basename) and exit. Env overrides: `PLOT_EXPORT_WIDTH`, `PLOT_EXPORT_PER_PLOT`.
349
+ - `-w, --weight FLOAT`: Line width (in pixels) for all plotted lines (default 1.0). Increase (e.g. 2 or 3) to make thin signals more visible.
350
+ - `-o, --out-path PATH`: Output PNG path or directory (implies `--save` if not explicitly provided). If a directory or ends with a path separator, the file name `<csv_basename>.png` is used. `.png` extension appended if missing.
351
+
352
+ **Automatic X-axis detection:**
353
+ 1. If selected x column parses as (mostly) datetimes or epoch seconds/milliseconds -> time axis (DateAxisItem).
354
+ 2. Else if (mostly) numeric -> numeric index using the column’s values.
355
+ 3. Else -> simple row index (0..N-1).
356
+
357
+ **Y column selection:**
358
+ - Columns with ≥ ~60% numeric entries qualify automatically (unless overridden with `--ycols`).
359
+ - Non-numeric cells become gaps (NaN) in the plot.
360
+
361
+ **Index trimming (`--xlim`):**
362
+ - Applied to row indices, not data values or timestamps.
363
+ - Example: `--xlim 1000,2000` keeps only rows 1000–2000 inclusive.
364
+ - `--xlim ,500` keeps start through 500; `--xlim 500,` keeps 500 through end.
365
+
366
+ **White Theme:**
367
+ - Background forced to white; axes/text black; subtle grid (alpha 0.15).
368
+ - Exported PNG uses the same theme.
369
+
370
+ **Examples:**
371
+ ```sh
372
+ # Quick auto plot
373
+ lf plot ~/data/sensors.csv
374
+
375
+ # Tab-delimited with custom title
376
+ lf plot ~/data/log.tsv -d $'\t' -t "Device Log"
377
+
378
+ # Explicit x column by name and selected y columns
379
+ lf plot data.csv -x timestamp -y temperature,pressure,3
380
+
381
+ # Restrict to row indices 200..300
382
+ lf plot data.csv --xlim 200,300
383
+
384
+ # Export a high-res PNG (no GUI)
385
+ lf plot data.csv -y acc_x,acc_y,acc_z -s
386
+
387
+ # Export to a specific file path (auto-enables save mode)
388
+ lf plot data.csv -o ~/Desktop/plots/session1.png
389
+
390
+ # Custom export size via environment
391
+ PLOT_EXPORT_WIDTH=3000 PLOT_EXPORT_PER_PLOT=250 lf plot data.csv -s
392
+
393
+ # Thicker lines for visibility
394
+ lf plot data.csv -y acc_x,acc_y,acc_z -w 2.5
395
+ ```
396
+
397
+ **Console Output Summary:** (example)
398
+ ```text
399
+ Loaded 6000 rows, 18 columns from: data.csv
400
+ Using x-axis: index (column: time[0])
401
+ Y subplots: (6 / 17)
402
+ Selected channels (6): acc_x[3], acc_y[4], acc_z[5], gyr_x[6], gyr_y[7], gyr_z[8]
403
+ Unselected channels (11): temp[9], pressure[10], battery[11], state[12], ...
404
+ Index trim -> kept indices [1000,1500] (501 points)
405
+ Data points (x): [1000,1500] (501 / 6000 points selected)
406
+ Saved PNG: data.png (width=2400px, plots=6, line-width=2.5)
407
+ ```
408
+ Notes:
409
+ - Channel indices in brackets are zero-based column positions from the original CSV.
410
+ - Unselected list excludes the chosen x-axis column.
411
+ - When no trimming is applied you will see `(full dataset)` instead of a selected fraction.
412
+
413
+ **Requirements:**
414
+ - Desktop GUI environment (macOS, Windows, Linux with X11/Wayland).
415
+ - Dependencies: `PyQt6`, `pyqtgraph` (plus optional `python-dateutil` for richer date parsing).
416
+
417
+ **Keyboard Shortcuts (interactive mode):**
418
+ - `Esc`: Close the window and exit.
419
+
420
+ **Other Behaviors:**
421
+ - Supplying `--out-path` without `--save` prints a note and performs a save (no interactive session).
422
+ - Rows with non-numeric Y values render gaps (NaN) in lines instead of aborting.
423
+
424
+ **Planned (possible future additions):** trimmed-segment CSV export, interactive ROI selection, overlay/legend mode, optional scaled vector/SVG export.
425
+
426
+ ---
427
+
428
+ ## Project Structure
429
+
430
+ ```
431
+ cli.py # Main CLI entry point
432
+ tools/
433
+ _cli_common.py # Shared Typer app factory
434
+ _cli_output.py # Shared CLI output helpers
435
+ tree.py # Directory tree tool
436
+ youtube.py # YouTube downloader tool
437
+ clock.py # Full-screen seven-segment terminal clock
438
+ cheque.py # HK cheque wording (Chinese + English)
439
+ plot.py # CSV plotting with pyqtgraph (PyQt6)
440
+ tests/
441
+ test_cheque.py
442
+ test_tree.py
443
+ ```
444
+
445
+ ## License
446
+
447
+ See `LICENSE` for details.
@@ -0,0 +1,16 @@
1
+ cli.py,sha256=KgIeJ24fUtlUQAcPW1U1Y_R4TE1R1EHFq4giSzNmmAI,2220
2
+ lf_toolbox-1.10.3.dist-info/licenses/LICENSE,sha256=VAtDVeUzP4caO6ImonMFiUxuVY9XdKstt5kvjUtia1k,1063
3
+ tools/__init__.py,sha256=N8DW2MdYuGdTFMpR3zhNEUEcyEGHSItZdh3lUbWIqzk,904
4
+ tools/_cli_common.py,sha256=jLHfQd3D085E56lzFum_sNPxVsjuMuczzumJfoWL1UE,492
5
+ tools/_cli_output.py,sha256=ljWKmqGSVVQGKCzWLx1jxnWEFiN8GpAjRSCLmIbl8HA,732
6
+ tools/_script.py,sha256=BTJLsWMS2Gvtw1kJ5JCP9iX62Dz5rj-B3KzNBdrSu-Q,698
7
+ tools/cheque.py,sha256=ZDU3vEJFEium1JjAYdeNWH1ePHuqY56H8luBYYP8Edc,8802
8
+ tools/clock.py,sha256=S-oG1AgcgJdncMVjitKRkqW8l4j09yyEelpnAItOT-Q,12284
9
+ tools/plot.py,sha256=jJMBdiLKofIHo45BeoZNiuhVuyLDNyCHjAw4dGmA-JU,17221
10
+ tools/tree.py,sha256=PYOPSZuIJeDYHjKiPFYEtpVM8mbMTR1P1bu7X7sMKPY,7467
11
+ tools/youtube.py,sha256=OniLFDHRshSIhu_PJTqJ-_KE5XtI3bLmyMtY89Vp6Yk,10530
12
+ lf_toolbox-1.10.3.dist-info/METADATA,sha256=GjhLQPsiSzd75j31r4N-V2YakJAesINuV08hQuY52vY,15067
13
+ lf_toolbox-1.10.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
14
+ lf_toolbox-1.10.3.dist-info/entry_points.txt,sha256=H-S_-ynmCMKPEwA8eVVZkkW4YgfYFNVrUnHo7gHP8G0,31
15
+ lf_toolbox-1.10.3.dist-info/top_level.txt,sha256=CXePm3jINa7SS3yDrI4qvtycvntP3PyFIjO56aIgrac,10
16
+ lf_toolbox-1.10.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ lf = cli:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 o0fung
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ cli
2
+ tools
tools/__init__.py ADDED
@@ -0,0 +1,38 @@
1
+ """toolbox.tools package."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ import typer
8
+
9
+ from . import cheque, clock, plot, tree, youtube
10
+
11
+
12
+ @dataclass(frozen=True)
13
+ class ToolCommand:
14
+ """Declarative CLI registration entry for a toolbox subcommand."""
15
+
16
+ name: str
17
+ app: typer.Typer
18
+ invoke_without_command: bool = False
19
+
20
+
21
+ TOOL_COMMANDS: tuple[ToolCommand, ...] = (
22
+ ToolCommand(name="tree", app=tree.app, invoke_without_command=False),
23
+ ToolCommand(name="youtube", app=youtube.app, invoke_without_command=True),
24
+ ToolCommand(name="clock", app=clock.app, invoke_without_command=True),
25
+ ToolCommand(name="cheque", app=cheque.app, invoke_without_command=True),
26
+ ToolCommand(name="plot", app=plot.app, invoke_without_command=True),
27
+ )
28
+
29
+
30
+ __all__ = [
31
+ "tree",
32
+ "youtube",
33
+ "clock",
34
+ "cheque",
35
+ "plot",
36
+ "ToolCommand",
37
+ "TOOL_COMMANDS",
38
+ ]
tools/_cli_common.py ADDED
@@ -0,0 +1,16 @@
1
+ """Shared CLI helpers for toolbox commands."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ import typer
8
+
9
+ HELP_OPTION_NAMES = ("-h", "--help")
10
+
11
+
12
+ def new_typer_app(**kwargs: Any) -> typer.Typer:
13
+ """Create a Typer app with consistent help flag shortcuts."""
14
+ context_settings = dict(kwargs.pop("context_settings", {}) or {})
15
+ context_settings.setdefault("help_option_names", list(HELP_OPTION_NAMES))
16
+ return typer.Typer(context_settings=context_settings, **kwargs)
tools/_cli_output.py ADDED
@@ -0,0 +1,28 @@
1
+ """Shared console output helpers for CLI tools."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import NoReturn
6
+
7
+ import typer
8
+
9
+
10
+ def info(message: str) -> None:
11
+ """Print a neutral informational message."""
12
+ typer.echo(f"[info] {message}")
13
+
14
+
15
+ def warn(message: str) -> None:
16
+ """Print a warning message."""
17
+ typer.secho(f"[warn] {message}", fg=typer.colors.YELLOW)
18
+
19
+
20
+ def error(message: str, *, err: bool = True) -> None:
21
+ """Print an error message."""
22
+ typer.secho(f"[error] {message}", fg=typer.colors.RED, err=err)
23
+
24
+
25
+ def fatal(message: str, *, code: int = 1, err: bool = True) -> NoReturn:
26
+ """Print an error message and terminate the command."""
27
+ error(message, err=err)
28
+ raise typer.Exit(code=code)
tools/_script.py ADDED
@@ -0,0 +1,24 @@
1
+ import re
2
+ import os
3
+
4
+ def _test(filepath: str):
5
+ """
6
+ Given a full file path, search regular expression pattern.
7
+
8
+ Returns OK if found the match.
9
+ """
10
+
11
+ # Regex works on the full path. It captures:
12
+ # dir: any leading directory part (optional)
13
+ # name: the base name WITHOUT the trailing '_test'
14
+ # ext: the file extension (optional)
15
+ # This matches only when the stem ends with '_test'.
16
+ pattern = re.compile(r"(?P<dir>.*/)?(?P<name>[^/]+?)(?P<ext>\.[^/]+)?$")
17
+ x = pattern.search(filepath)
18
+ if not x:
19
+ return None
20
+
21
+ # outpath = f"{x.group('dir') or ''}{x.group('name')}{x.group('ext') or ''}"
22
+ # os.rename(filepath, outpath)
23
+
24
+ return 'OK'