|
1 | 1 | """Main entry point for the document generator.""" |
2 | 2 |
|
3 | 3 | import importlib |
| 4 | +import logging |
4 | 5 | import os |
5 | 6 | import sys |
6 | 7 | from pathlib import Path |
|
10 | 11 | from .common import deep_merge |
11 | 12 | from .render import create_env |
12 | 13 |
|
| 14 | +logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") |
| 15 | +logger = logging.getLogger(__name__) |
| 16 | + |
13 | 17 |
|
14 | 18 | def _get_config_path(config_path=None): |
15 | 19 | """Get and validate the configuration file path.""" |
16 | 20 | if config_path is None: |
17 | 21 | if len(sys.argv) < 2: |
18 | | - print("Error: Config file path is required") |
19 | | - print("Usage: python -m pdfbaker <config_file_path>") |
| 22 | + logger.error("Config file path is required") |
| 23 | + logger.error("Usage: python -m pdfbaker <config_file_path>") |
20 | 24 | return None |
21 | 25 | config_path = sys.argv[1] |
22 | 26 |
|
23 | 27 | config_path = Path(config_path).resolve() |
24 | 28 | if not config_path.exists(): |
25 | | - print(f"Error: Configuration file not found: {config_path}") |
| 29 | + logger.error("Configuration file not found: %s", config_path) |
26 | 30 | return None |
27 | 31 |
|
28 | 32 | return config_path |
@@ -64,17 +68,17 @@ def _get_document_paths(base_dir, documents): |
64 | 68 | def _validate_document_path(doc_name, doc_path): |
65 | 69 | """Validate that a document has all required files.""" |
66 | 70 | if not doc_path.is_dir(): |
67 | | - print(f'Warning: Directory missing for document "{doc_name}" ' f"at {doc_path}") |
| 71 | + logger.warning('Directory missing for document "%s" at %s', doc_name, doc_path) |
68 | 72 | return False |
69 | 73 |
|
70 | 74 | bake_path = doc_path / "bake.py" |
71 | 75 | if not bake_path.exists(): |
72 | | - print(f'Warning: bake.py missing for document "{doc_name}"') |
| 76 | + logger.warning('bake.py missing for document "%s"', doc_name) |
73 | 77 | return False |
74 | 78 |
|
75 | 79 | config_yml_path = doc_path / "config.yml" |
76 | 80 | if not config_yml_path.exists(): |
77 | | - print(f'Warning: config.yml missing for document "{doc_name}"') |
| 81 | + logger.warning('config.yml missing for document "%s"', doc_name) |
78 | 82 | return False |
79 | 83 |
|
80 | 84 | return bake_path, config_yml_path |
@@ -110,10 +114,10 @@ def _process_document(doc_name, doc_path, config, build_dir, dist_dir): |
110 | 114 | """Process an individual document.""" |
111 | 115 | validation_result = _validate_document_path(doc_name, doc_path) |
112 | 116 | if not validation_result: |
113 | | - print(f'Warning: Document "{doc_name}" at {doc_path} is invalid - skipping') |
| 117 | + logger.warning('Document "%s" at %s is invalid - skipping', doc_name, doc_path) |
114 | 118 | return |
115 | 119 |
|
116 | | - print(f'Processing document "{doc_name}" from {doc_path}...') |
| 120 | + logger.info('Processing document "%s" from %s...', doc_name, doc_path) |
117 | 121 | bake_path, config_yml_path = validation_result |
118 | 122 | bake_module = _load_document_bake_module(doc_name, bake_path) |
119 | 123 | with open(config_yml_path, encoding="utf-8") as f: |
@@ -152,7 +156,7 @@ def main(config_path=None): |
152 | 156 | for doc_name, doc_path in document_paths.items(): |
153 | 157 | _process_document(doc_name, doc_path, config, build_dir, dist_dir) |
154 | 158 |
|
155 | | - print("Done.") |
| 159 | + logger.info("Done.") |
156 | 160 | return 0 |
157 | 161 |
|
158 | 162 |
|
|
0 commit comments