New glyph (black diamond) and two harmonic-like notehead styles using it.
[lilypond.git] / buildscripts / texi-langutils.py
blob62c87619ddadf9f8a030057fe15db80c4f6a980f
1 #!@PYTHON@
2 # texi-langutils.py
4 # WARNING: this script can't find files included in a different directory
6 import sys
7 import re
8 import getopt
9 import os
10 import string
12 optlist, texi_files = getopt.getopt(sys.argv[1:],'no:d:b:i:',['skeleton', 'gettext'])
13 process_includes = not ('-n', '') in optlist # -n don't process @include's in texinfo files
15 make_gettext = ('--gettext', '') in optlist # --gettext generate a node list from a Texinfo source
16 make_skeleton = ('--skeleton', '') in optlist # --skeleton extract the node tree from a Texinfo source
18 output_file = 'doc.pot'
19 node_blurb = ''
20 intro_blurb = ''
22 for x in optlist:
23 if x[0] == '-o': # -o NAME set PO output file name to NAME
24 output_file = x[1]
25 elif x[0] == '-d': # -d DIR set working directory to DIR
26 os.chdir (x[1])
27 elif x[0] == '-b': # -b BLURB set blurb written at each node to BLURB
28 node_blurb = x[1]
29 elif x[0] == '-i': # -i BLURB set blurb written at beginning of each file to BLURB
30 intro_blurb = x[1]
32 def process_texi (texifilename, i_blurb, n_blurb, write_skeleton, output_file=None):
33 try:
34 #print "Processing %s..." % texifilename
35 f = open (texifilename, 'r')
36 texifile = f.read ()
37 f.close ()
38 includes = []
39 if write_skeleton:
40 g = open (os.path.basename (texifilename), 'w')
41 g.write (i_blurb)
42 tutu = re.findall (r"""^(\*) +([^:
43 ]+)::[^
44 ]*?$|^@(include|menu|end menu|node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) *([^@
45 ]*)[^
46 ]*?$""", texifile, re.M)
47 node_trigger = False
48 for item in tutu:
49 if item[0] == '*':
50 g.write ('* ' + item[1] + '::\n')
51 else:
52 g.write ('@' + item[2] + ' ' + item[3] + '\n')
53 if node_trigger:
54 g.write (n_blurb)
55 node_trigger = False
56 if not item[2] in ('include', 'menu', 'end menu'):
57 if output_file:
58 output_file.write ('_("' + item[3].strip () + '")\n')
59 node_trigger = True
60 elif item[2] == 'include':
61 includes.append(item[3])
62 g.close ()
63 elif output_file:
64 toto = re.findall (r"""^@(include|node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) *([^@
65 ]*)[^
66 ]*?$""", texifile, re.M)
67 for item in toto:
68 if item[0] == 'include':
69 includes.append(item[1])
70 else:
71 output_file.write ('_("' + item[1].strip () + '")\n')
72 if process_includes:
73 dir = os.path.dirname (texifilename)
74 for item in includes:
75 process_texi (os.path.join (dir, item.strip ()), i_blurb, n_blurb, write_skeleton, output_file)
76 except IOError, (errno, strerror):
77 print "I/O error(%s): %s: %s" % (errno, texifilename, strerror)
80 if intro_blurb != '':
81 intro_blurb += '\n\n'
82 if node_blurb != '':
83 node_blurb = '\n' + node_blurb + '\n\n'
84 if make_gettext:
85 node_list_filename = 'node_list'
86 node_list = open (node_list_filename, 'w')
87 for texi_file in texi_files:
88 process_texi (texi_file, intro_blurb, node_blurb, make_skeleton, node_list)
89 for word in ('Up:', 'Next:', 'Previous:', 'Appendix', 'Footnotes'):
90 node_list.write ('_("' + word + '")\n')
91 node_list.close ()
92 os.system ('xgettext -L Python --no-location -o ' + output_file + ' ' + node_list_filename)
93 else:
94 for texi_file in texi_files:
95 process_texi (texi_file, intro_blurb, node_blurb, make_skeleton)