4 # WARNING: this script can't find files included in a different directory
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'
23 if x
[0] == '-o': # -o NAME set PO output file name to NAME
25 elif x
[0] == '-d': # -d DIR set working directory to DIR
27 elif x
[0] == '-b': # -b BLURB set blurb written at each node to BLURB
29 elif x
[0] == '-i': # -i BLURB set blurb written at beginning of each file to BLURB
32 def process_texi (texifilename
, i_blurb
, n_blurb
, write_skeleton
, output_file
=None):
34 #print "Processing %s..." % texifilename
35 f
= open (texifilename
, 'r')
40 g
= open (os
.path
.basename (texifilename
), 'w')
42 tutu
= re
.findall (r
"""^(\*) +([^:
44 ]*?$|^@(include|menu|end menu|node|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|(?:major|chap|(?:sub){0,2})heading) *([^@
46 ]*?$""", texifile
, re
.M
)
50 g
.write ('* ' + item
[1] + '::\n')
52 g
.write ('@' + item
[2] + ' ' + item
[3] + '\n')
56 if not item
[2] in ('include', 'menu', 'end menu'):
58 output_file
.write ('_("' + item
[3].strip () + '")\n')
60 elif item
[2] == 'include':
61 includes
.append(item
[3])
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) *([^@
66 ]*?$""", texifile
, re
.M
)
68 if item
[0] == 'include':
69 includes
.append(item
[1])
71 output_file
.write ('_("' + item
[1].strip () + '")\n')
73 dir = os
.path
.dirname (texifilename
)
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
)
83 node_blurb
= '\n' + node_blurb
+ '\n\n'
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')
92 os
.system ('xgettext -L Python --no-location -o ' + output_file
+ ' ' + node_list_filename
)
94 for texi_file
in texi_files
:
95 process_texi (texi_file
, intro_blurb
, node_blurb
, make_skeleton
)