From 71f3932c1ca55fe097c7eb8507affdda08562818 Mon Sep 17 00:00:00 2001 From: Cyrille Bougot Date: Wed, 29 May 2024 00:41:12 +0200 Subject: [PATCH] Updates for the structure diff scripts: (#125) - now also checks the diffs of the change log - indicate the files being compared in the report - fixed a bug where no diff could be detected for files of unequal length --- scripts/rebuildStats.sh | 16 +++++++++++----- scripts/structDiffMd.py | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/scripts/rebuildStats.sh b/scripts/rebuildStats.sh index c895cdd..b71b379 100755 --- a/scripts/rebuildStats.sh +++ b/scripts/rebuildStats.sh @@ -2,13 +2,19 @@ # Called by convertOne.sh, with current directory set to SRT_PATH/ -nextRev=`ls -1 userGuide-newRevisions/ | head -n 1` +scriptsDir="../../scripts" +lang=$(basename `pwd`) + +nextRev=`ls -1 changes-newRevisions/ | head -n 1` if [ "$nextRev" == "" ]; then - echo "No revision found, unable to calculate structure difference." + echo "No revision found, unable to calculate changes structure difference." exit fi +python3 ${scriptsDir}/structDiffMd.py $lang changes-newRevisions/$nextRev/changes.md changes.md changes-structureDifferences.txt -scriptsDir="../../scripts" -lang=$(basename `pwd`) - +nextRev=`ls -1 userGuide-newRevisions/ | head -n 1` +if [ "$nextRev" == "" ]; then + echo "No revision found, unable to calculate userGuide structure difference." + exit +fi python3 ${scriptsDir}/structDiffMd.py $lang userGuide-newRevisions/$nextRev/userGuide.md userGuide.md userGuide-structureDifferences.txt diff --git a/scripts/structDiffMd.py b/scripts/structDiffMd.py index 80b15e9..ae914b3 100644 --- a/scripts/structDiffMd.py +++ b/scripts/structDiffMd.py @@ -11,6 +11,7 @@ import sys import os import re +from itertools import zip_longest # Set to True to check blank at end of line. It is currently disabled due to the high number of diffs in # the change log (French) @@ -22,7 +23,12 @@ def structDiff(enFile, localeFile): output = [] with open(enFile, encoding="utf8") as f1, open(localeFile, encoding="utf8") as f2: - for (nLine, (enLine, locLine)) in enumerate(zip(f1, f2)): + for (nLine, (enLine, locLine)) in enumerate(zip_longest(f1, f2)): + if enLine is None or locLine is None: + output.append(f'Line {nLine+1}: One of the files is shortest') + output.append(f'English = {repr(enLine)}') + output.append(f'Locale = {repr(locLine)}') # Double space for vertical alignment between both lines. + continue err = compareLines(enLine, locLine) if err is not None: output.append(f'Line {nLine+1}: {err}') @@ -138,4 +144,10 @@ def compareLineContents(l1, l2): else: print("No differences found") output = "No differences found" - open(outFile, 'w', encoding='utf-8').write(output) + compaInfo = f"Comparing {locale} {baseName} against English:\n" + compaInfo += f"English file: {enFile}\n" + compaInfo += f"Local file: {transFile}\n" + compaInfo += "\n" + with open(outFile, 'w', encoding='utf-8') as f: + f.write(compaInfo) + f.write(output)