mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 11:18:26 +02:00
added Layer, AbstractLayer, IDLayer and RegexLayer for bmg patch operation (unimplemented)
This commit is contained in:
parent
f40f9212f1
commit
e403d1dce1
2 changed files with 60 additions and 4 deletions
|
@ -251,11 +251,61 @@ class PatchOperation:
|
||||||
|
|
||||||
def __init__(self, layers: list[dict]):
|
def __init__(self, layers: list[dict]):
|
||||||
"""
|
"""
|
||||||
:param layers: all the bmg patch to apply
|
:param layers: layers
|
||||||
"""
|
"""
|
||||||
self.layers = layers
|
self.layers = layers
|
||||||
|
|
||||||
def patch(self, patch: "Patch", file_name: str, file_content: IO) -> (str, IO):
|
def patch(self, patch: "Patch", file_name: str, file_content: IO) -> (str, IO):
|
||||||
print(file_content)
|
for layer in self.layers:
|
||||||
|
file_content = self.Layer(layer).patch_bmg(patch, file_content)
|
||||||
|
|
||||||
return file_name, file_content
|
return file_name, file_content
|
||||||
|
|
||||||
|
class Layer:
|
||||||
|
"""
|
||||||
|
represent a layer for a bmg-edit
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __new__(cls, layer: dict) -> "Layer":
|
||||||
|
"""
|
||||||
|
return the correct type of layer corresponding to the layer mode
|
||||||
|
:param layer: the layer to load
|
||||||
|
"""
|
||||||
|
for subclass in filter(lambda subclass: subclass.mode == layer["mode"],
|
||||||
|
cls.AbstractLayer.__subclasses__()):
|
||||||
|
layer.pop("mode")
|
||||||
|
return subclass(**layer)
|
||||||
|
raise InvalidBmgLayerMode(layer["mode"])
|
||||||
|
|
||||||
|
class AbstractLayer(ABC):
|
||||||
|
@abstractmethod
|
||||||
|
def patch_bmg(self, patch: "Patch", file_content: IO) -> IO:
|
||||||
|
"""
|
||||||
|
Patch a bmg with the actual layer. Return the new bmg content.
|
||||||
|
"""
|
||||||
|
|
||||||
|
class IDLayer(AbstractLayer):
|
||||||
|
"""
|
||||||
|
Represent a layer that replace bmg entry by their ID
|
||||||
|
"""
|
||||||
|
|
||||||
|
mode = "id"
|
||||||
|
|
||||||
|
def __init__(self, template: dict[str, str]):
|
||||||
|
self.template = template
|
||||||
|
|
||||||
|
def patch_bmg(self, patch: "Patch", file_content: IO) -> IO:
|
||||||
|
return file_content
|
||||||
|
|
||||||
|
class RegexLayer(AbstractLayer):
|
||||||
|
"""
|
||||||
|
Represent a layer that replace bmg entry by matching them with a regex
|
||||||
|
"""
|
||||||
|
|
||||||
|
mode = "regex"
|
||||||
|
|
||||||
|
def __init__(self, template: dict[str, str]):
|
||||||
|
self.template = template
|
||||||
|
|
||||||
|
def patch_bmg(self, patch: "Patch", file_content: IO) -> IO:
|
||||||
|
return file_content
|
||||||
|
|
|
@ -18,14 +18,20 @@ class InvalidPatchOperation(Exception):
|
||||||
|
|
||||||
class InvalidImageLayerType(Exception):
|
class InvalidImageLayerType(Exception):
|
||||||
def __init__(self, layer_type: str):
|
def __init__(self, layer_type: str):
|
||||||
super().__init__(f"Error : layer type \"{layer_type}\" is not implemented")
|
super().__init__(f"Error : image layer type \"{layer_type}\" is not implemented")
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidBmgLayerMode(Exception):
|
||||||
|
def __init__(self, layer_mode: str):
|
||||||
|
super().__init__(f"Error : bmg layer mode \"{layer_mode}\" is not implemented")
|
||||||
|
|
||||||
|
|
||||||
# TODO : implement BMG
|
# TODO : implement BMG
|
||||||
# TODO : recreate SZS
|
# TODO : recreate SZS
|
||||||
|
|
||||||
configuration_example = {
|
configuration_example = {
|
||||||
"operation": { # other operation for the file
|
"operation": { # other operation for the file
|
||||||
"bmg-replace": {
|
"bmg-edit": {
|
||||||
"mode": "regex", # regex or id
|
"mode": "regex", # regex or id
|
||||||
"template": {
|
"template": {
|
||||||
"CWF": "{{ ONLINE_SERVICE }}", # regex type expression
|
"CWF": "{{ ONLINE_SERVICE }}", # regex type expression
|
||||||
|
|
Loading…
Reference in a new issue