19.35%
532 statements
« prev ^ index » next coverage.py v7.6.8, created at 2024-11-25 15:36:16 +00:00
« prev ^ index » next coverage.py v7.6.8, created at 2024-11-25 15:36:16 +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, LOG_SEPARATOR, log
15METADATA_TEMPLATE = os.getenv('LIITOS_METADATA_TEMPLATE', '')
16METADATA_TEMPLATE_IS_EXTERNAL = bool(METADATA_TEMPLATE)
17if not METADATA_TEMPLATE: 17 ↛ 20line 17 didn't jump to line 20 because the condition on line 17 was always true
18 METADATA_TEMPLATE = 'templates/metadata.tex.in'
20METADATA_PATH = pathlib.Path('metadata.tex')
22SETUP_TEMPLATE = os.getenv('LIITOS_SETUP_TEMPLATE', '')
23SETUP_TEMPLATE_IS_EXTERNAL = bool(SETUP_TEMPLATE)
24if not SETUP_TEMPLATE: 24 ↛ 27line 24 didn't jump to line 27 because the condition on line 24 was always true
25 SETUP_TEMPLATE = 'templates/setup.tex.in'
27SETUP_PATH = pathlib.Path('setup.tex')
29DRIVER_TEMPLATE = os.getenv('LIITOS_DRIVER_TEMPLATE', '')
30DRIVER_TEMPLATE_IS_EXTERNAL = bool(DRIVER_TEMPLATE)
31if not DRIVER_TEMPLATE: 31 ↛ 34line 31 didn't jump to line 34 because the condition on line 31 was always true
32 DRIVER_TEMPLATE = 'templates/driver.tex.in'
34DRIVER_PATH = pathlib.Path('driver.tex')
36VALUE_SLOT = 'VALUE.SLOT'
37DOC_BASE = pathlib.Path('..', '..')
38STRUCTURE_PATH = DOC_BASE / 'structure.yml'
39MAGIC_OF_TODAY = 'PUBLICATIONDATE'
41WEAVE_DEFAULTS = {
42 'font_path': '/opt/fonts/',
43 'font_suffix': '.otf',
44 'bold_font': 'ITCFranklinGothicStd-Demi',
45 'italic_font': 'ITCFranklinGothicStd-BookIt',
46 'bold_italic_font': 'ITCFranklinGothicStd-DemiIt',
47 'main_font': 'ITCFranklinGothicStd-Book',
48 'fixed_font_package': 'sourcecodepro',
49 'code_fontsize': r'\scriptsize',
50 'chosen_logo': '/opt/logo/liitos-logo.png',
51 'footer_frame_note': os.getenv('LIITOS_FOOTER_FRAME_NOTE', ' '), # TODO
52 'footer_outer_field_normal_pages': r'\theMetaPageNumPrefix { } \thepage { }',
53 'approvals_adjustable_vertical_space': '2.5em',
54 'change_log_tune_header_sep': '-0em',
55 'proprietary_information': '/opt/legal/proprietary-information.txt',
56 'proprietary_information_adjustable_vertical_space': '-0em',
57 'proprietary_information_tune_header_sep': '-0em',
58}
59ACROSS = {
60 'eff_font_folder': '',
61 'eff_font_suffix': '',
62}
65@no_type_check
66def process_meta(aspects: dict[str, str]) -> Union[gat.Meta, int]:
67 """TODO."""
68 meta_path = DOC_BASE / aspects[gat.KEY_META]
69 if not meta_path.is_file() or not meta_path.stat().st_size:
70 log.error(f'destructure failed to find non-empty meta file at {meta_path}')
71 return 1
72 if meta_path.suffix.lower() not in ('.yaml', '.yml'):
73 return 1
74 with open(meta_path, 'rt', encoding=ENCODING) as handle:
75 metadata = yaml.safe_load(handle)
76 if not metadata:
77 log.error(f'empty metadata file? Please add metadata to ({meta_path})')
78 return 1
79 if 'import' in metadata['document']:
80 base_meta_path = DOC_BASE / metadata['document']['import']
81 if not base_meta_path.is_file() or not base_meta_path.stat().st_size:
82 log.error(
83 f'metadata declares import of base data from ({base_meta_path.name})'
84 f' but failed to find non-empty base file at {base_meta_path}'
85 )
86 return 1
87 with open(base_meta_path, 'rt', encoding=ENCODING) as handle:
88 base_data = yaml.safe_load(handle)
89 for key, value in metadata['document']['patch'].items():
90 base_data['document']['common'][key] = value
91 metadata = base_data
92 with open('metadata.yml', 'wt', encoding=ENCODING) as handle:
93 yaml.dump(metadata, handle, default_flow_style=False)
94 return metadata
97@no_type_check
98def weave_setup_font_path(
99 mapper: dict[str, Union[str, int, bool, None]],
100 text: str,
101) -> str:
102 """Weave in the xxxx from mapper or default for driver.
104 Trigger is text.rstrip().endswith('%%_PATCH_%_FONT_%_PATH_%%')
105 """
106 defaults = {**WEAVE_DEFAULTS}
107 if mapper.get('font_path'):
108 font_path = mapper.get('font_path')
109 if not pathlib.Path(font_path).is_dir():
110 log.warning(f'font_path ({font_path}) is no directory on this system - rendering may not work as intended')
111 ACROSS['eff_font_folder'] = font_path
112 return text.replace(VALUE_SLOT, font_path)
113 else:
114 log.warning(f'font_path value missing ... setting default ({defaults["font_path"]})')
115 ACROSS['eff_font_folder'] = defaults['font_path']
116 return text.replace(VALUE_SLOT, defaults['font_path'])
119@no_type_check
120def weave_setup_font_suffix(
121 mapper: dict[str, Union[str, int, bool, None]],
122 text: str,
123) -> str:
124 """Weave in the font_suffix from mapper or default for driver.
126 Trigger is text.rstrip().endswith('%%_PATCH_%_FONT_%_SUFFIX_%%')
127 """
128 defaults = {**WEAVE_DEFAULTS}
129 if mapper.get('font_suffix'):
130 font_suffix = mapper.get('font_suffix')
131 if font_suffix not in ('.otf', '.ttf'):
132 log.warning(f'font_suffix ({font_suffix}) is unexpected - rendering may not work as intended')
133 ACROSS['eff_font_suffix'] = font_suffix
134 return text.replace(VALUE_SLOT, font_suffix)
135 else:
136 log.warning(f'font_suffix value missing ... setting default ({defaults["font_suffix"]})')
137 ACROSS['eff_font_suffix'] = defaults['font_suffix']
138 return text.replace(VALUE_SLOT, defaults['font_suffix'])
141@no_type_check
142def weave_setup_bold_font(
143 mapper: dict[str, Union[str, int, bool, None]],
144 text: str,
145) -> str:
146 """Weave in the bold_font from mapper or default for driver.
148 Trigger is text.rstrip().endswith('%%_PATCH_%_BOLD_%_FONT_%%')
149 """
150 defaults = {**WEAVE_DEFAULTS}
151 eff_font_folder = ACROSS['eff_font_folder']
152 eff_font_suffix = ACROSS['eff_font_suffix']
153 if mapper.get('bold_font'):
154 bold_font = mapper.get('bold_font')
155 font_path = pathlib.Path(eff_font_folder) / f'{bold_font}{eff_font_suffix}'
156 if not font_path.is_file():
157 log.warning(
158 f'bold_font ({bold_font}) is not found'
159 f' as ({font_path}) on this system - rendering may not work as intended'
160 )
161 return text.replace(VALUE_SLOT, bold_font)
162 else:
163 log.warning(f'bold_font value missing ... setting default ({defaults["bold_font"]})')
164 return text.replace(VALUE_SLOT, defaults['bold_font'])
167@no_type_check
168def weave_setup_italic_font(
169 mapper: dict[str, Union[str, int, bool, None]],
170 text: str,
171) -> str:
172 """Weave in the italic_font from mapper or default for driver.
174 Trigger is text.rstrip().endswith('%%_PATCH_%_ITALIC_%_FONT_%%')
175 """
176 defaults = {**WEAVE_DEFAULTS}
177 eff_font_folder = ACROSS['eff_font_folder']
178 eff_font_suffix = ACROSS['eff_font_suffix']
179 if mapper.get('italic_font'):
180 italic_font = mapper.get('italic_font')
181 font_path = pathlib.Path(eff_font_folder) / f'{italic_font}{eff_font_suffix}'
182 if not font_path.is_file():
183 log.warning(
184 f'italic_font ({italic_font}) is not found'
185 f' as ({font_path}) on this system - rendering may not work as intended'
186 )
187 return text.replace(VALUE_SLOT, italic_font)
188 else:
189 log.warning(f'italic_font value missing ... setting default ({defaults["italic_font"]})')
190 return text.replace(VALUE_SLOT, defaults['italic_font'])
193@no_type_check
194def weave_setup_bold_italic_font(
195 mapper: dict[str, Union[str, int, bool, None]],
196 text: str,
197) -> str:
198 """Weave in the bold_italic_font from mapper or default for driver.
200 Trigger is text.rstrip().endswith('%%_PATCH_%_BOLDITALIC_%_FONT_%%')
201 """
202 defaults = {**WEAVE_DEFAULTS}
203 eff_font_folder = ACROSS['eff_font_folder']
204 eff_font_suffix = ACROSS['eff_font_suffix']
205 if mapper.get('bold_italic_font'):
206 bold_italic_font = mapper.get('bold_italic_font')
207 font_path = pathlib.Path(eff_font_folder) / f'{bold_italic_font}{eff_font_suffix}'
208 if not font_path.is_file():
209 log.warning(
210 f'bold_italic_font ({bold_italic_font}) is not found'
211 f' as ({font_path}) on this system - rendering may not work as intended'
212 )
213 return text.replace(VALUE_SLOT, bold_italic_font)
214 else:
215 log.warning(f'bold_italic_font value missing ... setting default ({defaults["bold_italic_font"]})')
216 return text.replace(VALUE_SLOT, defaults['bold_italic_font'])
219@no_type_check
220def weave_setup_main_font(
221 mapper: dict[str, Union[str, int, bool, None]],
222 text: str,
223) -> str:
224 """Weave in the main_font from mapper or default for driver.
226 Trigger is text.rstrip().endswith('%%_PATCH_%_MAIN_%_FONT_%%')
227 """
228 defaults = {**WEAVE_DEFAULTS}
229 eff_font_folder = ACROSS['eff_font_folder']
230 eff_font_suffix = ACROSS['eff_font_suffix']
231 if mapper.get('main_font'):
232 main_font = mapper.get('main_font')
233 font_path = pathlib.Path(eff_font_folder) / f'{main_font}{eff_font_suffix}'
234 if not font_path.is_file():
235 log.warning(
236 f'main_font ({main_font}) is not found'
237 f' as ({font_path}) on this system - rendering may not work as intended'
238 )
239 return text.replace(VALUE_SLOT, main_font)
240 else:
241 log.warning(f'main_font value missing ... setting default ({defaults["main_font"]})')
242 return text.replace(VALUE_SLOT, defaults['main_font'])
245@no_type_check
246def weave_setup_fixed_font_package(
247 mapper: dict[str, Union[str, int, bool, None]],
248 text: str,
249) -> str:
250 """Weave in the fixed_font_package from mapper or default for driver.
252 Trigger is text.rstrip().endswith('%%_PATCH_%_FIXED_%_FONT_%_PACKAGE_%%')
253 """
254 defaults = {**WEAVE_DEFAULTS}
255 if mapper.get('fixed_font_package'):
256 fixed_font_package = mapper.get('fixed_font_package')
257 if fixed_font_package != defaults['fixed_font_package']:
258 log.warning(
259 f'fixed_font_package ({fixed_font_package}) has not'
260 ' been tested on this system - rendering may not work as intended'
261 )
262 return text.replace(VALUE_SLOT, fixed_font_package)
263 else:
264 log.warning(f'fixed_font_package value missing ... setting default ({defaults["fixed_font_package"]})')
265 return text.replace(VALUE_SLOT, defaults['fixed_font_package'])
268@no_type_check
269def weave_setup_code_fontsize(
270 mapper: dict[str, Union[str, int, bool, None]],
271 text: str,
272) -> str:
273 """Weave in the code_fontsize from mapper or default for driver.
275 Trigger is text.rstrip().endswith('%%_PATCH_%_CODE_%_FONTSIZE_%%')
276 """
277 defaults = {**WEAVE_DEFAULTS}
278 if mapper.get('code_fontsize'):
279 code_fontsize = mapper.get('code_fontsize')
280 valid_code_font_sizes = (
281 r'\Huge',
282 r'\huge',
283 r'\LARGE',
284 r'\Large',
285 r'\large',
286 r'\normalsize',
287 r'\small',
288 r'\footnotesize',
289 r'\scriptsize',
290 r'\tiny',
291 )
292 bs = '\\'
293 sizes = tuple(size[1:] for size in valid_code_font_sizes)
294 if code_fontsize.startswith(r'\\'):
295 code_fontsize = code_fontsize[1:]
296 if code_fontsize not in valid_code_font_sizes:
297 log.error(
298 f'code_fontsize ({code_fontsize}) is not a valid font size value'
299 ' - rendering would not work as intended'
300 )
301 log.info(f'valid values for code_fontsize must be in {bs}{(", " + bs).join(sizes)}')
302 log.warning(
303 f'overriding code font size value with the (working) default of ({defaults["code_fontsize"]})'
304 f' - in config that would be {defaults["code_fontsize"]}'
305 )
306 return text.replace(VALUE_SLOT, defaults['code_fontsize'])
307 else:
308 return text.replace(VALUE_SLOT, code_fontsize)
309 else:
310 log.info(
311 f'code_fontsize value missing ... setting default ({defaults["code_fontsize"]})'
312 f' - in config that would be {defaults["code_fontsize"]}'
313 )
314 return text.replace(VALUE_SLOT, defaults['code_fontsize'])
317@no_type_check
318def weave_setup_chosen_logo(
319 mapper: dict[str, Union[str, int, bool, None]],
320 text: str,
321) -> str:
322 """Weave in the chosen_logo from mapper or default for driver.
324 Trigger is text.rstrip().endswith('%%_PATCH_%_CHOSEN_%_LOGO_%%')
325 """
326 defaults = {**WEAVE_DEFAULTS}
327 if mapper.get('chosen_logo'):
328 chosen_logo = mapper.get('chosen_logo')
329 logo_path = pathlib.Path(chosen_logo)
330 if not logo_path.is_file():
331 log.warning(
332 f'chosen_logo ({chosen_logo}) is not found'
333 f' as ({logo_path}) on this system - rendering may not work as intended'
334 )
335 return text.replace(VALUE_SLOT, chosen_logo)
336 else:
337 log.info(f'chosen_logo value missing ... setting default ({defaults["chosen_logo"]})')
338 return text.replace(VALUE_SLOT, defaults['chosen_logo'])
341@no_type_check
342def weave_setup_footer_outer_field_normal_pages(
343 mapper: dict[str, Union[str, int, bool, None]],
344 text: str,
345) -> str:
346 """Weave in the footer_outer_field_normal_pages from mapper or default for driver.
348 Trigger is text.rstrip().endswith('%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%')
349 """
350 defaults = {**WEAVE_DEFAULTS}
351 if mapper.get('footer_outer_field_normal_pages'):
352 footer_outer_field_normal_pages = mapper.get('footer_outer_field_normal_pages')
353 return text.replace(VALUE_SLOT, footer_outer_field_normal_pages)
354 else:
355 log.info(
356 'footer_outer_field_normal_pages value missing ...'
357 f' setting default ({defaults["footer_outer_field_normal_pages"]})'
358 )
359 return text.replace(VALUE_SLOT, defaults['footer_outer_field_normal_pages'])
362@no_type_check
363def dispatch_setup_weaver(
364 mapper: dict[str, Union[str, int, bool, None]],
365 text: str,
366) -> str:
367 """Dispatch the driver weaver by mapping to handled groups per source marker."""
368 dispatch = {
369 '%%_PATCH_%_FONT_%_PATH_%%': weave_setup_font_path,
370 '%%_PATCH_%_FONT_%_SUFFIX_%%': weave_setup_font_suffix,
371 '%%_PATCH_%_BOLD_%_FONT_%%': weave_setup_bold_font,
372 '%%_PATCH_%_ITALIC_%_FONT_%%': weave_setup_italic_font,
373 '%%_PATCH_%_BOLDITALIC_%_FONT_%%': weave_setup_bold_italic_font,
374 '%%_PATCH_%_MAIN_%_FONT_%%': weave_setup_main_font,
375 '%%_PATCH_%_FIXED_%_FONT_%_PACKAGE_%%': weave_setup_fixed_font_package,
376 '%%_PATCH_%_CODE_%_FONTSIZE_%%': weave_setup_code_fontsize,
377 '%%_PATCH_%_CHOSEN_%_LOGO_%%': weave_setup_chosen_logo,
378 '%%_PATCH_%_NORMAL_%_PAGES_%_OUTER_%_FOOT_%_CONTENT_%_VALUE_%%': weave_setup_footer_outer_field_normal_pages,
379 }
380 for trigger, weaver in dispatch.items():
381 if text.rstrip().endswith(trigger):
382 return weaver(mapper, text)
383 return text
386@no_type_check
387def weave_meta_setup(meta_map: gat.Meta, latex: list[str]) -> list[str]:
388 """TODO."""
389 log.info('weaving in the meta data per setup.tex.in into setup.tex ...')
390 completed = [dispatch_setup_weaver(meta_map['document']['common'], line) for line in latex]
391 if completed and completed[-1]:
392 completed.append('\n')
393 return completed
396@no_type_check
397def weave_driver_toc_level(
398 mapper: dict[str, Union[str, int, bool, None]],
399 text: str,
400) -> str:
401 """Weave in the toc_level from mapper or default for driver.
403 Trigger is text.rstrip().endswith('%%_PATCH_%_TOC_%_LEVEL_%%')
404 """
405 toc_level = 2
406 if mapper.get('toc_level'):
407 try:
408 toc_level_read = int(mapper['toc_level'])
409 toc_level = toc_level_read if 0 < toc_level_read < 5 else 2
410 if toc_level != toc_level_read:
411 log.warning(
412 f'ignored toc level ({toc_level_read}) set to default (2) - expected value 0 < toc_level < 5'
413 )
414 except ValueError as err:
415 toc_level = 2
416 log.warning(f'toc_level ({mapper["toc_level"]}) not in (1, 2, 3, 4) - resorting to default ({toc_level})')
417 log.error(f'error detail: {err}')
418 else:
419 log.info(f'toc_level value missing ... setting default ({toc_level})')
420 return text.replace(VALUE_SLOT, str(toc_level))
423@no_type_check
424def weave_driver_list_of_figures(
425 mapper: dict[str, Union[str, int, bool, None]],
426 text: str,
427) -> str:
428 """Weave in the list_of_figures from mapper or default for driver.
430 Trigger is text.rstrip().endswith('%%_PATCH_%_LOF_%%')
431 """
432 if mapper.get('list_of_figures', None) is not None:
433 lof = mapper['list_of_figures']
434 if lof in ('', '%'):
435 return text.replace(VALUE_SLOT, str(lof))
436 else:
437 lof = '%'
438 log.warning(
439 f"list_of_figures ({mapper['list_of_figures']}) not in ('', '%')"
440 f' - resorting to default ({lof}) i.e. commenting out the list of figures'
441 )
442 else:
443 log.info('list_of_figures value missing ... setting default (comment out the lof per %)')
445 return text.replace(VALUE_SLOT, '%')
448@no_type_check
449def weave_driver_list_of_tables(
450 mapper: dict[str, Union[str, int, bool, None]],
451 text: str,
452) -> str:
453 """Weave in the list_of_tables from mapper or default for driver.
455 Trigger is text.rstrip().endswith('%%_PATCH_%_LOT_%%')
456 """
457 if mapper.get('list_of_tables', None) is not None:
458 lof = mapper['list_of_tables']
459 if lof in ('', '%'):
460 return text.replace(VALUE_SLOT, str(lof))
461 else:
462 lof = '%'
463 log.warning(
464 f"list_of_tables ({mapper['list_of_tables']}) not in ('', '%')"
465 f' - resorting to default ({lof}) i.e. commenting out the list of tables'
466 )
467 else:
468 log.info('list_of_tables value missing ... setting default (comment out the lot per %)')
470 return text.replace(VALUE_SLOT, '%')
473@no_type_check
474def dispatch_driver_weaver(
475 mapper: dict[str, Union[str, int, bool, None]],
476 text: str,
477) -> str:
478 """Dispatch the driver weaver by mapping to handled groups per source marker."""
479 dispatch = {
480 '%%_PATCH_%_TOC_%_LEVEL_%%': weave_driver_toc_level,
481 '%%_PATCH_%_LOF_%%': weave_driver_list_of_figures,
482 '%%_PATCH_%_LOT_%%': weave_driver_list_of_tables,
483 }
484 for trigger, weaver in dispatch.items():
485 if text.rstrip().endswith(trigger):
486 return weaver(mapper, text)
487 return text
490@no_type_check
491def weave_meta_driver(meta_map: gat.Meta, latex: list[str]) -> list[str]:
492 """TODO."""
493 log.info('weaving in the meta data per driver.tex.in into driver.tex ...')
494 completed = [dispatch_driver_weaver(meta_map['document']['common'], line) for line in latex]
495 if completed and completed[-1]:
496 completed.append('\n')
497 return completed
500@no_type_check
501def weave_meta_part_header_title(
502 mapper: dict[str, Union[str, int, bool, None]],
503 text: str,
504) -> str:
505 """Weave in the header_title from mapper or default.
507 Trigger is text.rstrip().endswith('%%_PATCH_%_HEADER_%_TITLE_%%')
508 """
509 if mapper.get('header_title'):
510 return text.replace(VALUE_SLOT, mapper['header_title'])
511 else:
512 log.info('header_title value missing ... setting default (the title value)')
513 return text.replace(VALUE_SLOT, mapper['title'])
516@no_type_check
517def weave_meta_part_title_slug(
518 mapper: dict[str, Union[str, int, bool, None]],
519 text: str,
520) -> str:
521 """Weave in the title slug deriving from mapper or default.
523 Trigger is text.rstrip().endswith('%%_PATCH_%_MAIN_%_TITLE_%_SLUG_%%')
524 """
525 if mapper.get('bookmark_title'):
526 return text.replace(VALUE_SLOT, mapper['bookmark_title'])
527 else:
528 log.info('bookmark_title value missing ... setting default (the slugged title value)')
529 return text.replace(VALUE_SLOT, mapper['title'].replace('\\\\', '').replace(' ', ' ').title())
532@no_type_check
533def weave_meta_part_title(
534 mapper: dict[str, Union[str, int, bool, None]],
535 text: str,
536) -> str:
537 """Weave in the title from mapper or default.
539 Trigger is text.rstrip().endswith('%%_PATCH_%_MAIN_%_TITLE_%%')
540 """
541 return text.replace(VALUE_SLOT, mapper['title'])
544@no_type_check
545def weave_meta_part_sub_title(
546 mapper: dict[str, Union[str, int, bool, None]],
547 text: str,
548) -> str:
549 """Weave in the sub_title from mapper or default.
551 Trigger is text.rstrip().endswith('%%_PATCH_%_SUB_%_TITLE_%%')
552 """
553 if mapper.get('sub_title'):
554 return text.replace(VALUE_SLOT, mapper['sub_title'])
555 else:
556 log.info('sub_title value missing ... setting default (single space)')
557 return text.replace(VALUE_SLOT, ' ')
560@no_type_check
561def weave_meta_part_header_type(
562 mapper: dict[str, Union[str, int, bool, None]],
563 text: str,
564) -> str:
565 """Weave in the header_type from mapper or default.
567 Trigger is text.rstrip().endswith('%%_PATCH_%_TYPE_%%')
568 """
569 if mapper.get('header_type'):
570 return text.replace(VALUE_SLOT, mapper['header_type'])
571 else:
572 log.info('header_type value missing ... setting default (Engineering Document)')
573 return text.replace(VALUE_SLOT, 'Engineering Document')
576@no_type_check
577def weave_meta_part_header_id_label(
578 mapper: dict[str, Union[str, int, bool, None]],
579 text: str,
580) -> str:
581 """Weave in the header_id_label from mapper or default.
583 Trigger is text.rstrip().endswith('%%_PATCH_%_ID_%_LABEL_%%')
584 """
585 if mapper.get('header_id_show', None) is not None and not mapper['header_id_show']:
586 log.info('header_id_show set to false - hiding id slot in header by setting label to a single space(" ")')
587 return text.replace(VALUE_SLOT, ' ')
588 log.info('header_id_show not set - considering header_id_label ...')
589 if mapper.get('header_id_label'):
590 pub_id_label = mapper['header_id_label'].strip()
591 if not pub_id_label:
592 pub_id_label = ' ' # single space to please the backend parser
593 return text.replace(VALUE_SLOT, pub_id_label)
594 else:
595 log.info('header_id_label value missing ... setting default(Doc. ID:)')
596 return text.replace(VALUE_SLOT, 'Doc. ID:')
599@no_type_check
600def weave_meta_part_header_id(
601 mapper: dict[str, Union[str, int, bool, None]],
602 text: str,
603) -> str:
604 """Weave in the header_id from mapper or default.
606 Trigger is text.rstrip().endswith('%%_PATCH_%_ID_%%')
607 """
608 if mapper.get('header_id_show', None) is not None and not mapper['header_id_show']:
609 log.info('header_id_show set to false - hiding id slot in header by setting value to a single space(" ")')
610 return text.replace(VALUE_SLOT, ' ')
611 log.info('header_id_show not set - considering header_id ...')
612 if mapper.get('header_id'):
613 return text.replace(VALUE_SLOT, mapper['header_id'])
614 else:
615 log.info('header_id value missing ... setting default (N/A)')
616 return text.replace(VALUE_SLOT, 'N/A')
619@no_type_check
620def weave_meta_part_issue(
621 mapper: dict[str, Union[str, int, bool, None]],
622 text: str,
623) -> str:
624 """Weave in the issue from mapper or default.
626 Trigger is text.rstrip().endswith('%%_PATCH_%_ISSUE_%%')
627 """
628 if mapper.get('issue'):
629 return text.replace(VALUE_SLOT, mapper['issue'])
630 else:
631 log.info('issue value missing ... setting default (01)')
632 return text.replace(VALUE_SLOT, '01')
635@no_type_check
636def weave_meta_part_revision(
637 mapper: dict[str, Union[str, int, bool, None]],
638 text: str,
639) -> str:
640 """Weave in the revision from mapper or default.
642 Trigger is text.rstrip().endswith('%%_PATCH_%_REVISION_%%')
643 """
644 if mapper.get('revision'):
645 return text.replace(VALUE_SLOT, mapper['revision'])
646 else:
647 log.info('revision value missing ... setting default (00)')
648 return text.replace(VALUE_SLOT, '00')
651@no_type_check
652def weave_meta_part_header_date_label(
653 mapper: dict[str, Union[str, int, bool, None]],
654 text: str,
655) -> str:
656 """Weave in the header_date_label from mapper or default.
658 Trigger is text.rstrip().endswith('%%_PATCH_%_DATE_%_LABEL_%%')
659 """
660 if mapper.get('header_date_show', None) is not None and not mapper['header_date_show']:
661 log.info('header_date_show set to false - hiding date slot in header by setting label to a single space(" ")')
662 return text.replace(VALUE_SLOT, ' ')
663 log.info('header_date_show not set - considering header_date_label ...')
664 if mapper.get('header_date_label'):
665 pub_date_label = mapper['header_date_label'].strip()
666 if not pub_date_label:
667 pub_date_label = ' ' # single space to please the backend parser
668 return text.replace(VALUE_SLOT, pub_date_label)
669 else:
670 log.info('header_date_label value missing ... setting default(" ")')
671 return text.replace(VALUE_SLOT, ' ')
674@no_type_check
675def weave_meta_part_header_date(
676 mapper: dict[str, Union[str, int, bool, None]],
677 text: str,
678) -> str:
679 """Weave in the header_date from mapper or default.
681 Trigger is text.rstrip().endswith('%%_PATCH_%_DATE_%%')
682 """
683 if mapper.get('header_date_show', None) is not None and not mapper['header_date_show']:
684 log.info('header_date_show set to false - hiding date slot in header by setting value to a single space(" ")')
685 return text.replace(VALUE_SLOT, ' ')
686 log.info('header_date_show not set - considering header_date ...')
687 if mapper.get('header_date_enable_auto', None) is not None and not mapper['header_date_enable_auto']:
688 log.info('header_date_enable_auto set to false - setting that slot value as is (no date semantics enforced)')
689 if mapper.get('header_date'):
690 pub_date_or_any = mapper['header_date'].strip()
691 if not pub_date_or_any:
692 pub_date_or_any = ' ' # single space to please the backend parser
693 return text.replace(VALUE_SLOT, pub_date_or_any)
694 else:
695 log.info('header_date value missing and as-is mode ... setting to single space ( ) a.k.a. hiding')
696 return text.replace(VALUE_SLOT, ' ')
697 else:
698 today = dti.datetime.today()
699 pub_date_today = today.strftime('%d %b %Y').upper()
700 if mapper.get('header_date'):
701 pub_date = mapper['header_date'].strip()
702 if pub_date == MAGIC_OF_TODAY:
703 pub_date = pub_date_today
704 return text.replace(VALUE_SLOT, pub_date)
705 else:
706 log.info('header_date value missing ... setting default as empty(" ")')
707 return text.replace(VALUE_SLOT, ' ')
710@no_type_check
711def weave_meta_part_footer_frame_note(
712 mapper: dict[str, Union[str, int, bool, None]],
713 text: str,
714) -> str:
715 """Weave in the footer_frame_note from mapper or default.
717 Trigger is text.rstrip().endswith('%%_PATCH_%_FRAME_%_NOTE_%%')
718 """
719 if mapper.get('footer_frame_note'):
720 return text.replace(VALUE_SLOT, mapper['footer_frame_note'])
721 else:
722 log.info('footer_frame_note value missing ... setting default from module / environment ...')
723 return text.replace(VALUE_SLOT, WEAVE_DEFAULTS['footer_frame_note'])
726@no_type_check
727def weave_meta_part_footer_page_number_prefix(
728 mapper: dict[str, Union[str, int, bool, None]],
729 text: str,
730) -> str:
731 """Weave in the footer_page_number_prefix from mapper or default.
733 Trigger is text.rstrip().endswith('%%_PATCH_%_FOOT_%_PAGE_%_COUNTER_%_LABEL_%%')
734 """
735 if mapper.get('footer_page_number_prefix'):
736 return text.replace(VALUE_SLOT, mapper['footer_page_number_prefix'])
737 else:
738 log.info('footer_page_number_prefix value missing ... setting default (Page)')
739 return text.replace(VALUE_SLOT, 'Page')
742@no_type_check
743def weave_meta_part_change_log_issue_label(
744 mapper: dict[str, Union[str, int, bool, None]],
745 text: str,
746) -> str:
747 """Weave in the change_log_issue_label from mapper or default.
749 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_ISSUE_%_LABEL_%%')
750 """
751 if mapper.get('change_log_issue_label'):
752 return text.replace(VALUE_SLOT, mapper['change_log_issue_label'])
753 else:
754 log.info('change_log_issue_label value missing ... setting default (Iss.)')
755 return text.replace(VALUE_SLOT, 'Iss.')
758@no_type_check
759def weave_meta_part_change_log_revision_label(
760 mapper: dict[str, Union[str, int, bool, None]],
761 text: str,
762) -> str:
763 """Weave in the change_log_revision_label from mapper or default.
765 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_REVISION_%_LABEL_%%')
766 """
767 if mapper.get('change_log_revision_label'):
768 return text.replace(VALUE_SLOT, mapper['change_log_revision_label'])
769 else:
770 log.info('change_log_revision_label value missing ... setting default (Rev.)')
771 return text.replace(VALUE_SLOT, 'Rev.')
774@no_type_check
775def weave_meta_part_change_log_date_label(
776 mapper: dict[str, Union[str, int, bool, None]],
777 text: str,
778) -> str:
779 """Weave in the change_log_date_label from mapper or default.
781 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_DATE_%_LABEL_%%')
782 """
783 if mapper.get('change_log_date_label'):
784 return text.replace(VALUE_SLOT, mapper['change_log_date_label'])
785 else:
786 log.info('change_log_date_label value missing ... setting default (Date)')
787 return text.replace(VALUE_SLOT, 'Date')
790@no_type_check
791def weave_meta_part_change_log_author_label(
792 mapper: dict[str, Union[str, int, bool, None]],
793 text: str,
794) -> str:
795 """Weave in the change_log_author_label from mapper or default.
797 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_AUTHOR_%_LABEL_%%')
798 """
799 if mapper.get('change_log_author_label'):
800 return text.replace(VALUE_SLOT, mapper['change_log_author_label'])
801 else:
802 log.info('change_log_author_label value missing ... setting default (Author)')
803 return text.replace(VALUE_SLOT, 'Author')
806@no_type_check
807def weave_meta_part_change_log_description_label(
808 mapper: dict[str, Union[str, int, bool, None]],
809 text: str,
810) -> str:
811 """Weave in the change_log_description_label from mapper or default.
813 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGELOG_%_DESCRIPTION_%_LABEL_%%')
814 """
815 if mapper.get('change_log_description_label'):
816 return text.replace(VALUE_SLOT, mapper['change_log_description_label'])
817 else:
818 log.info('change_log_description_label value missing ... setting default (Description)')
819 return text.replace(VALUE_SLOT, 'Description')
822@no_type_check
823def weave_meta_part_with_default_slot(
824 mapper: dict[str, Union[str, int, bool, None]],
825 text: str,
826 slot: str,
827) -> str:
828 """Do the conditional weaving of slot if text matches else used default (and log a warning)."""
829 if mapper.get(slot):
830 return text.replace(VALUE_SLOT, mapper[slot])
831 else:
832 log.info(f'{slot} value missing ... setting default ({WEAVE_DEFAULTS[slot]})')
833 return text.replace(VALUE_SLOT, WEAVE_DEFAULTS[slot])
836@no_type_check
837def weave_meta_part_approvals_adjustable_vertical_space(
838 mapper: dict[str, Union[str, int, bool, None]],
839 text: str,
840) -> str:
841 """Weave in the approvals_adjustable_vertical_space from mapper or default.
843 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%')
844 """
845 return weave_meta_part_with_default_slot(mapper, text, 'approvals_adjustable_vertical_space')
848@no_type_check
849def weave_meta_part_proprietary_information_adjustable_vertical_space(
850 mapper: dict[str, Union[str, int, bool, None]],
851 text: str,
852) -> str:
853 """Weave in the proprietary_information_adjustable_vertical_space from mapper or default.
855 Trigger is text.rstrip().endswith('%%_PATCH_%_BLURB_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%')
856 """
857 return weave_meta_part_with_default_slot(mapper, text, 'proprietary_information_adjustable_vertical_space')
860@no_type_check
861def weave_meta_part_proprietary_information_tune_header_sep(
862 mapper: dict[str, Union[str, int, bool, None]],
863 text: str,
864) -> str:
865 """Weave in the proprietary_information_tune_header_sep from mapper or default.
867 Trigger is text.rstrip().endswith('%%_PATCH_%_BLURB_%_TUNE_%_HEADER_%_SEP_%%')
868 """
869 return weave_meta_part_with_default_slot(mapper, text, 'proprietary_information_tune_header_sep')
872@no_type_check
873def weave_meta_part_change_log_tune_header_sep(
874 mapper: dict[str, Union[str, int, bool, None]],
875 text: str,
876) -> str:
877 """Weave in the change_log_tune_header_sep from mapper or default.
879 Trigger is text.rstrip().endswith('%%_PATCH_%_CHANGE_%_LOG_%_TUNE_%_HEADER_%_SEP_%%')
880 """
881 return weave_meta_part_with_default_slot(mapper, text, 'change_log_tune_header_sep')
884@no_type_check
885def weave_meta_part_approvals_department_label(
886 mapper: dict[str, Union[str, int, bool, None]],
887 text: str,
888) -> str:
889 """Weave in the approvals_department_label from mapper or default.
891 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_LABEL_%%')
892 """
893 if mapper.get('approvals_department_label'):
894 return text.replace(VALUE_SLOT, mapper['approvals_department_label'])
895 else:
896 log.info('approvals_department_label value missing ... setting default (Department)')
897 return text.replace(VALUE_SLOT, 'Department')
900@no_type_check
901def weave_meta_part_approvals_department_value(
902 mapper: dict[str, Union[str, int, bool, None]],
903 text: str,
904) -> str:
905 """Weave in the approvals_department_value from mapper or default.
907 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%')
908 """
909 if mapper.get('approvals_department_value'):
910 return text.replace(VALUE_SLOT, mapper['approvals_department_value'])
911 else:
912 log.info('approvals_department_value value missing ... setting default ( )')
913 return text.replace(VALUE_SLOT, ' ')
916@no_type_check
917def weave_meta_part_approvals_role_label(
918 mapper: dict[str, Union[str, int, bool, None]],
919 text: str,
920) -> str:
921 """Weave in the approvals_role_label from mapper or default.
923 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_ROLE_%_LABEL_%%')
924 """
925 if mapper.get('approvals_role_label'):
926 return text.replace(VALUE_SLOT, mapper['approvals_role_label'])
927 else:
928 log.info('approvals_role_label value missing ... setting default (Approvals)')
929 return text.replace(VALUE_SLOT, 'Approvals')
932@no_type_check
933def weave_meta_part_approvals_name_label(
934 mapper: dict[str, Union[str, int, bool, None]],
935 text: str,
936) -> str:
937 """Weave in the approvals_name_label from mapper or default.
939 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_NAME_%_LABEL_%%')
940 """
941 if mapper.get('approvals_name_label'):
942 return text.replace(VALUE_SLOT, mapper['approvals_name_label'])
943 else:
944 log.info('approvals_name_label value missing ... setting default (Name)')
945 return text.replace(VALUE_SLOT, 'Name')
948@no_type_check
949def weave_meta_part_approvals_date_and_signature_label(
950 mapper: dict[str, Union[str, int, bool, None]],
951 text: str,
952) -> str:
953 """Weave in the approvals_date_and_signature_label from mapper or default.
955 Trigger is text.rstrip().endswith('%%_PATCH_%_APPROVALS_%_DATE_%_AND_%_SIGNATURE_%_LABEL_%%')
956 """
957 if mapper.get('approvals_date_and_signature_label'):
958 return text.replace(VALUE_SLOT, mapper['approvals_date_and_signature_label'])
959 else:
960 log.info('approvals_date_and_signature_label value missing ... setting default (Date and Signature)')
961 return text.replace(VALUE_SLOT, 'Date and Signature')
964@no_type_check
965def weave_meta_part_header_issue_revision_combined_label(
966 mapper: dict[str, Union[str, int, bool, None]],
967 text: str,
968) -> str:
969 """Weave in the header_issue_revision_combined_label from mapper or default.
971 Trigger is text.rstrip().endswith('%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%')
972 """
973 do_show_key = 'header_issue_revision_combined_show'
974 if mapper.get(do_show_key, None) is not None and not mapper[do_show_key]:
975 log.info(f'{do_show_key} set to false' ' - hiding date slot in header by setting label to a single space(" ")')
976 return text.replace(VALUE_SLOT, ' ')
977 log.info(f'{do_show_key} not set - considering header_issue_revision_combined_label ...')
978 if mapper.get('header_issue_revision_combined_label'):
979 head_iss_rev_comb_label = mapper['header_issue_revision_combined_label'].strip()
980 if not head_iss_rev_comb_label:
981 head_iss_rev_comb_label = ' ' # single space to please the backend parser
982 return text.replace(VALUE_SLOT, head_iss_rev_comb_label)
983 else:
984 log.info('header_issue_revision_combined_label value missing ... setting default(Issue, Revision:)')
985 return text.replace(VALUE_SLOT, 'Issue, Revision:')
988@no_type_check
989def weave_meta_part_header_issue_revision_combined(
990 mapper: dict[str, Union[str, int, bool, None]],
991 text: str,
992) -> str:
993 """Weave in the header_issue_revision_combined from mapper or default.
995 Trigger is text.rstrip().endswith('%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%')
996 """
997 do_show_key = 'header_issue_revision_combined_show'
998 if mapper.get(do_show_key, None) is not None and not mapper[do_show_key]:
999 log.info(f'{do_show_key} set to false' ' - hiding date slot in header by setting value to a single space(" ")')
1000 return text.replace(VALUE_SLOT, ' ')
1001 log.info(f'{do_show_key} not set - considering header_issue_revision_combined ...')
1002 if mapper.get('header_issue_revision_combined'):
1003 return text.replace(VALUE_SLOT, mapper['header_issue_revision_combined'])
1004 else:
1005 log.info(
1006 'header_issue_revision_combined value missing ... setting'
1007 ' default (Iss \\theMetaIssCode, Rev \\theMetaRevCode)'
1008 )
1009 return text.replace(VALUE_SLOT, r'Iss \theMetaIssCode, Rev \theMetaRevCode')
1012@no_type_check
1013def weave_meta_part_proprietary_information(
1014 mapper: dict[str, Union[str, int, bool, None]],
1015 text: str,
1016) -> str:
1017 """Weave in the proprietary_information from mapper or default.
1019 Trigger is text.rstrip().endswith('%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%')
1020 """
1021 if mapper.get('proprietary_information'):
1022 prop_info = mapper['proprietary_information']
1023 if pathlib.Path(prop_info).is_file():
1024 try:
1025 prop_info_from_file = pathlib.Path(prop_info).open().read()
1026 prop_info = prop_info_from_file
1027 except (OSError, UnicodeDecodeError) as err:
1028 log.error(f'interpretation of proprietary_information value ({prop_info}) failed with error: {err}')
1029 log.warning(f'using value ({prop_info}) directly for proprietary_information')
1030 else:
1031 log.info(f'using value ({prop_info}) directly for proprietary_information (no file)')
1032 return text.replace(VALUE_SLOT, prop_info)
1033 else:
1034 log.warning('proprietary_information value missing ... setting default from module ...')
1035 prop_info = WEAVE_DEFAULTS['proprietary_information']
1036 if pathlib.Path(prop_info).is_file():
1037 try:
1038 prop_info_from_file = pathlib.Path(prop_info).open().read()
1039 prop_info = prop_info_from_file
1040 except (OSError, UnicodeDecodeError) as err:
1041 log.error(f'interpretation of proprietary_information value ({prop_info}) failed with error: {err}')
1042 log.warning(f'using value ({prop_info}) directly for proprietary_information')
1043 else:
1044 log.info(f'using value ({prop_info}) directly for proprietary_information (no file)')
1045 return text.replace(VALUE_SLOT, prop_info)
1048@no_type_check
1049def dispatch_meta_weaver(
1050 mapper: dict[str, Union[str, int, bool, None]],
1051 text: str,
1052) -> str:
1053 """Dispatch the meta weaver by mapping to handled groups per source marker."""
1054 dispatch = {
1055 '%%_PATCH_%_HEADER_%_TITLE_%%': weave_meta_part_header_title,
1056 '%%_PATCH_%_TITLE_%_SLUG_%%': weave_meta_part_title_slug,
1057 '%%_PATCH_%_MAIN_%_TITLE_%%': weave_meta_part_title,
1058 '%%_PATCH_%_SUB_%_TITLE_%%': weave_meta_part_sub_title,
1059 '%%_PATCH_%_TYPE_%%': weave_meta_part_header_type,
1060 '%%_PATCH_%_ID_%_LABEL_%%': weave_meta_part_header_id_label,
1061 '%%_PATCH_%_ID_%%': weave_meta_part_header_id,
1062 '%%_PATCH_%_ISSUE_%%': weave_meta_part_issue,
1063 '%%_PATCH_%_REVISION_%%': weave_meta_part_revision,
1064 '%%_PATCH_%_DATE_%_LABEL_%%': weave_meta_part_header_date_label,
1065 '%%_PATCH_%_DATE_%%': weave_meta_part_header_date,
1066 '%%_PATCH_%_FRAME_%_NOTE_%%': weave_meta_part_footer_frame_note,
1067 '%%_PATCH_%_FOOT_%_PAGE_%_COUNTER_%_LABEL_%%': weave_meta_part_footer_page_number_prefix,
1068 '%%_PATCH_%_CHANGELOG_%_ISSUE_%_LABEL_%%': weave_meta_part_change_log_issue_label,
1069 '%%_PATCH_%_CHANGELOG_%_REVISION_%_LABEL_%%': weave_meta_part_change_log_revision_label,
1070 '%%_PATCH_%_CHANGELOG_%_DATE_%_LABEL_%%': weave_meta_part_change_log_date_label,
1071 '%%_PATCH_%_CHANGELOG_%_AUTHOR_%_LABEL_%%': weave_meta_part_change_log_author_label,
1072 '%%_PATCH_%_CHANGELOG_%_DESCRIPTION_%_LABEL_%%': weave_meta_part_change_log_description_label,
1073 '%%_PATCH_%_APPROVALS_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%': weave_meta_part_approvals_adjustable_vertical_space,
1074 '%%_PATCH_%_BLURB_%_ADJUSTABLE_%_VERTICAL_%_SPACE_%%': weave_meta_part_proprietary_information_adjustable_vertical_space, # noqa
1075 '%%_PATCH_%_BLURB_%_TUNE_%_HEADER_%_SEP_%%': weave_meta_part_proprietary_information_tune_header_sep,
1076 '%%_PATCH_%_CHANGE_%_LOG_%_TUNE_%_HEADER_%_SEP_%%': weave_meta_part_change_log_tune_header_sep,
1077 '%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_LABEL_%%': weave_meta_part_approvals_department_label,
1078 '%%_PATCH_%_APPROVALS_%_DEPARTMENT_%_VALUE_%%': weave_meta_part_approvals_department_value,
1079 '%%_PATCH_%_APPROVALS_%_ROLE_%_LABEL_%%': weave_meta_part_approvals_role_label,
1080 '%%_PATCH_%_APPROVALS_%_NAME_%_LABEL_%%': weave_meta_part_approvals_name_label,
1081 '%%_PATCH_%_APPROVALS_%_DATE_%_AND_%_SIGNATURE_%_LABEL_%%': weave_meta_part_approvals_date_and_signature_label,
1082 '%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%_LABEL_%%': weave_meta_part_header_issue_revision_combined_label,
1083 '%%_PATCH_%_ISSUE_%_REVISION_%_COMBINED_%%': weave_meta_part_header_issue_revision_combined,
1084 '%%_PATCH_%_PROPRIETARY_%_INFORMATION_%_LABEL_%%': weave_meta_part_proprietary_information,
1085 }
1086 for trigger, weaver in dispatch.items():
1087 if text.rstrip().endswith(trigger):
1088 return weaver(mapper, text)
1089 return text
1092@no_type_check
1093def weave_meta_meta(meta_map: gat.Meta, latex: list[str]) -> list[str]:
1094 """TODO."""
1095 log.info('weaving in the meta data per metadata.tex.in into metadata.tex ...')
1096 completed = [dispatch_meta_weaver(meta_map['document']['common'], line) for line in latex]
1097 if completed and completed[-1]:
1098 completed.append('\n')
1099 return completed
1102@no_type_check
1103def weave(
1104 doc_root: Union[str, pathlib.Path], structure_name: str, target_key: str, facet_key: str, options: dict[str, bool]
1105) -> int:
1106 """Later alligator."""
1107 log.info(LOG_SEPARATOR)
1108 log.info('entered meta weave function ...')
1109 target_code = target_key
1110 facet_code = facet_key
1111 if not facet_code.strip() or not target_code.strip():
1112 log.error(f'meta requires non-empty target ({target_code}) and facet ({facet_code}) codes')
1113 return 2
1115 log.info(f'parsed target ({target_code}) and facet ({facet_code}) from request')
1117 structure, asset_map = gat.prelude(
1118 doc_root=doc_root, structure_name=structure_name, target_key=target_key, facet_key=facet_key, command='meta'
1119 )
1120 log.info(f'prelude teleported processor into the document root at ({os.getcwd()}/)')
1121 rel_concat_folder_path = pathlib.Path('render/pdf/')
1122 rel_concat_folder_path.mkdir(parents=True, exist_ok=True)
1123 os.chdir(rel_concat_folder_path)
1124 log.info(f'meta (this processor) teleported into the render/pdf location ({os.getcwd()}/)')
1126 ok, aspect_map = too.load_target(target_code, facet_code)
1127 if not ok or not aspect_map:
1128 return 0 if ok else 1
1130 metadata = process_meta(aspect_map)
1131 if isinstance(metadata, int):
1132 return 1
1134 metadata_template = tpl.load_resource(METADATA_TEMPLATE, METADATA_TEMPLATE_IS_EXTERNAL)
1135 lines = [line.rstrip() for line in metadata_template.split('\n')]
1136 lines = weave_meta_meta(metadata, lines)
1137 with open(METADATA_PATH, 'wt', encoding=ENCODING) as handle:
1138 handle.write('\n'.join(lines))
1140 driver_template = tpl.load_resource(DRIVER_TEMPLATE, DRIVER_TEMPLATE_IS_EXTERNAL)
1141 lines = [line.rstrip() for line in driver_template.split('\n')]
1142 lines = weave_meta_driver(metadata, lines)
1143 with open(DRIVER_PATH, 'wt', encoding=ENCODING) as handle:
1144 handle.write('\n'.join(lines))
1146 setup_template = tpl.load_resource(SETUP_TEMPLATE, SETUP_TEMPLATE_IS_EXTERNAL)
1147 lines = [line.rstrip() for line in setup_template.split('\n')]
1148 lines = weave_meta_setup(metadata, lines)
1149 with open(SETUP_PATH, 'wt', encoding=ENCODING) as handle:
1150 handle.write('\n'.join(lines))
1152 return 0