4 '''USAGE: makesnippets.py INPUT_DIR OUTPUT_DIR DOC_DIR
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.'''
16 (input_dir, output_dir, doc_dir) = sys.argv[1:4]
18 texidoc_dirs = [os.path.join (doc_dir, language_code, 'texidocs')
19 for language_code in langdefs.LANGDICT]
21 begin_header_re = re.compile (r'\\header\s*{', re.M)
23 for f in glob.glob (os.path.join (input_dir, '*.ly')):
24 name = os.path.basename (f)
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)