mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-05 20:28:27 +02:00
patch_data have been renamed cat_data and can both patch and filters a bmg file
This commit is contained in:
parent
a078a4848b
commit
1d88f89f3d
2 changed files with 29 additions and 6 deletions
|
@ -0,0 +1,18 @@
|
||||||
|
from source.mkw.Patch.PatchOperation.Operation.BmgTxtEditor.Layer import *
|
||||||
|
from source.wt import bmg
|
||||||
|
|
||||||
|
Patch: any
|
||||||
|
|
||||||
|
|
||||||
|
class PatchLayer(AbstractLayer):
|
||||||
|
"""
|
||||||
|
Represent a layer that patch a bmg
|
||||||
|
"""
|
||||||
|
|
||||||
|
mode = "patch"
|
||||||
|
|
||||||
|
def __init__(self, patchs: dict[str, str | None]):
|
||||||
|
self.patchs = patchs
|
||||||
|
|
||||||
|
def patch_bmg(self, patch: "Patch", decoded_content: str) -> str:
|
||||||
|
return bmg.cat_data(decoded_content, patchs=self.patchs)
|
|
@ -31,22 +31,27 @@ def encode_data(txt_data: str) -> bytes:
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
|
|
||||||
def patch_data(bmg_data: bytes, patchs: dict[str, str | None]) -> bytes:
|
def cat_data(txt_data: str, patchs: dict[str, str | None] = None, filters: dict[str, str | None] = None) -> str:
|
||||||
"""
|
"""
|
||||||
Patch a file with LE-COPY. This copy the original tracks name into the new lecode track name id
|
Patch and filter a bmgtxt file (for example LE-COPY).
|
||||||
:patchs: dictionary of patchs bmg key and value
|
:patchs: dictionary of patchs bmg key and value
|
||||||
"""
|
"""
|
||||||
args = []
|
args = []
|
||||||
for key, value in patchs.items():
|
|
||||||
|
for key, value in filters.items() if filters is not None else {}:
|
||||||
|
args.append("--filter-bmg")
|
||||||
|
args.append(key if value is None else f"{key}={value}")
|
||||||
|
|
||||||
|
for key, value in patchs.items() if patchs is not None else {}:
|
||||||
args.append("--patch-bmg")
|
args.append("--patch-bmg")
|
||||||
args.append(key if value is None else f"{key}={value}")
|
args.append(key if value is None else f"{key}={value}")
|
||||||
|
|
||||||
process = _tools_run_popen("PATCH", "-", *args, "--DEST", "-")
|
process = _tools_run_popen("CAT", "-", *args)
|
||||||
stdout, _ = process.communicate(input=bmg_data)
|
stdout, _ = process.communicate(input=txt_data.encode("utf-8"))
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
raise WTError(tools_path, process.returncode)
|
raise WTError(tools_path, process.returncode)
|
||||||
|
|
||||||
return stdout
|
return stdout.decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
class BMGPath:
|
class BMGPath:
|
||||||
|
|
Loading…
Reference in a new issue