#!/usr/bin/env python # update-snippets.py # # This file is part of LilyPond, the GNU music typesetter. # # Copyright (C) 2007--2020 John Mandereau > # # LilyPond is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # LilyPond is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with LilyPond. If not, see . # USAGE: update-snippets.py REFERENCE-DIR TARGET-DIR FILES # # update ly snippets in TARGET-DIR/FILES with snippets from REFERENCE-DIR/FILES # # More precisely, each existing FILE in TARGET-DIR is matched to the FILE in # REFERENCE-DIR (it the latter does not exist, a warning is given). # # Shell wildcards expansion is performed on FILES. # This script currently supports Texinfo format. # Ly snippets preceded with a line containing '@c KEEP LY' in TARGET-DIR/FILES # will not be updated. # An error occurs if REFERENCE-DIR/FILE and TARGET-DIR/FILE do not have the # same snippets count. import sys import os import glob import re from functools import reduce print("update-snippets.py") comment_re = re.compile( r'(? 0 and (not target_source[j-1].startswith('@c KEEP LY')) and target_source[j] != ref_source[k]: target_source[j] = ref_source[k] c += 1 changed_snippets_count += 1 f = open(file, 'w', encoding='utf8') f.write(''.join(target_source)) sys.stderr.write('%s: %d/%d snippets updated\n' % (file, c, snippet_count)) sys.stderr.write('\nTotal: %d snippets, %d updated snippets.\n' % (total_snippet_count, changed_snippets_count)) sys.exit(exit_code)