eulumdat-report 1.0.0__tar.gz
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.
- eulumdat_report-1.0.0/LICENSE +21 -0
- eulumdat_report-1.0.0/PKG-INFO +175 -0
- eulumdat_report-1.0.0/README.md +141 -0
- eulumdat_report-1.0.0/pyproject.toml +54 -0
- eulumdat_report-1.0.0/setup.cfg +4 -0
- eulumdat_report-1.0.0/src/eulumdat_report/__init__.py +3 -0
- eulumdat_report-1.0.0/src/eulumdat_report/cli.py +94 -0
- eulumdat_report-1.0.0/src/eulumdat_report/collector.py +213 -0
- eulumdat_report-1.0.0/src/eulumdat_report/renderer.py +138 -0
- eulumdat_report-1.0.0/src/eulumdat_report/templates/default.css +187 -0
- eulumdat_report-1.0.0/src/eulumdat_report/templates/default.html +291 -0
- eulumdat_report-1.0.0/src/eulumdat_report.egg-info/PKG-INFO +175 -0
- eulumdat_report-1.0.0/src/eulumdat_report.egg-info/SOURCES.txt +16 -0
- eulumdat_report-1.0.0/src/eulumdat_report.egg-info/dependency_links.txt +1 -0
- eulumdat_report-1.0.0/src/eulumdat_report.egg-info/entry_points.txt +2 -0
- eulumdat_report-1.0.0/src/eulumdat_report.egg-info/requires.txt +13 -0
- eulumdat_report-1.0.0/src/eulumdat_report.egg-info/top_level.txt +1 -0
- eulumdat_report-1.0.0/tests/test_report.py +386 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 123VincentB
|
|
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,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: eulumdat-report
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Photometric datasheet generator (HTML + PDF) from EULUMDAT .ldt files
|
|
5
|
+
Author: 123VincentB
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/123VincentB/eulumdat-report
|
|
8
|
+
Project-URL: Repository, https://github.com/123VincentB/eulumdat-report
|
|
9
|
+
Keywords: photometry,eulumdat,ldt,lighting,report,pdf
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: eulumdat-py
|
|
22
|
+
Requires-Dist: eulumdat-analysis
|
|
23
|
+
Requires-Dist: eulumdat-plot
|
|
24
|
+
Requires-Dist: eulumdat-luminance
|
|
25
|
+
Requires-Dist: eulumdat-ugr
|
|
26
|
+
Requires-Dist: jinja2
|
|
27
|
+
Requires-Dist: weasyprint
|
|
28
|
+
Requires-Dist: click
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
31
|
+
Requires-Dist: build; extra == "dev"
|
|
32
|
+
Requires-Dist: twine; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# eulumdat-report
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/eulumdat-report/)
|
|
38
|
+
[](https://pypi.org/project/eulumdat-report/)
|
|
39
|
+
[](https://github.com/123VincentB/eulumdat-report/blob/main/LICENSE)
|
|
40
|
+
|
|
41
|
+
Photometric datasheet generator (HTML + PDF) from EULUMDAT `.ldt` files — orchestrates the full `eulumdat-*` ecosystem.
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
- Single-page A4 datasheet from any EULUMDAT `.ldt` file
|
|
46
|
+
- Polar intensity diagram (cd/klm) — `eulumdat-plot`
|
|
47
|
+
- Polar luminance diagram (cd/m²) + maximum luminance — `eulumdat-luminance`
|
|
48
|
+
- UGR catalogue table (CIE 117 / CIE 190, 19 rooms × 5 reflectances × 2 directions) — `eulumdat-ugr`
|
|
49
|
+
- Half-angles and FWHM per C-plane — `eulumdat-analysis`
|
|
50
|
+
- HTML output (self-contained, browser-ready A4 preview)
|
|
51
|
+
- PDF output via WeasyPrint (requires GTK — see installation notes)
|
|
52
|
+
- Custom Jinja2 template support
|
|
53
|
+
- CLI and Python API
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install eulumdat-report
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### PDF output (optional)
|
|
62
|
+
|
|
63
|
+
PDF rendering requires WeasyPrint with GTK libraries. On Windows, follow the
|
|
64
|
+
[WeasyPrint installation guide](https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#windows).
|
|
65
|
+
HTML output works on all platforms without GTK.
|
|
66
|
+
|
|
67
|
+
## Quick start
|
|
68
|
+
|
|
69
|
+
### CLI
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# HTML + PDF (PDF skipped gracefully if GTK not installed)
|
|
73
|
+
eulumdat-report luminaire.ldt
|
|
74
|
+
|
|
75
|
+
# HTML only, custom output directory
|
|
76
|
+
eulumdat-report luminaire.ldt --no-pdf --output-dir reports/
|
|
77
|
+
|
|
78
|
+
# All options
|
|
79
|
+
eulumdat-report --help
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Python API
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from eulumdat_report.collector import ReportCollector
|
|
86
|
+
from eulumdat_report.renderer import ReportRenderer
|
|
87
|
+
from pathlib import Path
|
|
88
|
+
|
|
89
|
+
data = ReportCollector.collect("luminaire.ldt")
|
|
90
|
+
html = ReportRenderer.render_html(data)
|
|
91
|
+
Path("luminaire.html").write_text(html, encoding="utf-8")
|
|
92
|
+
|
|
93
|
+
# PDF (requires GTK)
|
|
94
|
+
ReportRenderer.render_pdf(data, Path("luminaire.pdf"))
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## CLI reference
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
Usage: eulumdat-report [OPTIONS] LDT_FILE
|
|
101
|
+
|
|
102
|
+
Generate a photometric datasheet (HTML/PDF) from an EULUMDAT .ldt file.
|
|
103
|
+
|
|
104
|
+
Options:
|
|
105
|
+
-o, --output-dir DIRECTORY Output directory [default: same as LDT_FILE]
|
|
106
|
+
--template FILE Custom Jinja2 HTML template
|
|
107
|
+
--html / --no-html Generate HTML output [default: html]
|
|
108
|
+
--pdf / --no-pdf Generate PDF output [default: pdf]
|
|
109
|
+
-v, --verbose Enable debug logging
|
|
110
|
+
--help Show this message and exit
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Output filenames are derived from the input basename: `luminaire.ldt` → `luminaire.html` / `luminaire.pdf`.
|
|
114
|
+
|
|
115
|
+
## Template customisation
|
|
116
|
+
|
|
117
|
+
The default template is `src/eulumdat_report/templates/default.html` with companion `default.css`.
|
|
118
|
+
To customise, copy both files to a local directory and pass `--template` to the CLI:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
eulumdat-report luminaire.ldt --template my_templates/custom.html
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The template receives a single `data` object (`ReportData` dataclass). The following
|
|
125
|
+
Jinja2 filters are available:
|
|
126
|
+
|
|
127
|
+
| Filter | Description | Example |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| `thousands` | Space-separated thousands (int) | `12334` → `12 334` |
|
|
130
|
+
| `fmt1` | 1 decimal place | `184.6` |
|
|
131
|
+
| `ugr_fmt` | 1 decimal or `—` if None | `18.0` / `—` |
|
|
132
|
+
| `svg_responsive` | Makes SVG responsive (adds `viewBox`, sets `width=100%`) | |
|
|
133
|
+
|
|
134
|
+
SVG fields are embedded inline: `{{ data.svg_intensity \| svg_responsive \| safe }}`.
|
|
135
|
+
|
|
136
|
+
### Key `data` fields
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
data.luminaire_name # str
|
|
140
|
+
data.company # str
|
|
141
|
+
data.luminaire_number # str
|
|
142
|
+
data.isym # int (0–4)
|
|
143
|
+
data.mc, data.ng # int (C-planes, gamma angles)
|
|
144
|
+
data.lamp_flux # float (lm)
|
|
145
|
+
data.lamp_watt # float (W)
|
|
146
|
+
data.lorl # float (%)
|
|
147
|
+
data.lum_max # float | None (cd/m²)
|
|
148
|
+
data.svg_intensity # str | None
|
|
149
|
+
data.svg_luminance # str | None
|
|
150
|
+
data.ugr # UgrTableData | None
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Dependencies
|
|
154
|
+
|
|
155
|
+
| Package | Role |
|
|
156
|
+
|---|---|
|
|
157
|
+
| `eulumdat-py` | EULUMDAT parser |
|
|
158
|
+
| `eulumdat-plot` | Polar intensity diagram (SVG) |
|
|
159
|
+
| `eulumdat-luminance` | Polar luminance diagram (SVG) + maximum |
|
|
160
|
+
| `eulumdat-ugr` | UGR catalogue table |
|
|
161
|
+
| `eulumdat-analysis` | Half-angles, FWHM |
|
|
162
|
+
| `jinja2` | HTML templating |
|
|
163
|
+
| `weasyprint` | PDF rendering |
|
|
164
|
+
| `click` | CLI |
|
|
165
|
+
|
|
166
|
+
## Running the tests
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
pip install -e ".[dev]"
|
|
170
|
+
pytest
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# eulumdat-report
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/eulumdat-report/)
|
|
4
|
+
[](https://pypi.org/project/eulumdat-report/)
|
|
5
|
+
[](https://github.com/123VincentB/eulumdat-report/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
Photometric datasheet generator (HTML + PDF) from EULUMDAT `.ldt` files — orchestrates the full `eulumdat-*` ecosystem.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Single-page A4 datasheet from any EULUMDAT `.ldt` file
|
|
12
|
+
- Polar intensity diagram (cd/klm) — `eulumdat-plot`
|
|
13
|
+
- Polar luminance diagram (cd/m²) + maximum luminance — `eulumdat-luminance`
|
|
14
|
+
- UGR catalogue table (CIE 117 / CIE 190, 19 rooms × 5 reflectances × 2 directions) — `eulumdat-ugr`
|
|
15
|
+
- Half-angles and FWHM per C-plane — `eulumdat-analysis`
|
|
16
|
+
- HTML output (self-contained, browser-ready A4 preview)
|
|
17
|
+
- PDF output via WeasyPrint (requires GTK — see installation notes)
|
|
18
|
+
- Custom Jinja2 template support
|
|
19
|
+
- CLI and Python API
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install eulumdat-report
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### PDF output (optional)
|
|
28
|
+
|
|
29
|
+
PDF rendering requires WeasyPrint with GTK libraries. On Windows, follow the
|
|
30
|
+
[WeasyPrint installation guide](https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#windows).
|
|
31
|
+
HTML output works on all platforms without GTK.
|
|
32
|
+
|
|
33
|
+
## Quick start
|
|
34
|
+
|
|
35
|
+
### CLI
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# HTML + PDF (PDF skipped gracefully if GTK not installed)
|
|
39
|
+
eulumdat-report luminaire.ldt
|
|
40
|
+
|
|
41
|
+
# HTML only, custom output directory
|
|
42
|
+
eulumdat-report luminaire.ldt --no-pdf --output-dir reports/
|
|
43
|
+
|
|
44
|
+
# All options
|
|
45
|
+
eulumdat-report --help
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Python API
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from eulumdat_report.collector import ReportCollector
|
|
52
|
+
from eulumdat_report.renderer import ReportRenderer
|
|
53
|
+
from pathlib import Path
|
|
54
|
+
|
|
55
|
+
data = ReportCollector.collect("luminaire.ldt")
|
|
56
|
+
html = ReportRenderer.render_html(data)
|
|
57
|
+
Path("luminaire.html").write_text(html, encoding="utf-8")
|
|
58
|
+
|
|
59
|
+
# PDF (requires GTK)
|
|
60
|
+
ReportRenderer.render_pdf(data, Path("luminaire.pdf"))
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## CLI reference
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
Usage: eulumdat-report [OPTIONS] LDT_FILE
|
|
67
|
+
|
|
68
|
+
Generate a photometric datasheet (HTML/PDF) from an EULUMDAT .ldt file.
|
|
69
|
+
|
|
70
|
+
Options:
|
|
71
|
+
-o, --output-dir DIRECTORY Output directory [default: same as LDT_FILE]
|
|
72
|
+
--template FILE Custom Jinja2 HTML template
|
|
73
|
+
--html / --no-html Generate HTML output [default: html]
|
|
74
|
+
--pdf / --no-pdf Generate PDF output [default: pdf]
|
|
75
|
+
-v, --verbose Enable debug logging
|
|
76
|
+
--help Show this message and exit
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Output filenames are derived from the input basename: `luminaire.ldt` → `luminaire.html` / `luminaire.pdf`.
|
|
80
|
+
|
|
81
|
+
## Template customisation
|
|
82
|
+
|
|
83
|
+
The default template is `src/eulumdat_report/templates/default.html` with companion `default.css`.
|
|
84
|
+
To customise, copy both files to a local directory and pass `--template` to the CLI:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
eulumdat-report luminaire.ldt --template my_templates/custom.html
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The template receives a single `data` object (`ReportData` dataclass). The following
|
|
91
|
+
Jinja2 filters are available:
|
|
92
|
+
|
|
93
|
+
| Filter | Description | Example |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| `thousands` | Space-separated thousands (int) | `12334` → `12 334` |
|
|
96
|
+
| `fmt1` | 1 decimal place | `184.6` |
|
|
97
|
+
| `ugr_fmt` | 1 decimal or `—` if None | `18.0` / `—` |
|
|
98
|
+
| `svg_responsive` | Makes SVG responsive (adds `viewBox`, sets `width=100%`) | |
|
|
99
|
+
|
|
100
|
+
SVG fields are embedded inline: `{{ data.svg_intensity \| svg_responsive \| safe }}`.
|
|
101
|
+
|
|
102
|
+
### Key `data` fields
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
data.luminaire_name # str
|
|
106
|
+
data.company # str
|
|
107
|
+
data.luminaire_number # str
|
|
108
|
+
data.isym # int (0–4)
|
|
109
|
+
data.mc, data.ng # int (C-planes, gamma angles)
|
|
110
|
+
data.lamp_flux # float (lm)
|
|
111
|
+
data.lamp_watt # float (W)
|
|
112
|
+
data.lorl # float (%)
|
|
113
|
+
data.lum_max # float | None (cd/m²)
|
|
114
|
+
data.svg_intensity # str | None
|
|
115
|
+
data.svg_luminance # str | None
|
|
116
|
+
data.ugr # UgrTableData | None
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Dependencies
|
|
120
|
+
|
|
121
|
+
| Package | Role |
|
|
122
|
+
|---|---|
|
|
123
|
+
| `eulumdat-py` | EULUMDAT parser |
|
|
124
|
+
| `eulumdat-plot` | Polar intensity diagram (SVG) |
|
|
125
|
+
| `eulumdat-luminance` | Polar luminance diagram (SVG) + maximum |
|
|
126
|
+
| `eulumdat-ugr` | UGR catalogue table |
|
|
127
|
+
| `eulumdat-analysis` | Half-angles, FWHM |
|
|
128
|
+
| `jinja2` | HTML templating |
|
|
129
|
+
| `weasyprint` | PDF rendering |
|
|
130
|
+
| `click` | CLI |
|
|
131
|
+
|
|
132
|
+
## Running the tests
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
pip install -e ".[dev]"
|
|
136
|
+
pytest
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
MIT
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "eulumdat-report"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Photometric datasheet generator (HTML + PDF) from EULUMDAT .ldt files"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "123VincentB" }
|
|
13
|
+
]
|
|
14
|
+
keywords = ["photometry", "eulumdat", "ldt", "lighting", "report", "pdf"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
24
|
+
]
|
|
25
|
+
requires-python = ">=3.10"
|
|
26
|
+
dependencies = [
|
|
27
|
+
"eulumdat-py",
|
|
28
|
+
"eulumdat-analysis",
|
|
29
|
+
"eulumdat-plot",
|
|
30
|
+
"eulumdat-luminance",
|
|
31
|
+
"eulumdat-ugr",
|
|
32
|
+
"jinja2",
|
|
33
|
+
"weasyprint",
|
|
34
|
+
"click",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
dev = ["pytest>=7.0", "build", "twine"]
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
eulumdat-report = "eulumdat_report.cli:main"
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
Homepage = "https://github.com/123VincentB/eulumdat-report"
|
|
45
|
+
Repository = "https://github.com/123VincentB/eulumdat-report"
|
|
46
|
+
|
|
47
|
+
[tool.setuptools.packages.find]
|
|
48
|
+
where = ["src"]
|
|
49
|
+
|
|
50
|
+
[tool.setuptools.package-data]
|
|
51
|
+
eulumdat_report = ["templates/*.html", "templates/*.css"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""cli.py — eulumdat-report command-line interface."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import click
|
|
10
|
+
|
|
11
|
+
from .collector import ReportCollector
|
|
12
|
+
from .renderer import ReportRenderer
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@click.command()
|
|
18
|
+
@click.argument("ldt_file", type=click.Path(exists=True, dir_okay=False, path_type=Path))
|
|
19
|
+
@click.option(
|
|
20
|
+
"--output-dir", "-o",
|
|
21
|
+
type=click.Path(file_okay=False, path_type=Path),
|
|
22
|
+
default=None,
|
|
23
|
+
help="Output directory (default: same directory as LDT_FILE).",
|
|
24
|
+
)
|
|
25
|
+
@click.option(
|
|
26
|
+
"--template",
|
|
27
|
+
type=click.Path(exists=True, dir_okay=False, path_type=Path),
|
|
28
|
+
default=None,
|
|
29
|
+
help="Custom Jinja2 HTML template (default: built-in default.html).",
|
|
30
|
+
)
|
|
31
|
+
@click.option("--html/--no-html", default=True, show_default=True, help="Generate HTML output.")
|
|
32
|
+
@click.option("--pdf/--no-pdf", default=True, show_default=True, help="Generate PDF output.")
|
|
33
|
+
@click.option("-v", "--verbose", is_flag=True, help="Enable debug logging.")
|
|
34
|
+
def main(
|
|
35
|
+
ldt_file: Path,
|
|
36
|
+
output_dir: Path | None,
|
|
37
|
+
template: Path | None,
|
|
38
|
+
html: bool,
|
|
39
|
+
pdf: bool,
|
|
40
|
+
verbose: bool,
|
|
41
|
+
) -> None:
|
|
42
|
+
"""Generate a photometric datasheet (HTML/PDF) from an EULUMDAT .ldt file."""
|
|
43
|
+
logging.basicConfig(
|
|
44
|
+
level=logging.DEBUG if verbose else logging.WARNING,
|
|
45
|
+
format="%(levelname)s %(name)s: %(message)s",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if not html and not pdf:
|
|
49
|
+
click.echo("Nothing to do: both --no-html and --no-pdf specified.", err=True)
|
|
50
|
+
sys.exit(1)
|
|
51
|
+
|
|
52
|
+
dest = output_dir if output_dir is not None else ldt_file.parent
|
|
53
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
54
|
+
|
|
55
|
+
stem = ldt_file.stem
|
|
56
|
+
|
|
57
|
+
# ── Collect ──────────────────────────────────────────────────────────────
|
|
58
|
+
click.echo(f"Reading {ldt_file.name} ...")
|
|
59
|
+
try:
|
|
60
|
+
data = ReportCollector.collect(ldt_file)
|
|
61
|
+
except Exception as exc:
|
|
62
|
+
click.echo(f"Error reading {ldt_file}: {exc}", err=True)
|
|
63
|
+
sys.exit(1)
|
|
64
|
+
|
|
65
|
+
# ── HTML ─────────────────────────────────────────────────────────────────
|
|
66
|
+
if html:
|
|
67
|
+
html_path = dest / f"{stem}.html"
|
|
68
|
+
try:
|
|
69
|
+
html_str = ReportRenderer.render_html(data, template_path=template)
|
|
70
|
+
html_path.write_text(html_str, encoding="utf-8")
|
|
71
|
+
click.echo(f"HTML: {html_path}")
|
|
72
|
+
except Exception as exc:
|
|
73
|
+
click.echo(f"Error generating HTML: {exc}", err=True)
|
|
74
|
+
sys.exit(1)
|
|
75
|
+
|
|
76
|
+
# ── PDF ──────────────────────────────────────────────────────────────────
|
|
77
|
+
if pdf:
|
|
78
|
+
pdf_path = dest / f"{stem}.pdf"
|
|
79
|
+
try:
|
|
80
|
+
ReportRenderer.render_pdf(data, pdf_path, template_path=template)
|
|
81
|
+
click.echo(f"PDF : {pdf_path}")
|
|
82
|
+
except (ImportError, OSError) as exc:
|
|
83
|
+
if "libgobject" in str(exc) or "GTK" in str(exc) or isinstance(exc, ImportError):
|
|
84
|
+
click.echo(
|
|
85
|
+
"WeasyPrint requires GTK libraries which are not installed on this system. "
|
|
86
|
+
"PDF output skipped. See https://doc.courtbouillon.org/weasyprint/stable/first_steps.html",
|
|
87
|
+
err=True,
|
|
88
|
+
)
|
|
89
|
+
else:
|
|
90
|
+
click.echo(f"Error generating PDF: {exc}", err=True)
|
|
91
|
+
sys.exit(1)
|
|
92
|
+
except Exception as exc:
|
|
93
|
+
click.echo(f"Error generating PDF: {exc}", err=True)
|
|
94
|
+
sys.exit(1)
|