Commit 630a91b7 authored by Andrey Filippov's avatar Andrey Filippov

CLAUDE: migrate_curt_config.py - add provenance comment to migrated files

Per Andrey: insert an XML comment right after <properties> in every modified
file with the absolute path of the script that did the migration + timestamp
(absolute path intentional; adjust per machine). Java loadFromXML ignores XML
comments (verified with a real load: 4153 entries) but drops them on re-save.

Applied to the live config LV396-v013-...-POSEJP4-ENMB.corr-xml: 87 keys
renamed, .bak kept, Java load verified.
Co-Authored-By: 's avatarClaude Fable 5 <noreply@anthropic.com>
parent 7a793de1
......@@ -21,9 +21,16 @@ Only the literal substring '_imp_curt_' inside key="..." attributes is renamed t
'_curt_'; everything else (values, formatting, comments) is byte-preserved. If a
file already contains a _curt_ key that a rename would duplicate, the old key is
dropped (the new one wins) and a warning is printed.
A provenance XML comment (absolute path of this script + timestamp) is inserted
right after the <properties> line of every modified file. Java's XML properties
loader ignores XML comments, but note it also DROPS them if the application
re-saves the file - the marker survives only until the next save from ImageJ.
"""
import argparse
import datetime
import os
import re
import shutil
import sys
......@@ -51,6 +58,19 @@ def migrate_text(text):
return ''.join(out_lines), renamed[0], dropped
def add_provenance_comment(text):
"""Insert a provenance XML comment after the <properties> line."""
stamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
marker = ('<!-- curt_* keys migrated (_imp_curt_* to _curt_*) by %s on %s -->\n'
% (os.path.abspath(__file__), stamp))
lines = text.splitlines(keepends=True)
for i, line in enumerate(lines):
if '<properties>' in line:
lines.insert(i + 1, marker)
return ''.join(lines)
return marker + text # no <properties> line found - prepend (still valid for grep)
def main():
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument('files', nargs='+', help='corr-xml files to migrate')
......@@ -80,7 +100,7 @@ def main():
if not args.no_backup:
shutil.copy2(path, path + '.bak')
with open(path, 'w', encoding='utf-8') as f:
f.write(new_text)
f.write(add_provenance_comment(new_text))
print(f"{path}: renamed {n} key(s)" +
(f", dropped {len(dropped)} duplicate legacy entrie(s)" if dropped else "") +
("" if args.no_backup else f" (backup: {path}.bak)"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment