]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/makesnippets.py
Add '-dcrop' option to ps and svg backends
[lilypond.git] / scripts / build / makesnippets.py
1 #!@PYTHON@
2 # makesnippets.py
3
4 '''USAGE: makesnippets.py INPUT_DIR OUTPUT_DIR DOC_DIR
5
6 Read all .ly files from INPUT_DIR, insert translations from .texidoc
7 files found in DOC_DIR/LANG/texdiocs, and write ther result to OUTPUT_DIR.'''
8
9 import glob
10 import sys
11 import os.path
12 import re
13
14 import langdefs
15
16 (input_dir, output_dir, doc_dir) = sys.argv[1:4]
17
18 texidoc_dirs = [os.path.join (doc_dir, language_code, 'texidocs')
19                 for language_code in langdefs.LANGDICT]
20
21 begin_header_re = re.compile (r'\\header\s*{', re.M)
22
23 for f in glob.glob (os.path.join (input_dir, '*.ly')):
24     name = os.path.basename (f)
25     s = open (f).read ()
26     for path in texidoc_dirs:
27         texidoc_translation_path = \
28             os.path.join (path, os.path.splitext (name)[0] + '.texidoc')
29         if os.path.exists (texidoc_translation_path):
30             texidoc_translation = open (texidoc_translation_path).read ()
31             # Since we want to insert the translations verbatim using a
32             # regexp, \\ is understood as ONE escaped backslash. So we have
33             # to escape those backslashes once more...
34             texidoc_translation = texidoc_translation.replace ('\\', '\\\\')
35             s = begin_header_re.sub ('\\g<0>\n' + texidoc_translation, s, 1)
36     dest = os.path.join (output_dir, name)
37     open (dest, 'w').write (s)