|
50 | 50 | from sdpm.preview import ( |
51 | 51 | _is_wsl, |
52 | 52 | check_layout_imbalance, |
| 53 | + export_pdf, |
53 | 54 | get_tmp_project_dir, |
54 | 55 | refresh_autofit, |
55 | 56 | unlock_height_constraints, |
|
71 | 72 |
|
72 | 73 | def _resolve_template(data, input_path): |
73 | 74 | """Resolve template path: presentation.json "template" → templates/default-dark.pptx → repo fallback.""" |
74 | | - templates_dir = Path(__file__).parent.parent / "templates" |
| 75 | + from sdpm.config import resolve_templates_dir |
| 76 | + |
| 77 | + templates_dir = resolve_templates_dir() |
75 | 78 |
|
76 | 79 | if data.get("template"): |
77 | 80 | base_dir = Path(input_path).parent if input_path and input_path != "-" else Path(".") |
@@ -256,58 +259,17 @@ def cmd_preview(args): |
256 | 259 | import shutil |
257 | 260 | shutil.rmtree(png_dir, ignore_errors=True) |
258 | 261 | else: |
259 | | - # macOS / WSL: PDF + pdftoppm pipeline |
| 262 | + # PDF + pdftoppm pipeline (macOS / WSL / Linux) |
260 | 263 | pdf_path = output_dir / "slides.pdf" |
261 | 264 | pre_generated_pdf = getattr(args, '_pdf_path', None) |
262 | 265 |
|
263 | 266 | if pre_generated_pdf and Path(pre_generated_pdf).exists(): |
264 | | - # PDF already generated by _refresh_autofit — skip PowerPoint |
265 | 267 | import shutil |
266 | 268 | if str(Path(pre_generated_pdf).resolve()) != str(pdf_path.resolve()): |
267 | 269 | shutil.copy2(pre_generated_pdf, pdf_path) |
268 | 270 | else: |
269 | | - if _is_wsl(): |
270 | | - win_pptx = subprocess.run(["wslpath", "-w", str(pptx_path)], capture_output=True, text=True).stdout.strip() # nosec B603 # nosemgrep: python.lang.security.audit.dangerous-subprocess-use-audit |
271 | | - win_pdf = subprocess.run(["wslpath", "-w", str(pdf_path)], capture_output=True, text=True).stdout.strip() # nosec B603 # nosemgrep: python.lang.security.audit.dangerous-subprocess-use-audit |
272 | | - ps_cmd = ( |
273 | | - f"$app = New-Object -ComObject PowerPoint.Application; " |
274 | | - f"$prs = $app.Presentations.Open('{win_pptx}', " |
275 | | - f"[Microsoft.Office.Core.MsoTriState]::msoTrue, " |
276 | | - f"[Microsoft.Office.Core.MsoTriState]::msoFalse, " |
277 | | - f"[Microsoft.Office.Core.MsoTriState]::msoFalse); " |
278 | | - f"$prs.SaveAs('{win_pdf}', 32); " |
279 | | - f"$prs.Close(); $app.Quit()" |
280 | | - ) |
281 | | - result = subprocess.run( |
282 | | - ["/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe", "-Command", ps_cmd], |
283 | | - capture_output=True, timeout=60) # nosec B603 # nosemgrep: python.lang.security.audit.dangerous-subprocess-use-audit |
284 | | - result = subprocess.CompletedProcess( |
285 | | - result.args, result.returncode, |
286 | | - stdout=result.stdout.decode("cp932", errors="replace") if result.stdout else "", |
287 | | - stderr=result.stderr.decode("cp932", errors="replace") if result.stderr else "" |
288 | | - ) |
289 | | - else: |
290 | | - from sdpm.preview import ( |
291 | | - _mac_open_pptx_background, |
292 | | - _mac_restore_pptx_focus_async, |
293 | | - ) |
294 | | - pptx_name = Path(pptx_path).name |
295 | | - restore_info = _mac_open_pptx_background(pptx_path) |
296 | | - _mac_restore_pptx_focus_async(restore_info) |
297 | | - import time |
298 | | - time.sleep(2) |
299 | | - script = f''' |
300 | | - tell application "Microsoft PowerPoint" |
301 | | - set theDoc to presentation "{pptx_name}" |
302 | | - set outPath to (POSIX file "{pdf_path}") as text |
303 | | - save theDoc in outPath as save as PDF |
304 | | - close theDoc saving no |
305 | | - end tell |
306 | | - ''' |
307 | | - result = subprocess.run(["osascript", "-e", script], capture_output=True, text=True) # nosec B603 # nosemgrep: python.lang.security.audit.dangerous-subprocess-use-audit |
308 | | - |
309 | | - if result.returncode != 0 or not pdf_path.exists(): |
310 | | - print(f"Error: PDF export failed: {result.stderr}", file=sys.stderr) |
| 271 | + if not export_pdf(pptx_path, pdf_path): |
| 272 | + print("Error: PDF export failed", file=sys.stderr) |
311 | 273 | sys.exit(1) |
312 | 274 |
|
313 | 275 | # Parse pages to export |
@@ -417,7 +379,9 @@ def cmd_list_asset_sources(args): |
417 | 379 |
|
418 | 380 | def cmd_list_templates(args): |
419 | 381 | """List available PPTX templates.""" |
420 | | - templates_dir = Path(__file__).parent.parent / "templates" |
| 382 | + from sdpm.config import resolve_templates_dir |
| 383 | + |
| 384 | + templates_dir = resolve_templates_dir() |
421 | 385 | if not templates_dir.exists(): |
422 | 386 | print("No templates directory found.", file=sys.stderr) |
423 | 387 | return |
@@ -557,7 +521,9 @@ def cmd_examples(args): |
557 | 521 |
|
558 | 522 | # styles/ directory — always show full content |
559 | 523 | if base == "styles": |
560 | | - styles_dir = examples_dir / "styles" |
| 524 | + from sdpm.config import resolve_styles_dir |
| 525 | + |
| 526 | + styles_dir = resolve_styles_dir() |
561 | 527 | if not styles_dir.exists(): |
562 | 528 | print("# Not found: styles/", file=sys.stderr) |
563 | 529 | continue |
@@ -661,7 +627,9 @@ def cmd_init(args): |
661 | 627 | spec_files = ["brief.md", "outline.md"] |
662 | 628 | if args.style: |
663 | 629 | # Copy style HTML as art-direction.html |
664 | | - styles_dir = Path(__file__).parent.parent / "references" / "examples" / "styles" |
| 630 | + from sdpm.config import resolve_styles_dir |
| 631 | + |
| 632 | + styles_dir = resolve_styles_dir() |
665 | 633 | style_name = args.style if args.style.endswith(".html") else args.style + ".html" |
666 | 634 | style_src = styles_dir / style_name |
667 | 635 | if not style_src.exists(): |
@@ -1076,7 +1044,9 @@ def cmd_analyze_template(args): |
1076 | 1044 | name = args.input |
1077 | 1045 | if not name.endswith(".pptx"): |
1078 | 1046 | name += ".pptx" |
1079 | | - candidate = Path(__file__).resolve().parent.parent / "templates" / name |
| 1047 | + from sdpm.config import resolve_templates_dir |
| 1048 | + |
| 1049 | + candidate = resolve_templates_dir() / name |
1080 | 1050 | if candidate.exists(): |
1081 | 1051 | template_path = candidate |
1082 | 1052 | else: |
|
0 commit comments