1
1
from __future__ import annotations
2
2
3
+ import os
3
4
from abc import ABC , abstractmethod
4
- from typing import TYPE_CHECKING , Optional , TypeVar , Union
5
+ from typing import TYPE_CHECKING , ClassVar , Optional , TypeVar , Union
5
6
6
7
from app .translator .core .exceptions .core import (
7
8
StrictPlatformException ,
16
17
17
18
18
19
DEFAULT_MAPPING_NAME = "default"
20
+ GLOBAL_ALTERNATIVE_MAPPING_DIR = "global_alternative"
19
21
20
22
21
23
class LogSourceSignature (ABC ):
@@ -113,14 +115,15 @@ class BasePlatformMappings:
113
115
is_strict_mapping : bool = False
114
116
skip_load_default_mappings : bool = True
115
117
extend_default_mapping_with_all_fields : bool = False
116
- global_mappings : list [str ] = []
118
+ global_alternative_mappings : ClassVar [ list [str ] ] = []
117
119
118
120
def __init__ (self , platform_dir : str , platform_details : PlatformDetails ):
119
121
self ._loader = LoaderFileMappings ()
120
122
self .details = platform_details
121
123
self ._source_mappings = self .prepare_mapping (platform_dir )
122
124
self ._alternative_mappings = self .prepare_alternative_mapping (platform_dir )
123
- global_alternative_mappings = self .prepare_global_alternative_mapping ()
125
+ if self .global_alternative_mappings :
126
+ self ._alternative_mappings .update (self .prepare_global_alternative_mapping ())
124
127
125
128
def update_default_source_mapping (self , default_mapping : SourceMapping , fields_mapping : FieldsMapping ) -> None :
126
129
default_mapping .fields_mapping .update (fields_mapping )
@@ -132,8 +135,10 @@ def prepare_alternative_mapping(self, platform_dir: str) -> dict[str, dict[str,
132
135
return alternative_mappings
133
136
134
137
def prepare_global_alternative_mapping (self ) -> dict [str , dict [str , SourceMapping ]]:
135
- globa_alternative_mappings = {}
136
- return globa_alternative_mappings
138
+ global_alternative_mappings = {}
139
+ for name in self .global_alternative_mappings :
140
+ global_alternative_mappings [name ] = self .prepare_mapping (os .path .join (GLOBAL_ALTERNATIVE_MAPPING_DIR , name ))
141
+ return global_alternative_mappings
137
142
138
143
def prepare_mapping (self , platform_dir : str ) -> dict [str , SourceMapping ]:
139
144
source_mappings = {}
0 commit comments