Coverage for liitos/meta.py: 83.39%
603 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-08 19:41:18 +00:00
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-08 19:41:18 +00:00
1"""Weave the content of the meta file(s) of metadata.tex.in into the output metadata.tex."""
3import datetime as dti
4import os
5import pathlib
6from typing import Union, no_type_check
8import yaml
10import liitos.gather as gat
11import liitos.template as tpl
12import liitos.tools as too
13from liitos import ENCODING, ExternalsType, KNOWN_APPROVALS_STRATEGIES, LOG_SEPARATOR, log
15VALUE_SLOT = 'VALUE.SLOT'
16DOC_BASE = pathlib.Path('..', '..')
17STRUCTURE_PATH = DOC_BASE / 'structure.yml'
18MAGIC_OF_TODAY = 'PUBLICATIONDATE'
20WEAVE_DEFAULTS = {
21 'approvals_adjustable_vertical_space': '2.5em',
22 'approvals_strategy': KNOWN_APPROVALS_STRATEGIES[0],
23 'bold_font': 'ITCFranklinGothicStd-Demi',
24 'bold_italic_font': 'ITCFranklinGothicStd-DemiIt',
25 'bookmatter_path': '',
26 'change_log_tune_header_sep': '-0em',
27 'chosen_logo': '/opt/logo/liitos-logo.png',
28 'chosen_title_page_logo': '/opt/logo/liitos-logo.png',
29 'code_fontsize': r'\scriptsize',
30 'driver_path': '',
31 'fixed_font_package': 'sourcecodepro',
32 'font_path': '/opt/fonts/',
33 'font_suffix': '.otf',
34 'footer_frame_note': os.getenv('LIITOS_FOOTER_FRAME_NOTE', ' '), # TODO
35 'footer_outer_field_normal_pages': r'\theMetaPageNumPrefix { } \thepage { }',
36 'italic_font': 'ITCFranklinGothicStd-BookIt',
37 'lox_indent': r'\hspace*{0.40\textwidth}', # old default was '' for left align
38 'main_font': 'ITCFranklinGothicStd-Book',
39 'metadata_path': '',
40 'proprietary_information': '/opt/legal/proprietary-information.txt',
41 'proprietary_information_adjustable_vertical_space': '-0em',
42 'proprietary_information_tune_header_sep': '-0em',
43 'publisher_path': '',
44 'setup_path': '',
45 'stretch': '1.04', # old default was 1.2
46 'toc_all_dots': '', # old default was not toc all dots, so '%' would restore
47}
48ACROSS = {
49 'eff_font_folder': '',
50 'eff_font_suffix': '',
51}
54@no_type_check
55def process_meta(aspects: dict[str, str]) -> Union[gat.Meta, int]:
56 """TODO."""
57 meta_path = DOC_BASE / aspects[gat.KEY_META]
58 if not meta_path.is_file() or not meta_path.stat().st_size: 58 ↛ 59line 58 didn't jump to line 59 because the condition on line 58 was never true
59 log.error(f'destructure failed to find non-empty meta file at {meta_path}')
60 return 1
61 if meta_path.suffix.lower() not in ('.yaml', '.yml'): 61 ↛ 62line 61 didn't jump to line 62 because the condition on line 61 was never true
62 return 1
63 with open(meta_path, 'rt', encoding=ENCODING) as handle:
64 metadata = yaml.safe_load(handle)
65 if not metadata: 65 ↛ 66line 65 didn't jump to line 66 because the condition on line 65 was never true
66 log.error(f'empty metadata file? Please add metadata to ({meta_path})')
67 return 1
68 if 'import' in metadata['document']: 68 ↛ 81line 68 didn't jump to line 81 because the condition on line 68 was always true
69 base_meta_path = DOC_BASE / metadata['document']['import']
70 if not base_meta_path.is_file() or not base_meta_path.stat().st_size: 70 ↛ 71line 70 didn't jump to line 71 because the condition on line 70 was never true
71 log.error(
72 f'metadata declares import of base data from ({base_meta_path.name})'
73 f' but failed to find non-empty base file at {base_meta_path}'
74 )
75 return 1
76 with open(base_meta_path, 'rt', encoding=ENCODING) as handle:
77 base_data = yaml.safe_load(handle)
78 for key, value in metadata['document']['patch'].items():
79 base_data['document']['common'][key] = value
80 metadata = base_data
81 with open('metadata.yml', 'wt', encoding=ENCODING) as handle:
82 yaml.dump(metadata, handle, default_flow_style=False)
83 return metadata
86@no_type_check
87def weave_setup_font_path(
88 mapper: dict[str, Union[str, int, bool, None]],
89 text: str,
90) -> str:
91 """Weave in the xxxx from mapper or default for driver.
93 Trigger is text.rstrip().endswith('%%_PATCH_%_FONT_%_PATH_%%')
94 """
95 defaults = {**WEAVE_DEFAULTS}
96 if mapper.get('font_path'):
97 font_path = mapper.get('font_path')
98 if not pathlib.Path(font_path).is_dir(): 98 ↛ 99line 98 didn't jump to line 99 because the condition on line 98 was never true
99 log.warning(f'font_path ({font_path}) is no directory on this system - rendering may not work as intended')
100 ACROSS['eff_font_folder'] = font_path
101 return text.replace(VALUE_SLOT, font_path)
102 else:
103 log.warning(f'font_path value missing ... setting default ({defaults["font_path"]})')
104 ACROSS['eff_font_folder'] = defaults['font_path']
105 return text.replace(VALUE_SLOT, defaults['font_path'])
108@no_type_check
109def weave_setup_font_suffix(
110 mapper: dict[str, Union[str, int, bool, None]],
111 text: str,
112) -> str:
113 """Weave in the font_suffix from mapper or default for driver.
115 Trigger is text.rstrip().endswith('%%_PATCH_%_FONT_%_SUFFIX_%%')
116 """
117 defaults = {**WEAVE_DEFAULTS}
118 if mapper.get('font_suffix'):
119 font_suffix = mapper.get('font_suffix')
120 if font_suffix not in ('.otf', '.ttf'): 120 ↛ 121line 120 didn't jump to line 121 because the condition on line 120 was never true
121 log.warning(f'font_suffix ({font_suffix}) is unexpected - rendering may not work as intended')
122 ACROSS['eff_font_suffix'] = font_suffix
123 return text.replace(VALUE_SLOT, font_suffix)
124 else:
125 log.warning(f'font_suffix value missing ... setting default ({defaults["font_suffix"]})')
126 ACROSS['eff_font_suffix'] = defaults['font_suffix']
127 return text.replace(VALUE_SLOT, defaults['font_suffix'])
130@no_type_check
131def weave_setup_bold_font(
132 mapper: dict[str, Union[str, int, bool, None]],
133 text: str,
134) -> str:
135 """Weave in the bold_font from mapper or default for driver.
137 Trigger is text.rstrip().endswith('%%_PATCH_%_BOLD_%_FONT_%%')
138 """
139 defaults = {**WEAVE_DEFAULTS}
140 eff_font_folder = ACROSS['eff_font_folder']
141 eff_font_suffix = ACROSS['eff_font_suffix']
142 if mapper.get('bold_font'):
143 bold_font = mapper.get('bold_font')
144 font_path = pathlib.Path(eff_font_folder) / f'{bold_font}{eff_font_suffix}'
145 if not font_path.is_file(): 145 ↛ 146line 145 didn't jump to line 146 because the condition on line 145 was never true
146 log.warning(
147 f'bold_font ({bold_font}) is not found'
148 f' as ({font_path}) on this system - rendering may not work as intended'
149 )
150 return text.replace(VALUE_SLOT, bold_font)
151 else:
152 log.warning(f'bold_font value missing ... setting default ({defaults["bold_font"]})')
153 return text.replace(VALUE_SLOT, defaults['bold_font'])
156@no_type_check
157def weave_setup_italic_font(
158 mapper: dict[str, Union[str, int, bool, None]],
159 text: str,
160) -> str:
161 """Weave in the italic_font from mapper or default for driver.
163 Trigger is text.rstrip().endswith('%%_PATCH_%_ITALIC_%_FONT_%%')
164 """
165 defaults = {**WEAVE_DEFAULTS}
166 eff_font_folder = ACROSS['eff_font_folder']
167 eff_font_suffix = ACROSS['eff_font_suffix']
168 if mapper.get('italic_font'):
169 italic_font = mapper.get('italic_font')
170 font_path = pathlib.Path(eff_font_folder) / f'{italic_font}{eff_font_suffix}'
171 if not font_path.is_file(): 171 ↛ 172line 171 didn't jump to line 172 because the condition on line 171 was never true
172 log.warning(
173 f'italic_font ({italic_font}) is not found'
174 f' as ({font_path}) on this system - rendering may not work as intended'
175 )
176 return text.replace(VALUE_SLOT, italic_font)
177 else:
178 log.warning(f'italic_font value missing ... setting default ({defaults["italic_font"]})')
179 return text.replace(VALUE_SLOT, defaults['italic_font'])
182@no_type_check
183def weave_setup_bold_italic_font(
184 mapper: dict[str, Union[str, int, bool, None]],
185 text: str,
186) -> str:
187 """Weave in the bold_italic_font from mapper or default for driver.
189 Trigger is text.rstrip().endswith('%%_PATCH_%_BOLDITALIC_%_FONT_%%')
190 """
191 defaults = {**WEAVE_DEFAULTS}
192 eff_font_folder = ACROSS['eff_font_folder']
193 eff_font_suffix = ACROSS['eff_font_suffix']
194 if mapper.get('bold_italic_font'):
195 bold_italic_font = mapper.get('bold_italic_font')
196 font_path = pathlib.Path(eff_font_folder) / f'{bold_italic_font}{eff_font_suffix}'
197 if not font_path.is_file(): 197 ↛ 198line 197 didn't jump to line 198 because the condition on line 197 was never true
198 log.warning(
199 f'bold_italic_font ({bold_italic_font}) is not found'
200 f' as ({font_path}) on this system - rendering may not work as intended'
201 )
202 return text.replace(VALUE_SLOT, bold_italic_font)
203 else:
204 log.warning(f'bold_italic_font value missing ... setting default ({defaults["bold_italic_font"]})')
205 return text.replace(VALUE_SLOT, defaults['bold_italic_font'])
208@no_type_check
209def weave_setup_main_font(
210 mapper: dict[str, Union[str, int, bool, None]],
211 text: str,
212) -> str:
213 """Weave in the main_font from mapper or default for driver.
215 Trigger is text.rstrip().endswith('%%_PATCH_%_MAIN_%_FONT_%%')
216 """
217 defaults = {**WEAVE_DEFAULTS}
218 eff_font_folder = ACROSS['eff_font_folder']
219 eff_font_suffix = ACROSS['eff_font_suffix']
220 if mapper.get('main_font'):
221 main_font = mapper.get('main_font')
222 font_path = pathlib.Path(eff_font_folder) / f'{main_font}{eff_font_suffix}'
223 if not font_path.is_file(): 223 ↛ 224line 223 didn't jump to line 224 because the condition on line 223 was never true
224 log.warning(
225 f'main_font ({main_font}) is not found'
226 f' as ({font_path}) on this system - rendering may not work as intended'
227 )
228 return text.replace(VALUE_SLOT, main_font)
229 else:
230 log.warning(f'main_font value missing ... setting default ({defaults["main_font"]})')
231 return text.replace(VALUE_SLOT, defaults['main_font'])
234@no_type_check
235def weave_setup_fixed_font_package(
236 mapper: dict[str, Union[str, int, bool, None]],
237 text: str,
238) -> str:
239 """Weave in the fixed_font_package from mapper or default for driver.
241 Trigger is text.rstrip().endswith('%%_PATCH_%_FIXED_%_FONT_%_PACKAGE_%%')
242 """
243 defaults = {**WEAVE_DEFAULTS}
244 if mapper.get('fixed_font_package'):
245 fixed_font_package = mapper.get('fixed_font_package')
246 if fixed_font_package != defaults['fixed_font_package']: 246 ↛ 247line 246 didn't jump to line 247 because the condition on line 246 was never true
247 log.warning(
248 f'fixed_font_package ({fixed_font_package}) has not'
249 ' been tested on this system - rendering may not work as intended'
250 )
251 return text.replace(VALUE_SLOT, fixed_font_package)
252 else:
253 log.warning(f'fixed_font_package value missing ... setting default ({defaults["fixed_font_package"]})')
254 return text.replace(VALUE_SLOT, defaults['fixed_font_package'])
257@no_type_check
258def weave_setup_code_fontsize(
259 mapper: dict[str, Union[str, int, bool, None]],
260 text: str,
261) -> str:
262 """Weave in the code_fontsize from mapper or default for driver.
264 Trigger is text.rstrip().endswith('%%_PATCH_%_CODE_%_FONTSIZE_%%')
265 """
266 defaults = {**WEAVE_DEFAULTS}
267 if mapper.get('code_fontsize'):
268 code_fontsize = mapper.get('code_fontsize')
269 valid_code_font_sizes = (
270 r'\Huge',
271 r'\huge',
272 r'\LARGE',
273 r'\Large',
274 r'\large',
275 r'\normalsize',
276 r'\small',
277 r'\footnotesize',
278 r'\scriptsize',
279 r'\tiny',
280 )
281 bs = '\\'
282 sizes = tuple(size[1:] for size in valid_code_font_sizes)
283 if code_fontsize.startswith(r'\\'): 283 ↛ 284line 283 didn't jump to line 284 because the condition on line 283 was never true
284 code_fontsize = code_fontsize[1:]
285 if code_fontsize not in valid_code_font_sizes: 285 ↛ 286line 285 didn't jump to line 286 because the condition on line 285 was never true
286 log.error(
287 f'code_fontsize ({code_fontsize}) is not a valid font size value'
288 ' - rendering would not work as intended'
289 )
290 log.info(f'valid values for code_fontsize must be in {bs}{(", " + bs).join(sizes)}')
291 log.warning(
292 f'overriding code font size value with the (working) default of ({defaults["code_fontsize"]})'
293 f' - in config that would be {defaults["code_fontsize"]}'
294 )
295 return text.replace(VALUE_SLOT, defaults['code_fontsize'])
296 else:
297 return text.replace(VALUE_SLOT, code_fontsize)
298 else:
299 log.info(
300 f'code_fontsize value missing ... setting default ({defaults["code_fontsize"]})'
301 f' - in config that would be {defaults["code_fontsize"]}'
302 )
303 return text.replace(VALUE_SLOT, defaults['code_fontsize'])
306@no_type_check
307def weave_setup_chosen_logo(
308 mapper: dict[str, Union[str, int, bool, None]],
309 text: str,
310) -> str:
311 """Weave in the chosen_logo from mapper or default for driver.
313 Trigger is text.rstrip().endswith('%%_PATCH_%_CHOSEN_%_LOGO_%%')
314 """
315 defaults = {**WEAVE_DEFAULTS}
316 if mapper.get('chosen_logo'):
317 chosen_logo = mapper.get('chosen_logo')
318 logo_path = pathlib.Path(chosen_logo)
319 if not logo_path.is_file(): 319 ↛ 320line 319 didn't jump to line 320 because the condition on line 319 was never true
320 log.warning(
321 f'chosen_logo ({chosen_logo}) is not found'
322 f' as ({logo_path}) on this system - rendering may not work as intended'
323 )
324 return text.replace(VALUE_SLOT, chosen_logo)
325 else:
326 log.info(f'chosen_logo value missing ... setting default ({defaults["chosen_logo"]})')
327 return text.replace(VALUE_SLOT, defaults['chosen_logo'])
330@no_type_check
331def weave_setup_chosen_title_page_logo(
332 mapper: dict[str, Union[str, int, bool, None]],
333 text: str,
334) -> str:
335 """Weave in the chosen_logo from mapper or default for driver.
337 Trigger is text.rstrip().endswith('%%_PATCH_%_CHOSEN_%_TITLE_%_PAGE_%_LOGO_%%')
338 """
339 defaults = {**WEAVE_DEFAULTS}
340 log.warning(text)
341 if mapper.get('chosen_title_page_logo'):
342 chosen_title_page_logo = mapper.get('chosen_title_page_logo')
343 title_page_logo_path = pathlib.Path(chosen_title_page_logo)
344 log.warning(f'found {chosen_title_page_logo}')
345 if not title_page_logo_path.is_file(): 345 ↛ 346line 345 didn't jump to line 346 because the condition on line 345 was never true
346 log.warning(
347 f'chosen_title_page_logo ({chosen_title_page_logo}) is not found'
348 f' as ({title_page_logo_path}) on this system - rendering may not work as intended'
349 )
350 return text.replace(VALUE_SLOT, chosen_title_page_logo)
351 else:
352 log.warning('default logo')
353 log.info(f'chosen_title_page_logo value missing ... setting default ({defaults["chosen_title_page_logo"]})')
354 return text.replace(VALUE_SLOT, defaults['chosen_title_page_logo'])
357@no_type_check
358def weave_setup_footer_outer_field_normal_pages(
359 mapper: dict[str, Union[str, int, bool, None]],
360 text: str,
361) -> str:
362 """Weave in the footer_outer_field_normal_pages from mapper or default for driver.
364 Trigger is text.rstrip().endswith('%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%')
365 """
366 defaults = {**WEAVE_DEFAULTS}
367 if mapper.get('footer_outer_field_normal_pages'): 367 ↛ 371line 367 didn't jump to line 371 because the condition on line 367 was always true
368 footer_outer_field_normal_pages = mapper.get('footer_outer_field_normal_pages')
369 return text.replace(VALUE_SLOT, footer_outer_field_normal_pages)
370 else:
371 log.info(
372 'footer_outer_field_normal_pages value missing ...'
373 f' setting default ({defaults["footer_outer_field_normal_pages"]})'
374 )
375 return text.replace(VALUE_SLOT, defaults['footer_outer_field_normal_pages'])
378@no_type_check
379def weave_setup_toc_all_dots(
380 mapper: dict[str, Union[str, int, bool, None]],
381 text: str,
382) -> str:
383 """Weave in the toc_all_dots from mapper or default for driver.
385 Trigger is text.rstrip().endswith('%%_PATCH_%_TOC_ALL_DOTS_%%')
386 """
387 defaults = {**WEAVE_DEFAULTS}
388 if mapper.get('toc_all_dots'): 388 ↛ 389line 388 didn't jump to line 389 because the condition on line 388 was never true
389 toc_all_dots = mapper.get('toc_all_dots')
390 return text.replace(VALUE_SLOT, toc_all_dots)
391 else:
392 log.info('toc_all_dots value missing ...' f' setting default ({defaults["toc_all_dots"]})')
393 return text.replace(VALUE_SLOT, defaults['toc_all_dots'])
396@no_type_check
397def dispatch_setup_weaver(
398 mapper: dict[str, Union[str, int, bool, None]],
399 text: str,
400) -> str:
401 """Dispatch the driver weaver by mapping to handled groups per source marker."""
402 dispatch = {
403 '%%_PATCH_%_FONT_%_PATH_%%': weave_setup_font_path,
404 '%%_PATCH_%_FONT_%_SUFFIX_%%': weave_setup_font_suffix,
405 '%%_PATCH_%_BOLD_%_FONT_%%': weave_setup_bold_font,
406 '%%_PATCH_%_ITALIC_%_FONT_%%': weave_setup_italic_font,
407 '%%_PATCH_%_BOLDITALIC_%_FONT_%%': weave_setup_bold_italic_font,
408 '%%_PATCH_%_MAIN_%_FONT_%%': weave_setup_main_font,
409 '%%_PATCH_%_FIXED_%_FONT_%_PACKAGE_%%': weave_setup_fixed_font_package,
410 '%%_PATCH_%_CODE_%_FONTSIZE_%%': weave_setup_code_fontsize,
411 '%%_PATCH_%_CHOSEN_%_LOGO_%%': weave_setup_chosen_logo,
412 '%%_PATCH_%_CHOSEN_%_TITLE_%_PAGE_%_LOGO_%%': weave_setup_chosen_title_page_logo,
413 '%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%': weave_setup_footer_outer_field_normal_pages,
414 '%%_PATCH_%_TOC_ALL_DOTS_%%': weave_setup_toc_all_dots,
415 }
416 for trigger, weaver in dispatch.items():
417 if text.rstrip().endswith(trigger):
418 return weaver(mapper, text)
419 return text
422@no_type_check
423def weave_meta_setup(meta_map: gat.Meta, latex: list[str]) -> list[str]:
424 """TODO."""
425 log.info('weaving in the meta data per setup.tex.in into setup.tex ...')
426 completed = [dispatch_setup_weaver(meta_map['document']['common'], line) for line in latex]
427 if completed and completed[-1]:
428 completed.append('\n')
429 return completed
432@no_type_check
433def weave_driver_toc_level(
434 mapper: dict[str, Union[str, int, bool, None]],
435 text: str,
436) -> str:
437 """Weave in the toc_level from mapper or default for driver.
439 Trigger is text.rstrip().endswith('%%_PATCH_%_TOC_%_LEVEL_%%')
440 """
441 toc_level = 2
442 if mapper.get('toc_level'):
443 try:
444 toc_level_read = int(mapper['toc_level'])
445 toc_level = toc_level_read if 0 < toc_level_read < 5 else 2
446 if toc_level != toc_level_read:
447 log.warning(
448 f'ignored toc level ({toc_level_read}) set to default (2) - expected value 0 < toc_level < 5'
449 )
450 except ValueError as err:
451 toc_level = 2
452 log.warning(f'toc_level ({mapper["toc_level"]}) not in (1, 2, 3, 4) - resorting to default ({toc_level})')
453 log.error(f'error detail: {err}')
454 else:
455 log.info(f'toc_level value missing ... setting default ({toc_level})')
456 return text.replace(VALUE_SLOT, str(toc_level))
459@no_type_check
460def weave_driver_list_of_figures(
461 mapper: dict[str, Union[str, int, bool, None]],
462 text: str,
463) -> str:
464 """Weave in the list_of_figures from mapper or default for driver.
466 Trigger is text.rstrip().endswith('%%_PATCH_%_LOF_%%')
467 """
468 if mapper.get('list_of_figures', None) is not None:
469 lof = mapper['list_of_figures']
470 if lof in ('', '%'):
471 return text.replace(VALUE_SLOT, str(lof))
472 else:
473 lof = '%'
474 log.warning(
475 f"list_of_figures ({mapper['list_of_figures']}) not in ('', '%')"
476 f' - resorting to default ({lof}) i.e. commenting out the list of figures'
477 )
478 else:
479 log.info('list_of_figures value missing ... setting default (comment out the lof per %)')
481 return text.replace(VALUE_SLOT, '%')
484@no_type_check
485def weave_driver_list_of_tables(
486 mapper: dict[str, Union[str, int, bool, None]],
487 text: str,
488) -> str:
489 """Weave in the list_of_tables from mapper or default for driver.
491 Trigger is text.rstrip().endswith('%%_PATCH_%_LOT_%%')
492 """
493 if mapper.get('list_of_tables', None) is not None:
494 lof = mapper['list_of_tables']
495 if lof in ('', '%'):
496 return text.replace(VALUE_SLOT, str(lof))
497 else:
498 lof = '%'
499 log.warning(
500 f"list_of_tables ({mapper['list_of_tables']}) not in ('', '%')"
501 f' - resorting to default ({lof}) i.e. commenting out the list of tables'
502 )
503 else:
504 log.info('list_of_tables value missing ... setting default (comment out the lot per %)')
506 return text.replace(VALUE_SLOT, '%')
509@no_type_check
510def dispatch_driver_weaver(
511 mapper: dict[str, Union[str, int, bool, None]],
512 text: str,
513) -> str:
514 """Dispatch the driver weaver by mapping to handled groups per source marker."""
515 dispatch = {
516 '%%_PATCH_%_TOC_%_LEVEL_%%': weave_driver_toc_level,
517 '%%_PATCH_%_LOF_%%': weave_driver_list_of_figures,
518 '%%_PATCH_%_LOT_%%': weave_driver_list_of_tables,
519 }
520 for trigger, weaver in dispatch.items():
521 if text.rstrip().endswith(trigger):
522 return weaver(mapper, text)
523 return text
526@no_type_check
527def weave_meta_driver(meta_map: gat.Meta, latex: list[str]) -> list[str]:
528 """TODO."""
529 log.info('weaving in the meta data per driver.tex.in into driver.tex ...')
530 completed = [dispatch_driver_weaver(meta_map['document']['common'], line) for line in latex]
531 if completed and completed[-1]:
532 completed.append('\n')
533 return completed
536@no_type_check
537def weave_meta_part_header_title(
538 mapper: dict[str, Union[str, int, bool, None]],
539 text: str,
540) -> str:
541 """Weave in the header_title from mapper or default.
543 Trigger is text.rstrip().endswith('%%_PATCH_%_HEADER_%_TITLE_%%')
544 """
545 if mapper.get('header_title'):
546 return text.replace(VALUE_SLOT, mapper['header_title'])
547 else:
548 log.info('header_title value missing ... setting default (the title value)')
549 return text.replace(VALUE_SLOT, mapper['title'])
552@no_type_check
553def weave_meta_part_title_slug(
554 mapper: dict[str, Union[str, int, bool, None]],
555 text: str,
556) -> str:
557 """Weave in the title slug deriving from mapper or default.
559 Trigger is text.rstrip().endswith('%%_PATCH_%_MAIN_%_TITLE_%_SLUG_%%')
560 """
561 if mapper.get('bookmark_title'): 561 ↛ 562line 561 didn't jump to line 562 because the condition on line 561 was never true
562 return text.replace(VALUE_SLOT, mapper['bookmark_title'])
563 else:
564 log.info('bookmark_title value missing ... setting default (the slugged title value)')
565 return text.replace(VALUE_SLOT, mapper['title'].replace('\\\\', '').replace(' ', ' ').title())
568@no_type_check
569def weave_meta_part_title(
570 mapper: dict[str, Union[str, int, bool, None]],
571 text: str,
572) -> str:
573 """Weave in the title from mapper or default.
575 Trigger is text.rstrip().endswith('%%_PATCH_%_MAIN_%_TITLE_%%')
576 """
577 return text.replace(VALUE_SLOT, mapper['title'])
580@no_type_check
581def weave_meta_part_sub_title(
582 mapper: dict[str, Union[str, int, bool, None]],
583 text: str,
584) -> str:
585 """Weave in the sub_title from mapper or default.
587 Trigger is text.rstrip().endswith('%%_PATCH_%_SUB_%_TITLE_%%')
588 """
589 if mapper.get('sub_title'):
590 return text.replace(VALUE_SLOT, mapper['sub_title'])
591 else:
592 log.info('sub_title value missing ... setting default (single space)')
593 return text.replace(VALUE_SLOT, ' ')
596@no_type_check
597def weave_meta_part_header_type(
598 mapper: dict[str, Union[str, int, bool, None]],
599 text: str,
600) -> str:
601 """Weave in the header_type from mapper or default.
603 Trigger is text.rstrip().endswith('%%_PATCH_%_TYPE_%%')
604 """
605 if mapper.get('header_type'):
606 return text.replace(VALUE_SLOT, mapper['header_type'])
607 else:
608 log.info('header_type value missing ... setting default (Engineering Document)')
609 return text.replace(VALUE_SLOT, 'Engineering Document')
612@no_type_check
613def weave_meta_part_header_id_label(
614 mapper: dict[str, Union[str, int, bool, None]],
615 text: str,
616) -> str:
617 """Weave in the header_id_label from mapper or default.
619 Trigger is text.rstrip().endswith('%%_PATCH_%_ID_%_LABEL_%%')
620 """
621 if mapper.get('header_id_show', None) is not None and not mapper['header_id_show']: 621 ↛ 622line 621 didn't jump to line 622 because the condition on line 621 was never true
622 log.info('header_id_show set to false - hiding id slot in header by setting label to a single space(" ")')
623 return text.replace(VALUE_SLOT, ' ')
624 log.info('header_id_show not set - considering header_id_label ...')
625 if mapper.get('header_id_label'): 625 ↛ 626line 625 didn't jump to line 626 because the condition on line 625 was never true
626 pub_id_label = mapper['header_id_label'].strip()
627 if not pub_id_label:
628 pub_id_label = ' ' # single space to please the backend parser
629 return text.replace(VALUE_SLOT, pub_id_label)
630 else:
631 log.info('header_id_label value missing ... setting default(Doc. ID:)')
632 return text.replace(VALUE_SLOT, 'Doc. ID:')
635@no_type_check
636def weave_meta_part_header_id(
637 mapper: dict[str, Union[str, int, bool, None]],
638 text: str,
639) -> str:
640 """Weave in the header_id from mapper or default.
642 Trigger is text.rstrip().endswith('%%_PATCH_%_ID_%%')
643 """
644 if mapper.get('header_id_show', None) is not None and not mapper['header_id_show']: 644 ↛ 645line 644 didn't jump to line 645 because the condition on line 644 was never true
645 log.info('header_id_show set to false - hiding id slot in header by setting value to a single space(" ")')
646 return text.replace(VALUE_SLOT, ' ')
647 log.info('header_id_show not set - considering header_id ...')
648 if mapper.get('header_id'):
649 return text.replace(VALUE_SLOT, mapper['header_id'])
650 else:
651 log.info('header_id value missing ... setting default (N/A)')
652 return text.replace(VALUE_SLOT, 'N/A')
655@no_type_check
656def weave_meta_part_issue(
657 mapper: dict[str, Union[str, int, bool, None]],
658 text: str,
659) -> str:
660 """Weave in the issue from mapper or default.
662 Trigger is text.rstrip().endswith('%%_PATCH_%_ISSUE_%%')
663 """
664 if mapper.get('issue'):
665 return text.replace(VALUE_SLOT, mapper['issue'])
666 else:
667 log.info('issue value missing ... setting default (01)')
668 return text.replace(VALUE_SLOT, '01')
671@no_type_check
672def weave_meta_part_revision(
673 mapper: dict[str, Union[str, int, bool, None]],
674 text: str,
675) -> str:
676 """Weave in the revision from mapper or default.
678 Trigger is text.rstrip().endswith('%%_PATCH_%_REVISION_%%')
679 """
680 if mapper.get('revision'):
681 return text.replace(VALUE_SLOT, mapper['revision'])
682 else:
683 log.info('revision value missing ... setting default (00)')
684 return text.replace(VALUE_SLOT, '00')
687@no_type_check
688def weave_meta_part_header_date_label(
689 mapper: dict[str, Union[str, int, bool, None]],
690 text: str,
691) -> str:
692 """Weave in the header_date_label from mapper or default.
694 Trigger is text.rstrip().endswith('%%_PATCH_%_DATE_%_LABEL_%%')
695 """
696 if mapper.get('header_date_show', None) is not None and not mapper['header_date_show']: 696 ↛ 697line 696 didn't jump to line 697 because the condition on line 696 was never true
697 log.info('header_date_show set to false - hiding date slot in header by setting label to a single space(" ")')
698 return text.replace(VALUE_SLOT, ' ')
699 log.info('header_date_show not set - considering header_date_label ...')
700 if mapper.get('header_date_label'): 700 ↛ 701line 700 didn't jump to line 701 because the condition on line 700 was never true
701 pub_date_label = mapper['header_date_label'].strip()
702 if not pub_date_label:
703 pub_date_label = ' ' # single space to please the backend parser
704 return text.replace(VALUE_SLOT, pub_date_label)
705 else:
706 log.info('header_date_label value missing ... setting default(" ")')
707 return text.replace(VALUE_SLOT, ' ')
710@no_type_check
711def weave_meta_part_header_date(
712 mapper: dict[str, Union[str, int, bool, None]],
713 text: str,
714) -> str:
715 """Weave in the header_date from mapper or default.
717 Trigger is text.rstrip().endswith('%%_PATCH_%_DATE_%%')
718 """
719 if mapper.get('header_date_show', None) is not None and not mapper['header_date_show']: 719 ↛ 720line 719 didn't jump to line 720 because the condition on line 719 was never true
720 log.info('header_date_show set to false - hiding date slot in header by setting value to a single space(" ")')
721 return text.replace(VALUE_SLOT, ' ')
722 log.info('header_date_show not set - considering header_date ...')
723 if mapper.get('header_date_enable_auto', None) is not None and not mapper['header_date_enable_auto']: 723 ↛ 724line 723 didn't jump to line 724 because the condition on line 723 was never true
724 log.info('header_date_enable_auto set to false - setting that slot value as is (no date semantics enforced)')
725 if mapper.get('header_date'):
726 pub_date_or_any = mapper['header_date'].strip()
727 if not pub_date_or_any:
728 pub_date_or_any = ' ' # single space to please the backend parser
729 return text.replace(VALUE_SLOT, pub_date_or_any)
730 else:
731 log.info('header_date value missing and as-is mode ... setting to single space ( ) a.k.a. hiding')
732 return text.replace(VALUE_SLOT, ' ')
733 else:
734 today = dti.datetime.today()
735 pub_date_today = today.strftime('%d %b %Y').upper()
736 if mapper.get('header_date'):
737 pub_date = mapper['header_date'].strip()
738 if pub_date == MAGIC_OF_TODAY:
739 pub_date = pub_date_today
740 return text.replace(VALUE_SLOT, pub_date)
741 else:
742 log.info('header_date value missing ... setting default as empty(" ")')
743 return text.replace(VALUE_SLOT, ' ')
746@no_type_check
747def weave_meta_part_footer_frame_note(
748 mapper: dict[str, Union[str, int, bool, None]],
749 text: str,
750) -> str:
751 """Weave in the footer_frame_note from mapper or default.
753 Trigger is text.rstrip().endswith('%%_PATCH_%_FRAME_%_NOTE_%%')
754 """
755 if mapper.get('footer_frame_note'):
756 return text.replace(VALUE_SLOT, mapper['footer_frame_note'])
757 else:
758 log.info('footer_frame_note value missing ... setting default from module / environment ...')
759 return text.replace(VALUE_SLOT, WEAVE_DEFAULTS['footer_frame_note'])
762@no_type_check
763def weave_meta_part_footer_page_number_prefix(
764 mapper: dict[str, Union[str, int, bool, None]],
765 text: str,
766) -> str:
767 """Weave in the footer_page_number_prefix from mapper or default.
769 Trigger is text.rstrip().endswith('%%_PATCH_%_FOOT_%_PAGE_%_COUNTER_%_LABEL_%%')
770 """
771 if mapper.get('footer_page_number_prefix'):
772 return text.replace(VALUE_SLOT, mapper['footer_page_number_prefix'])
773 else:
774 log.info('footer_page_number_prefix value missing ... setting default (Page)')
775 return text.replace(VALUE_SLOT, 'Page')
778@no_type_check
779def weave_meta_part_change_log_issue_label(
780 mapper: dict[str, Union[str, int, bool, None]],
781 text: str,
782) -> str:
783 """Weave in the change_log_issue_label from mapper or default.
785 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_ISSUE_%_LABEL_%%')
786 """
787 if mapper.get('change_log_issue_label'):
788 return text.replace(VALUE_SLOT, mapper['change_log_issue_label'])
789 else:
790 log.info('change_log_issue_label value missing ... setting default (Iss.)')
791 return text.replace(VALUE_SLOT, 'Iss.')
794@no_type_check
795def weave_meta_part_change_log_revision_label(
796 mapper: dict[str, Union[str, int, bool, None]],
797 text: str,
798) -> str:
799 """Weave in the change_log_revision_label from mapper or default.
801 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_REVISION_%_LABEL_%%')
802 """
803 if mapper.get('change_log_revision_label'):
804 return text.replace(VALUE_SLOT, mapper['change_log_revision_label'])
805 else:
806 log.info('change_log_revision_label value missing ... setting default (Rev.)')
807 return text.replace(VALUE_SLOT, 'Rev.')
810@no_type_check
811def weave_meta_part_change_log_date_label(
812 mapper: dict[str, Union[str, int, bool, None]],
813 text: str,
814) -> str:
815 """Weave in the change_log_date_label from mapper or default.
817 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_DATE_%_LABEL_%%')
818 """
819 if mapper.get('change_log_date_label'):
820 return text.replace(VALUE_SLOT, mapper['change_log_date_label'])
821 else:
822 log.info('change_log_date_label value missing ... setting default (Date)')
823 return text.replace(VALUE_SLOT, 'Date')
826@no_type_check
827def weave_meta_part_change_log_author_label(
828 mapper: dict[str, Union[str, int, bool, None]],
829 text: str,
830) -> str:
831 """Weave in the change_log_author_label from mapper or default.
833 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_AUTHOR_%_LABEL_%%')
834 """
835 if mapper.get('change_log_author_label'):
836 return text.replace(VALUE_SLOT, mapper['change_log_author_label'])
837 else:
838 log.info('change_log_author_label value missing ... setting default (Author)')
839 return text.replace(VALUE_SLOT, 'Author')
842@no_type_check
843def weave_meta_part_change_log_description_label(
844 mapper: dict[str, Union[str, int, bool, None]],
845 text: str,
846) -> str:
847 """Weave in the change_log_description_label from mapper or default.
849 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_DESCRIPTION_%_LABEL_%%')
850 """
851 if mapper.get('change_log_description_label'):
852 return text.replace(VALUE_SLOT, mapper['change_log_description_label'])
853 else:
854 log.info('change_log_description_label value missing ... setting default (Description)')
855 return text.replace(VALUE_SLOT, 'Description')
858@no_type_check
859def weave_meta_part_with_default_slot(
860 mapper: dict[str, Union[str, int, bool, None]],
861 text: str,
862 slot: str,
863) -> str:
864 """Do the conditional weaving of slot if text matches else used default (and log a warning)."""
865 if mapper.get(slot):
866 return text.replace(VALUE_SLOT, mapper[slot])
867 else:
868 log.info(f'{slot} value missing ... setting default ({WEAVE_DEFAULTS[slot]})')
869 return text.replace(VALUE_SLOT, WEAVE_DEFAULTS[slot])
872@no_type_check
873def weave_meta_part_approvals_adjustable_vertical_space(
874 mapper: dict[str, Union[str, int, bool, None]],
875 text: str,
876) -> str:
877 """Weave in the approvals_adjustable_vertical_space from mapper or default.
879 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%')
880 """
881 return weave_meta_part_with_default_slot(mapper, text, 'approvals_adjustable_vertical_space')
884@no_type_check
885def weave_meta_part_proprietary_information_adjustable_vertical_space(
886 mapper: dict[str, Union[str, int, bool, None]],
887 text: str,
888) -> str:
889 """Weave in the proprietary_information_adjustable_vertical_space from mapper or default.
891 Trigger is text.rstrip().endswith('%%_PATCH_%_BLURB_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%')
892 """
893 return weave_meta_part_with_default_slot(mapper, text, 'proprietary_information_adjustable_vertical_space')
896@no_type_check
897def weave_meta_part_proprietary_information_tune_header_sep(
898 mapper: dict[str, Union[str, int, bool, None]],
899 text: str,
900) -> str:
901 """Weave in the proprietary_information_tune_header_sep from mapper or default.
903 Trigger is text.rstrip().endswith('%%_PATCH_%_BLURB_%_TUNE_%_HEADER_%_SEP_%%')
904 """
905 return weave_meta_part_with_default_slot(mapper, text, 'proprietary_information_tune_header_sep')
908@no_type_check
909def weave_meta_part_change_log_tune_header_sep(
910 mapper: dict[str, Union[str, int, bool, None]],
911 text: str,
912) -> str:
913 """Weave in the change_log_tune_header_sep from mapper or default.
915 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGE_%_LOG_%_TUNE_%_HEADER_%_SEP_%%')
916 """
917 return weave_meta_part_with_default_slot(mapper, text, 'change_log_tune_header_sep')
920@no_type_check
921def weave_meta_part_approvals_department_label(
922 mapper: dict[str, Union[str, int, bool, None]],
923 text: str,
924) -> str:
925 """Weave in the approvals_department_label from mapper or default.
927 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_LABEL_%%')
928 """
929 if mapper.get('approvals_department_label'):
930 return text.replace(VALUE_SLOT, mapper['approvals_department_label'])
931 else:
932 log.info('approvals_department_label value missing ... setting default (Department)')
933 return text.replace(VALUE_SLOT, 'Department')
936@no_type_check
937def weave_meta_part_approvals_department_value(
938 mapper: dict[str, Union[str, int, bool, None]],
939 text: str,
940) -> str:
941 """Weave in the approvals_department_value from mapper or default.
943 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%')
944 """
945 if mapper.get('approvals_department_value'): 945 ↛ 948line 945 didn't jump to line 948 because the condition on line 945 was always true
946 return text.replace(VALUE_SLOT, mapper['approvals_department_value'])
947 else:
948 log.info('approvals_department_value value missing ... setting default ( )')
949 return text.replace(VALUE_SLOT, ' ')
952@no_type_check
953def weave_meta_part_approvals_role_label(
954 mapper: dict[str, Union[str, int, bool, None]],
955 text: str,
956) -> str:
957 """Weave in the approvals_role_label from mapper or default.
959 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_ROLE_%_LABEL_%%')
960 """
961 if mapper.get('approvals_role_label'):
962 return text.replace(VALUE_SLOT, mapper['approvals_role_label'])
963 else:
964 log.info('approvals_role_label value missing ... setting default (Approvals)')
965 return text.replace(VALUE_SLOT, 'Approvals')
968@no_type_check
969def weave_meta_part_approvals_name_label(
970 mapper: dict[str, Union[str, int, bool, None]],
971 text: str,
972) -> str:
973 """Weave in the approvals_name_label from mapper or default.
975 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_NAME_%_LABEL_%%')
976 """
977 if mapper.get('approvals_name_label'):
978 return text.replace(VALUE_SLOT, mapper['approvals_name_label'])
979 else:
980 log.info('approvals_name_label value missing ... setting default (Name)')
981 return text.replace(VALUE_SLOT, 'Name')
984@no_type_check
985def weave_meta_part_approvals_date_and_signature_label(
986 mapper: dict[str, Union[str, int, bool, None]],
987 text: str,
988) -> str:
989 """Weave in the approvals_date_and_signature_label from mapper or default.
991 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_DATE_%_AND_%_SIGNATURE_%_LABEL_%%')
992 """
993 if mapper.get('approvals_date_and_signature_label'):
994 return text.replace(VALUE_SLOT, mapper['approvals_date_and_signature_label'])
995 else:
996 log.info('approvals_date_and_signature_label value missing ... setting default (Date and Signature)')
997 return text.replace(VALUE_SLOT, 'Date and Signature')
1000@no_type_check
1001def weave_meta_part_header_issue_revision_combined_label(
1002 mapper: dict[str, Union[str, int, bool, None]],
1003 text: str,
1004) -> str:
1005 """Weave in the header_issue_revision_combined_label from mapper or default.
1007 Trigger is text.rstrip().endswith('%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%')
1008 """
1009 do_show_key = 'header_issue_revision_combined_show'
1010 if mapper.get(do_show_key, None) is not None and not mapper[do_show_key]: 1010 ↛ 1011line 1010 didn't jump to line 1011 because the condition on line 1010 was never true
1011 log.info(f'{do_show_key} set to false' ' - hiding date slot in header by setting label to a single space(" ")')
1012 return text.replace(VALUE_SLOT, ' ')
1013 log.info(f'{do_show_key} not set - considering header_issue_revision_combined_label ...')
1014 if mapper.get('header_issue_revision_combined_label'):
1015 head_iss_rev_comb_label = mapper['header_issue_revision_combined_label'].strip()
1016 if not head_iss_rev_comb_label: 1016 ↛ 1017line 1016 didn't jump to line 1017 because the condition on line 1016 was never true
1017 head_iss_rev_comb_label = ' ' # single space to please the backend parser
1018 return text.replace(VALUE_SLOT, head_iss_rev_comb_label)
1019 else:
1020 log.info('header_issue_revision_combined_label value missing ... setting default(Issue, Revision:)')
1021 return text.replace(VALUE_SLOT, 'Issue, Revision:')
1024@no_type_check
1025def weave_meta_part_header_issue_revision_combined(
1026 mapper: dict[str, Union[str, int, bool, None]],
1027 text: str,
1028) -> str:
1029 """Weave in the header_issue_revision_combined from mapper or default.
1031 Trigger is text.rstrip().endswith('%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%')
1032 """
1033 do_show_key = 'header_issue_revision_combined_show'
1034 if mapper.get(do_show_key, None) is not None and not mapper[do_show_key]: 1034 ↛ 1035line 1034 didn't jump to line 1035 because the condition on line 1034 was never true
1035 log.info(f'{do_show_key} set to false' ' - hiding date slot in header by setting value to a single space(" ")')
1036 return text.replace(VALUE_SLOT, ' ')
1037 log.info(f'{do_show_key} not set - considering header_issue_revision_combined ...')
1038 if mapper.get('header_issue_revision_combined'):
1039 return text.replace(VALUE_SLOT, mapper['header_issue_revision_combined'])
1040 else:
1041 log.info(
1042 'header_issue_revision_combined value missing ... setting'
1043 ' default (Iss \\theMetaIssCode, Rev \\theMetaRevCode)'
1044 )
1045 return text.replace(VALUE_SLOT, r'Iss \theMetaIssCode, Rev \theMetaRevCode')
1048@no_type_check
1049def weave_meta_part_proprietary_information(
1050 mapper: dict[str, Union[str, int, bool, None]],
1051 text: str,
1052) -> str:
1053 """Weave in the proprietary_information from mapper or default.
1055 Trigger is text.rstrip().endswith('%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%')
1056 """
1057 if mapper.get('proprietary_information'):
1058 prop_info = mapper['proprietary_information']
1059 if pathlib.Path(prop_info).is_file():
1060 try:
1061 prop_info_from_file = pathlib.Path(prop_info).open().read()
1062 prop_info = prop_info_from_file
1063 except (OSError, UnicodeDecodeError) as err:
1064 log.error(f'interpretation of proprietary_information value ({prop_info}) failed with error: {err}')
1065 log.warning(f'using value ({prop_info}) directly for proprietary_information')
1066 else:
1067 log.info(f'using value ({prop_info}) directly for proprietary_information (no file)')
1068 return text.replace(VALUE_SLOT, prop_info)
1069 else:
1070 log.warning('proprietary_information value missing ... setting default from module ...')
1071 prop_info = WEAVE_DEFAULTS['proprietary_information']
1072 if pathlib.Path(prop_info).is_file(): 1072 ↛ 1080line 1072 didn't jump to line 1080 because the condition on line 1072 was always true
1073 try:
1074 prop_info_from_file = pathlib.Path(prop_info).open().read()
1075 prop_info = prop_info_from_file
1076 except (OSError, UnicodeDecodeError) as err:
1077 log.error(f'interpretation of proprietary_information value ({prop_info}) failed with error: {err}')
1078 log.warning(f'using value ({prop_info}) directly for proprietary_information')
1079 else:
1080 log.info(f'using value ({prop_info}) directly for proprietary_information (no file)')
1081 return text.replace(VALUE_SLOT, prop_info)
1084@no_type_check
1085def weave_meta_part_stretch(
1086 mapper: dict[str, Union[str, int, bool, None]],
1087 text: str,
1088) -> str:
1089 """Weave in the stretch from mapper or default.
1091 Trigger is text.rstrip().endswith('%%_PATCH_%_STRETCH_%%')
1092 """
1093 return weave_meta_part_with_default_slot(mapper, text, 'stretch')
1096@no_type_check
1097def weave_meta_part_lox_indent(
1098 mapper: dict[str, Union[str, int, bool, None]],
1099 text: str,
1100) -> str:
1101 """Weave in the lox_indent from mapper or default.
1103 Trigger is text.rstrip().endswith('%%_PATCH_%_LOX_INDENT_%%')
1104 """
1105 return weave_meta_part_with_default_slot(mapper, text, 'lox_indent')
1108@no_type_check
1109def dispatch_meta_weaver(
1110 mapper: dict[str, Union[str, int, bool, None]],
1111 text: str,
1112) -> str:
1113 """Dispatch the meta weaver by mapping to handled groups per source marker."""
1114 dispatch = {
1115 '%%_PATCH_%_HEADER_%_TITLE_%%': weave_meta_part_header_title,
1116 '%%_PATCH_%_TITLE_%_SLUG_%%': weave_meta_part_title_slug,
1117 '%%_PATCH_%_MAIN_%_TITLE_%%': weave_meta_part_title,
1118 '%%_PATCH_%_SUB_%_TITLE_%%': weave_meta_part_sub_title,
1119 '%%_PATCH_%_TYPE_%%': weave_meta_part_header_type,
1120 '%%_PATCH_%_ID_%_LABEL_%%': weave_meta_part_header_id_label,
1121 '%%_PATCH_%_ID_%%': weave_meta_part_header_id,
1122 '%%_PATCH_%_ISSUE_%%': weave_meta_part_issue,
1123 '%%_PATCH_%_REVISION_%%': weave_meta_part_revision,
1124 '%%_PATCH_%_DATE_%_LABEL_%%': weave_meta_part_header_date_label,
1125 '%%_PATCH_%_DATE_%%': weave_meta_part_header_date,
1126 '%%_PATCH_%_FRAME_%_NOTE_%%': weave_meta_part_footer_frame_note,
1127 '%%_PATCH_%_FOOT_%_PAGE_%_COUNTER_%_LABEL_%%': weave_meta_part_footer_page_number_prefix,
1128 '%%_PATCH_%_CHANGELOG_%_ISSUE_%_LABEL_%%': weave_meta_part_change_log_issue_label,
1129 '%%_PATCH_%_CHANGELOG_%_REVISION_%_LABEL_%%': weave_meta_part_change_log_revision_label,
1130 '%%_PATCH_%_CHANGELOG_%_DATE_%_LABEL_%%': weave_meta_part_change_log_date_label,
1131 '%%_PATCH_%_CHANGELOG_%_AUTHOR_%_LABEL_%%': weave_meta_part_change_log_author_label,
1132 '%%_PATCH_%_CHANGELOG_%_DESCRIPTION_%_LABEL_%%': weave_meta_part_change_log_description_label,
1133 '%%_PATCH_%_APPROVALS_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%': weave_meta_part_approvals_adjustable_vertical_space,
1134 '%%_PATCH_%_BLURB_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%': weave_meta_part_proprietary_information_adjustable_vertical_space, # noqa
1135 '%%_PATCH_%_BLURB_%_TUNE_%_HEADER_%_SEP_%%': weave_meta_part_proprietary_information_tune_header_sep,
1136 '%%_PATCH_%_CHANGE_%_LOG_%_TUNE_%_HEADER_%_SEP_%%': weave_meta_part_change_log_tune_header_sep,
1137 '%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_LABEL_%%': weave_meta_part_approvals_department_label,
1138 '%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%': weave_meta_part_approvals_department_value,
1139 '%%_PATCH_%_APPROVALS_%_ROLE_%_LABEL_%%': weave_meta_part_approvals_role_label,
1140 '%%_PATCH_%_APPROVALS_%_NAME_%_LABEL_%%': weave_meta_part_approvals_name_label,
1141 '%%_PATCH_%_APPROVALS_%_DATE_%_AND_%_SIGNATURE_%_LABEL_%%': weave_meta_part_approvals_date_and_signature_label,
1142 '%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%': weave_meta_part_header_issue_revision_combined_label,
1143 '%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%': weave_meta_part_header_issue_revision_combined,
1144 '%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%': weave_meta_part_proprietary_information,
1145 '%%_PATCH_%_STRETCH_%%': weave_meta_part_stretch,
1146 '%%_PATCH_%_LOX_INDENT_%%': weave_meta_part_lox_indent,
1147 }
1148 for trigger, weaver in dispatch.items():
1149 if text.rstrip().endswith(trigger):
1150 return weaver(mapper, text)
1151 return text
1154@no_type_check
1155def weave_meta_meta(meta_map: gat.Meta, latex: list[str]) -> list[str]:
1156 """TODO."""
1157 log.info('weaving in the meta data per metadata.tex.in into metadata.tex ...')
1158 completed = [dispatch_meta_weaver(meta_map['document']['common'], line) for line in latex]
1159 if completed and completed[-1]:
1160 completed.append('\n')
1161 return completed
1164@no_type_check
1165def weave(
1166 doc_root: Union[str, pathlib.Path],
1167 structure_name: str,
1168 target_key: str,
1169 facet_key: str,
1170 options: dict[str, bool],
1171 externals: ExternalsType,
1172) -> int:
1173 """Later alligator."""
1174 log.info(LOG_SEPARATOR)
1175 log.info('entered meta weave function ...')
1176 target_code = target_key
1177 facet_code = facet_key
1178 if not facet_code.strip() or not target_code.strip(): 1178 ↛ 1179line 1178 didn't jump to line 1179 because the condition on line 1178 was never true
1179 log.error(f'meta requires non-empty target ({target_code}) and facet ({facet_code}) codes')
1180 return 2
1182 log.info(f'parsed target ({target_code}) and facet ({facet_code}) from request')
1184 structure, asset_map = gat.prelude(
1185 doc_root=doc_root, structure_name=structure_name, target_key=target_key, facet_key=facet_key, command='meta'
1186 )
1187 log.info(f'prelude teleported processor into the document root at ({os.getcwd()}/)')
1188 rel_concat_folder_path = pathlib.Path('render/pdf/')
1189 rel_concat_folder_path.mkdir(parents=True, exist_ok=True)
1190 os.chdir(rel_concat_folder_path)
1191 log.info(f'meta (this processor) teleported into the render/pdf location ({os.getcwd()}/)')
1193 ok, aspect_map = too.load_target(target_code, facet_code)
1194 if not ok or not aspect_map: 1194 ↛ 1195line 1194 didn't jump to line 1195 because the condition on line 1194 was never true
1195 return 0 if ok else 1
1197 metadata = process_meta(aspect_map)
1198 if isinstance(metadata, int): 1198 ↛ 1199line 1198 didn't jump to line 1199 because the condition on line 1198 was never true
1199 return 1
1201 meta_doc_common = metadata['document']['common'] # noqa
1202 log.debug(f'in meta.weave {meta_doc_common=}')
1203 log.debug(f'in meta.weave {externals=}')
1204 if externals['bookmatter']['is_custom']: 1204 ↛ 1205line 1204 didn't jump to line 1205 because the condition on line 1204 was never true
1205 log.info(
1206 'per environment variable value request to load external bookmatter layout template'
1207 f' from {externals["bookmatter"]["id"]} for title page incl. approvals'
1208 )
1209 log.debug(f'in meta.weave bookmatter_path is "{meta_doc_common.get("bookmatter_path", "NOT-PRESENT")}"')
1210 if 'bookmatter_path' in meta_doc_common: 1210 ↛ 1211line 1210 didn't jump to line 1211 because the condition on line 1210 was never true
1211 bookmatter_path_str = meta_doc_common['bookmatter_path']
1212 if bookmatter_path_str and isinstance(bookmatter_path_str, str):
1213 externals['bookmatter'] = {'id': bookmatter_path_str.strip(), 'is_custom': True}
1214 log.info(
1215 f'per configuration variable value request to load external bookmatter layout template'
1216 f' from {externals["bookmatter"]["id"]} title page incl. approvals'
1217 )
1219 if externals['driver']['is_custom']: 1219 ↛ 1220line 1219 didn't jump to line 1220 because the condition on line 1219 was never true
1220 log.info(
1221 'per environment variable value request to load external driver layout template'
1222 f' from {externals["driver"]["id"]} for general document structure'
1223 )
1224 log.debug(f'in meta.weave driver_path is "{meta_doc_common.get("driver_path", "NOT-PRESENT")}"')
1225 if 'driver_path' in meta_doc_common: 1225 ↛ 1226line 1225 didn't jump to line 1226 because the condition on line 1225 was never true
1226 driver_path_str = meta_doc_common['driver_path']
1227 if driver_path_str and isinstance(driver_path_str, str):
1228 externals['driver'] = {'id': driver_path_str.strip(), 'is_custom': True}
1229 log.info(
1230 f'per configuration variable value request to load external driver layout template'
1231 f' from {externals["driver"]["id"]} for general document structure'
1232 )
1234 if externals['metadata']['is_custom']: 1234 ↛ 1235line 1234 didn't jump to line 1235 because the condition on line 1234 was never true
1235 log.info(
1236 'per environment variable value request to load external metadata template'
1237 f' from {externals["metadata"]["id"]} for mapping values to required keys'
1238 )
1239 log.debug(f'in meta.weave metadata_path is "{meta_doc_common.get("metadata_path", "NOT-PRESENT")}"')
1240 if 'metadata_path' in meta_doc_common: 1240 ↛ 1241line 1240 didn't jump to line 1241 because the condition on line 1240 was never true
1241 metadata_path_str = meta_doc_common['metadata_path']
1242 if metadata_path_str and isinstance(metadata_path_str, str):
1243 externals['metadata'] = {'id': metadata_path_str.strip(), 'is_custom': True}
1244 log.info(
1245 f'per configuration variable value request to load external metadata template'
1246 f' from {externals["metadata"]["id"]} for mapping values to required keys'
1247 )
1249 if externals['publisher']['is_custom']: 1249 ↛ 1250line 1249 didn't jump to line 1250 because the condition on line 1249 was never true
1250 log.info(
1251 'per environment variable value request to load external publisher layout template'
1252 f' from {externals["publisher"]["id"]} for changes and notices'
1253 )
1254 log.debug(f'in meta.weave publisher_path is "{meta_doc_common.get("publisher_path", "NOT-PRESENT")}"')
1255 if 'publisher_path' in meta_doc_common: 1255 ↛ 1256line 1255 didn't jump to line 1256 because the condition on line 1255 was never true
1256 publisher_path_str = meta_doc_common['publisher_path']
1257 if publisher_path_str and isinstance(publisher_path_str, str):
1258 externals['publisher'] = {'id': publisher_path_str.strip(), 'is_custom': True}
1259 log.info(
1260 f'per configuration variable value request to load external publisher layout template'
1261 f' from {externals["publisher"]["id"]} for changes and notices'
1262 )
1264 if externals['setup']['is_custom']: 1264 ↛ 1265line 1264 didn't jump to line 1265 because the condition on line 1264 was never true
1265 log.info(
1266 'per environment variable value request to load external setup layout template'
1267 f' from {externals["setup"]["id"]} for general document setup'
1268 )
1269 log.debug(f'in meta.weave setup_path is "{meta_doc_common.get("setup_path", "NOT-PRESENT")}"')
1270 if 'setup_path' in meta_doc_common: 1270 ↛ 1271line 1270 didn't jump to line 1271 because the condition on line 1270 was never true
1271 setup_path_str = meta_doc_common['setup_path']
1272 if setup_path_str and isinstance(setup_path_str, str):
1273 externals['setup'] = {'id': setup_path_str.strip(), 'is_custom': True}
1274 log.info(
1275 f'per configuration variable value request to load external setup layout template'
1276 f' from {externals["setup"]["id"]} for general document setup'
1277 )
1279 if 'approvals_strategy' in meta_doc_common:
1280 approvals_strategy_str = meta_doc_common['approvals_strategy']
1281 if approvals_strategy_str and approvals_strategy_str in KNOWN_APPROVALS_STRATEGIES: 1281 ↛ 1289line 1281 didn't jump to line 1289 because the condition on line 1281 was always true
1282 memo = options.get('approvals_strategy', 'unset')
1283 options['approvals_strategy'] = approvals_strategy_str
1284 log.info(
1285 f'per configuration variable value request for approvals strategy ({approvals_strategy_str})'
1286 f' was set before to ({memo}) from default or command line'
1287 )
1289 metadata_template_is_custom = externals['metadata']['is_custom']
1290 metadata_template = str(externals['metadata']['id'])
1291 metadata_path = pathlib.Path('metadata.tex')
1293 metadata_template = tpl.load_resource(metadata_template, metadata_template_is_custom)
1294 lines = [line.rstrip() for line in metadata_template.split('\n')]
1295 lines = weave_meta_meta(metadata, lines)
1296 with open(metadata_path, 'wt', encoding=ENCODING) as handle:
1297 handle.write('\n'.join(lines))
1299 driver_template_is_custom = externals['driver']['is_custom']
1300 driver_template = str(externals['driver']['id'])
1301 driver_path = pathlib.Path('driver.tex')
1303 driver_template = tpl.load_resource(driver_template, driver_template_is_custom)
1304 lines = [line.rstrip() for line in driver_template.split('\n')]
1305 lines = weave_meta_driver(metadata, lines)
1306 with open(driver_path, 'wt', encoding=ENCODING) as handle:
1307 handle.write('\n'.join(lines))
1309 setup_template_is_custom = externals['setup']['is_custom']
1310 setup_template = str(externals['setup']['id'])
1311 setup_path = pathlib.Path('setup.tex')
1313 setup_template = tpl.load_resource(setup_template, setup_template_is_custom)
1314 lines = [line.rstrip() for line in setup_template.split('\n')]
1315 lines = weave_meta_setup(metadata, lines)
1316 with open(setup_path, 'wt', encoding=ENCODING) as handle:
1317 handle.write('\n'.join(lines))
1319 return 0