Skip to content

Commit

Permalink
Updates for the structure diff scripts: (#125)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
CyrilleB79 authored May 28, 2024
1 parent 0f6a96b commit 71f3932
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 11 additions & 5 deletions scripts/rebuildStats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

# Called by convertOne.sh, with current directory set to SRT_PATH/<lang>

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
16 changes: 14 additions & 2 deletions scripts/structDiffMd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}')
Expand Down Expand Up @@ -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)

0 comments on commit 71f3932

Please sign in to comment.