39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
"""Preserve imported or manually placed Camelot end caps during the default bottom-row fit."""
|
|
import argparse
|
|
from hashlib import sha256
|
|
from pathlib import Path
|
|
|
|
FDID = 7475645
|
|
PARENT_SHA256 = 'c2dff61845e65a96601b770c6028579d0caa2277162fb381fc570f9ce85d291f'
|
|
|
|
|
|
def compose(parent):
|
|
if sha256(parent).hexdigest() != PARENT_SHA256:
|
|
raise ValueError(f"Unexpected 70334 parent for FDID {FDID}")
|
|
newline = '\r\n' if b'\r\n' in parent else '\n'
|
|
lines = parent.decode().splitlines(keepends=True)
|
|
start = lines.index('\tif not octoCapY then' + newline)
|
|
last = next(i for i, line in enumerate(lines) if line.startswith('\tright:SetPoint("BOTTOMLEFT", bags,'))
|
|
# Both caps provide the geometry of the default gap. Do not learn the
|
|
# baseline from a custom layout, or move an individually positioned cap.
|
|
lines[start:last + 1] = [
|
|
'\tlocal fitCaps = left:IsInDefaultPosition() and right:IsInDefaultPosition();' + newline,
|
|
'\tif fitCaps then' + newline,
|
|
*['\t' + line for line in lines[start:last + 1]],
|
|
'\tend' + newline,
|
|
]
|
|
old = '\tOctoFitTopBars(bar, s, left, right);' + newline
|
|
lines[lines.index(old)] = '\tOctoFitTopBars(bar, s, fitCaps and left, fitCaps and right);' + newline
|
|
return ''.join(lines).encode()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('released_util', type=Path)
|
|
parser.add_argument('output', type=Path)
|
|
args = parser.parse_args()
|
|
candidate = compose(args.released_util.read_bytes())
|
|
with args.output.open('xb') as out:
|
|
out.write(candidate)
|
|
print(sha256(candidate).hexdigest())
|