]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/translations-status.py
translations-status.py: Move <tr></tr> into single function bodies.
[lilypond.git] / scripts / auxiliar / translations-status.py
1 #!/usr/bin/env python
2
3 '''
4 USAGE: cd Documentation && translations-status.py
5
6   Write:
7     translations.itexi
8     <LANG>/translations.itexi
9     out/translations-status.txt
10
11   Update word counts in:
12     contributor/doc-translation-list.itexi
13 '''
14
15 import sys
16 import re
17 import string
18 import operator
19 import os
20 #
21 import langdefs
22 import buildlib
23
24 def progress (str):
25     sys.stderr.write (str + '\n')
26
27 exit_code = 0
28
29 def error (str, update_status=1):
30     global exit_code
31     sys.stderr.write ('translations-status.py: %s\n' % str)
32     exit_code = max (exit_code, update_status)
33
34 progress ("translations-status.py")
35
36 _doc = lambda s: s
37
38 # load gettext messages catalogs
39 translation = langdefs.translation
40
41
42 language_re = re.compile (r'^@documentlanguage (.+)', re.M)
43 comments_re = re.compile (r'^@ignore\n(.|\n)*?\n@end ignore$|@c .*?$', re.M)
44 space_re = re.compile (r'\s+', re.M)
45 lilypond_re = re.compile (r'@lilypond({.*?}|(.|\n)*?\n@end lilypond$)', re.M)
46 node_re = re.compile ('^@node .*?$', re.M)
47 title_re = re.compile ('^@(settitle|chapter|top|(?:sub){0,2}section|'
48                            '(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?) (.*?)$', re.M)
49 include_re = re.compile ('^@include (.*?)$', re.M)
50
51 # allow multiple lines
52 translators_re = re.compile (r'^@c[ ]+[Tt]ranslators?[ ]*:[ ]*(.*?)$', re.M)
53 checkers_re = re.compile (r'^@c[ ]+[Tt]ranslation[ ]*[Cc]heckers?[ ]*:[ ]*(.*?)$', re.M)
54 status_re = re.compile (r'^@c[ ]+[Tt]ranslation[ ]*[Ss]tatus[ ]*:[ ]*(.*?)$', re.M)
55 post_gdp_re = re.compile ('post.GDP', re.I)
56 untranslated_node_str = '@untranslated'
57 skeleton_str = '-- SKELETON FILE --'
58
59 section_titles_string = _doc ('Section titles')
60 last_updated_string = _doc (' <p><i>Last updated %s</i></p>\n')
61 detailed_status_heads = [_doc ('Translators'), _doc ('Translation checkers'),
62                          _doc ('Translated'), _doc ('Up to date'),
63                          _doc ('Other info')]
64 format_table = {
65     'not translated': {'color':'d0f0f8', 'short':_doc ('no'), 'abbr':'NT',
66                        'long':_doc ('not translated')},
67     'partially translated': {'color':'dfef77',
68                              'short':_doc ('partially (%(p)d %%)'),
69                              'abbr':'%(p)d%%',
70                              'long':_doc ('partially translated (%(p)d %%)')},
71     'fully translated': {'color':'1fff1f', 'short':_doc ('yes'), 'abbr':'FT',
72                          'long': _doc ('translated')},
73     'up to date': {'short':_doc ('yes'), 'long':_doc ('up to date'),
74                    'abbr':'100%%', 'vague':_doc ('up to date')},
75     'outdated': {'short':_doc ('partially'), 'abbr':'%(p)d%%',
76                  'vague':_doc ('partially up to date')},
77     'N/A': {'short':_doc ('N/A'), 'abbr':'N/A', 'color':'d587ff', 'vague':''},
78     'pre-GDP':_doc ('pre-GDP'),
79     'post-GDP':_doc ('post-GDP')
80 }
81
82 texi_level = {
83 # (Unumbered/Numbered/Lettered, level)
84     'top': ('u', 0),
85     'unnumbered': ('u', 1),
86     'unnumberedsec': ('u', 2),
87     'unnumberedsubsec': ('u', 3),
88     'chapter': ('n', 1),
89     'section': ('n', 2),
90     'subsection': ('n', 3),
91     'appendix': ('l', 1),
92     'appendixsec': ('l', 2),
93 }
94
95 appendix_number_trans = string.maketrans ('@ABCDEFGHIJKLMNOPQRSTUVWXY',
96                                           'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
97
98 class SectionNumber (object):
99     def __init__ (self):
100         self.__data = [[0,'u']]
101
102     def __increase_last_index (self):
103         type = self.__data[-1][1]
104         if type == 'l':
105             self.__data[-1][0] = \
106                 self.__data[-1][0].translate (appendix_number_trans)
107         elif type == 'n':
108             self.__data[-1][0] += 1
109
110     def format (self):
111         if self.__data[-1][1] == 'u':
112             return ''
113         return '.'.join ([str (i[0]) for i in self.__data if i[1] != 'u']) + ' '
114
115     def increase (self, (type, level)):
116         if level == 0:
117             self.__data = [[0,'u']]
118         while level + 1 < len (self.__data):
119             del self.__data[-1]
120         if level + 1 > len (self.__data):
121             self.__data.append ([0, type])
122             if type == 'l':
123                 self.__data[-1][0] = '@'
124         if type == self.__data[-1][1]:
125             self.__increase_last_index ()
126         else:
127             self.__data[-1] = ([0, type])
128             if type == 'l':
129                 self.__data[-1][0] = 'A'
130             elif type == 'n':
131                 self.__data[-1][0] = 1
132         return self.format ()
133
134
135 def percentage_color (percent):
136     p = percent / 100.0
137     if p < 0.33:
138         c = [hex (int (3 * p * b + (1 - 3 * p) * a))[2:]
139              for (a, b) in [(0xff, 0xff), (0x5c, 0xa6), (0x5c, 0x4c)]]
140     elif p < 0.67:
141         c = [hex (int ((3 * p - 1) * b + (2 - 3 * p) * a))[2:]
142              for (a, b) in [(0xff, 0xff), (0xa6, 0xff), (0x4c, 0x3d)]]
143     else:
144         c = [hex (int ((3 * p - 2) * b + 3 * (1 - p) * a))[2:]
145              for (a, b) in [(0xff, 0x1f), (0xff, 0xff), (0x3d, 0x1f)]]
146     return ''.join (c)
147
148
149 def update_word_count (text, filename, word_count):
150     return re.sub (r'(?m)^(\d+) *' + filename,
151                    str (word_count).ljust (6) + filename,
152                    text)
153
154 po_msgid_re = re.compile (r'^msgid "(.*?)"(?:\n"(.*?)")*', re.M)
155
156 def po_word_count (po_content):
157     s = ' '.join ([''.join (t) for t in po_msgid_re.findall (po_content)])
158     return len (space_re.split (s))
159
160 sgml_tag_re = re.compile (r'<.*?>', re.S)
161
162 def sgml_word_count (sgml_doc):
163     s = sgml_tag_re.sub ('', sgml_doc)
164     return len (space_re.split (s))
165
166 def tely_word_count (tely_doc):
167     '''
168     Calculate word count of a Texinfo document node by node.
169
170     Take string tely_doc as an argument.
171     Return a list of integers.
172
173     Texinfo comments and @lilypond blocks are not included in word counts.
174     '''
175     tely_doc = comments_re.sub ('', tely_doc)
176     tely_doc = lilypond_re.sub ('', tely_doc)
177     nodes = node_re.split (tely_doc)
178     return [len (space_re.split (n)) for n in nodes]
179
180 class HTMLMarkup (object):
181     def entity (self, name, string='', attributes=[]):
182         attr_list = ''.join ([' %s="%s"' % x for x in attributes])
183         return '<%(name)s%(attr_list)s>%(string)s</%(name)s>' % locals ()
184     def paragraph (self, string=''):
185         return self.entity ('p')
186     def table (self, string):
187         return self.entity ('table', string, [('align', 'center'), ('border', '2')])
188     def row (self, string, attributes=[]):
189         return self.entity ('tr', string, attributes)
190     headrow = row
191     def cellhead (self, string, attributes=[]):
192         return self.entity ('th', string, attributes)
193     def cell (self, string, attributes=[]):
194         return self.entity ('td', string, attributes)
195     def newline (self, attributes=[]):
196         return self.entity ('br', '', attributes)[:-5]
197     def span (self, string, attributes=[]):
198         return self.entity ('span', string, attributes)
199     def small (self, string, attributes=[]):
200         return self.entity ('small', string, attributes)
201
202 class TexiMarkup (HTMLMarkup):
203     def entity (self, name, string='', attributes=[]):
204         return '''
205 @%(name)s
206 %(string)s
207 @end %(name)s
208 ''' % locals ()
209     def paragraph (self, string=''):
210         return '''
211 %(string)s''' % locals ()
212     def table (self, string):
213         return self.entity ('multitable', string)
214     def headrow (self, string, attributes=[]):
215         return '''
216 @headitem ''' + string
217     def row (self, string, attributes=[]):
218         return '''
219 @item ''' + string
220     def cell (self, string, attributes=[]):
221         return '''
222 @tab ''' + string
223     headcell = cell
224     def newline (self):
225         return '''
226 @* '''
227     def html (self, string):
228         return self.entity ('ifhtml', self.entity ('html', string))
229     def span (self, string, attributes=[]):
230         return self.html (HTMLMarkup.span (self, string, attributes))
231     def small (self, string, attributes=[]):
232         return self.html (HTMLMarkup.small (self, string, attributes))
233
234 class TelyDocument (object):
235     def __init__ (self, filename):
236         self.filename = filename
237         self.contents = 'GIT committish: 0'
238         if os.path.exists (filename):
239             self.contents = open (filename).read ()
240         ## record title and sectionning level of first Texinfo section
241         self.sectioning = 'unnumbered'
242         self.title = 'Untitled'
243         m = title_re.search (self.contents)
244         if m:
245             self.sectioning = m.group (1)
246             self.title = m.group (2)
247
248         if not hasattr (self, 'language'):
249             self.language = ''
250         m = language_re.search (self.contents)
251         if m:
252             self.language = m.group (1)
253
254         dir = os.path.dirname (filename).split ('/')[0]
255         if len (dir) == 2:
256             dir += '/'
257         else:
258             dir = ''
259         included_files = [dir + t
260                           for t in include_re.findall (self.contents)]
261         self.included_files = [p for p in included_files if os.path.exists (p)]
262
263     def get_level (self):
264         return texi_level [self.sectioning]
265
266     def print_title (self, section_number):
267         if not hasattr (self, 'level'):
268             self.level = self.get_level ()
269         return section_number.increase (self.level) + self.title
270
271
272 class TranslatedTelyDocument (TelyDocument):
273     def __init__ (self, filename, masterdocument, parent_translation=None):
274         TelyDocument.__init__ (self, filename)
275         self.masterdocument = masterdocument
276         if not hasattr (self, 'language'):
277             self.language = ''
278         if not self.language and parent_translation:
279             self.language = parent_translation.__dict__.get ('language', '')
280         if self.language == 'en':
281             print filename + ': language en specified: set @documentlanguage', self.filename[:2]
282             self.language = ''
283         if not self.language and filename[2] == '/':
284             print filename + ': no language specified: add @documentlanguage', self.filename[:2]
285             self.language = filename[:2]
286         if self.language:
287             self.translation = translation[self.language]
288         else:
289             self.translation = lambda x: x
290         self.title = self.translation (self.title)
291
292         ## record authoring information
293         self.translators = ['']
294         if parent_translation:
295             self.translators = parent_translation.__dict__.get ('translators', [''])
296         m = translators_re.findall (self.contents)
297         if m:
298             self.translators = [n.strip () for n in
299                                 reduce (operator.add, [n.split (',') for n in m])]
300         if self.language != self.filename[:2]:
301             print 'Barf:', self.filename
302             barf
303         if (not isinstance (self, UntranslatedTelyDocument)
304             and (not self.translators or not self.translators[0])
305             and not 'macros.itexi' in self.filename):
306             error (self.filename + ''': error: no translator name found
307 please specify one ore more lines in the master file
308 @c Translator: FirstName LastName[, FirstName LastName]..''')
309         self.checkers = []
310         m = checkers_re.findall (self.contents)
311         if m:
312             self.checkers = [n.strip () for n in
313                              reduce (operator.add, [n.split (',') for n in m])]
314         if not self.checkers and isinstance (parent_translation, TranslatedTelyDocument):
315             self.checkers = parent_translation.checkers
316
317         ## check whether translation is pre- or post-GDP
318         m = status_re.search (self.contents)
319         if m:
320             self.post_gdp = bool (post_gdp_re.search (m.group (1)))
321         else:
322             self.post_gdp = False
323
324         ## record which parts (nodes) of the file are actually translated
325         self.partially_translated = not skeleton_str in self.contents
326         nodes = node_re.split (self.contents)
327         self.translated_nodes = [not untranslated_node_str in n for n in nodes]
328
329         ## calculate translation percentage
330         master_total_word_count = sum (masterdocument.word_count)
331         translation_word_count = \
332             sum ([masterdocument.word_count[k] * self.translated_nodes[k]
333                   for k in range (min (len (masterdocument.word_count),
334                                        len (self.translated_nodes)))])
335         self.translation_percentage = \
336             100 * translation_word_count / master_total_word_count
337
338         ## calculate how much the file is outdated
339         (diff_string, git_error) = \
340             buildlib.check_translated_doc (masterdocument.filename, self.filename, self.contents)
341         if git_error:
342             sys.stderr.write ('warning: %s: %s' % (self.filename, git_error))
343             self.uptodate_percentage = None
344         else:
345             diff = diff_string.splitlines ()
346             insertions = sum ([len (l) - 1 for l in diff
347                                if l.startswith ('+')
348                                and not l.startswith ('+++')])
349             deletions = sum ([len (l) - 1 for l in diff
350                               if l.startswith ('-')
351                               and not l.startswith ('---')])
352             outdateness_percentage = 50.0 * (deletions + insertions) / \
353                 (masterdocument.size + 0.5 * (deletions - insertions))
354             self.uptodate_percentage = 100 - int (outdateness_percentage)
355             if self.uptodate_percentage > 100:
356                 alternative = 50
357                 progress ("%s: strange uptodateness percentage %d %%, \
358 setting to %d %%" % (self.filename, self.uptodate_percentage, alternative))
359                 self.uptodate_percentage = alternative
360             elif self.uptodate_percentage < 1:
361                 alternative = 1
362                 progress ("%s: strange uptodateness percentage %d %%, \
363 setting to %d %%" % (self.filename, self.uptodate_percentage, alternative))
364                 self.uptodate_percentage = alternative
365
366     def get_level (self):
367         return texi_level ['top']
368
369     def completeness (self, formats=['long'], translated=False):
370         if translated:
371             translation = self.translation
372         else:
373             translation = lambda x: x
374
375         if isinstance (formats, str):
376             formats = [formats]
377         p = self.translation_percentage
378         if p == 0:
379             status = 'not translated'
380         elif p == 100:
381             status = 'fully translated'
382         else:
383             status = 'partially translated'
384         return dict ([(f, translation (format_table[status][f]) % locals())
385                       for f in formats])
386
387     def uptodateness (self, formats=['long'], translated=False):
388         if translated:
389             translation = self.translation
390         else:
391             translation = lambda x: x
392
393         if isinstance (formats, str):
394             formats = [formats]
395         p = self.uptodate_percentage
396         if p == None:
397             status = 'N/A'
398         elif p == 100:
399             status = 'up to date'
400         else:
401             status = 'outdated'
402         l = {}
403         for f in formats:
404             if f == 'color' and p != None:
405                 l['color'] = percentage_color (p)
406             else:
407                 l[f] = translation (format_table[status][f]) % locals ()
408         return l
409
410     def gdp_status (self):
411         if self.post_gdp:
412             return self.translation (format_table['post-GDP'])
413         else:
414             return self.translation (format_table['pre-GDP'])
415
416     def short_texi_status (self, markup):
417         s = ''
418         if self.partially_translated:
419             s += markup.newline ().join (self.translators + [''])
420             if self.checkers:
421                 s += markup.small (markup.newline ().join (self.checkers + ['']))
422         c = self.completeness (['color', 'long'])
423         s += markup.span ('%(long)s' % c, [('style', 'background-color: #%(color)s' % c)])
424         s += markup.newline ()
425         if self.partially_translated:
426             u = self.uptodateness (['vague', 'color'])
427             s += markup.span ('%(vague)s' % u, [('style', 'background-color: #%(color)s' % u)])
428         return markup.cell (s, [('title', filename)])
429
430     def text_status (self):
431         s = self.completeness ('abbr')['abbr'] + ' '
432
433         if self.partially_translated:
434             s += self.uptodateness ('abbr')['abbr'] + ' '
435         return s
436
437     def texi_status (self, markup, numbering=SectionNumber ()):
438         s =  '''<tr align="center">
439   <th>%s</th>''' % self.print_title (numbering)
440         s += ''.join (['  <th>%s</th>\n' % self.translation (h)
441                        for h in detailed_status_heads])
442         s += ' </tr>\n'
443         s += (' <tr align="left">\n  <td title="%%(filename)s">%s<br>(%d)</td>\n'
444               % (self.translation (section_titles_string),
445                  sum (self.masterdocument.word_count))) % self.__dict__
446         s += self.texi_body (markup, numbering)
447         s += ' </tr>\n'
448         s += self.texi_translations (markup, numbering)
449         return markup.table (s) + markup.paragraph ()
450
451     def texi_body (self, markup, numbering):
452         return (self.texi_translators (markup)
453                 + self.texi_completeness (markup)
454                 + self.texi_uptodateness (markup)
455                 + self.texi_gdp (markup))
456
457     def texi_translators (self, markup):
458         if self.partially_translated:
459             return ('  <td>' + '<br>\n   '.join (self.translators) + '</td>\n'
460                     + '  <td>' + '<br>\n   '.join (self.checkers) + '</td>\n')
461         return '  <td></td>\n' * 2
462
463     def texi_completeness (self, markup):
464         c = self.completeness (['color', 'short'], translated=True)
465         return '  <td><span style="background-color: #%(color)s">\
466 %(short)s</span></td>\n' % {'color': c['color'],
467                            'short': c['short']}
468
469     def texi_uptodateness (self, markup):
470         if self.partially_translated:
471             u = self.uptodateness (['short', 'color'], translated=True)
472             return '  <td><span style="background-color: #%(color)s">\
473 %(short)s</span></td>\n' % {'color': u['color'],
474                            'short': u['short']}
475         return '  <td></td>\n'
476
477     def texi_gdp (self, markup):
478         return '  <td>' + self.gdp_status () + '</td>\n </tr>\n'
479
480     def texi_translations (self, markup, numbering):
481         return ''.join ([i.translations[self.language].texi_status (markup, numbering)
482                          for i in self.masterdocument.includes
483                          if self.language in i.translations])
484
485 class IncludedTranslatedTelyDocument (TranslatedTelyDocument):
486     get_level = TelyDocument.get_level
487     def texi_status (self, markup, numbering=SectionNumber ()):
488         if self.title != 'Untitled':
489             return ((' <tr align="left">\n  <td title="%%(filename)s">%s<br>(%d)</td>\n'
490                      % (self.print_title (numbering),
491                         sum (self.masterdocument.word_count))) % self.__dict__
492                     + self.texi_body (markup, numbering)
493                     + '</tr>'
494                     + self.texi_translations (markup, numbering))
495         return ''
496
497 class UntranslatedTelyDocument (TranslatedTelyDocument):
498     def __init__ (self, filename, masterdocument, parent_translation=None):
499         if filename[2] == '/':
500             self.language = filename[:2]
501         TranslatedTelyDocument.__init__ (self, filename, masterdocument, parent_translation)
502
503 class IncludedUntranslatedTelyDocument (UntranslatedTelyDocument, IncludedTranslatedTelyDocument):
504     get_level = TelyDocument.get_level
505
506 class MasterTelyDocument (TelyDocument):
507     def __init__ (self,
508                   filename,
509                   parent_translations=dict ([(lang, None)
510                                              for lang in langdefs.LANGDICT])):
511         TelyDocument.__init__ (self, filename)
512         self.size = len (self.contents)
513         self.word_count = tely_word_count (self.contents)
514         self.translations = {}
515         self.includes = []
516         if not self.language or self.language == 'en':
517             languages = [x for x in parent_translations.keys () if x != 'en']
518             self.translations = dict ([x for x in
519                                        [(lang, self.translated_factory (os.path.join (lang, self.filename),
520                                                                         parent_translations.get (lang)))
521                                         for lang in languages]
522                                        if x[1]])
523             if self.translations:
524                 self.includes = [IncludedMasterTelyDocument (f, self.translations)
525                                  for f in self.included_files]
526
527     def get_level (self):
528         return texi_level ['top']
529
530     def translated_factory (self, filename, parent):
531         if os.path.exists (filename):
532             return TranslatedTelyDocument (filename, self, parent)
533         return None
534
535     def update_word_counts (self, s):
536         s = update_word_count (s, self.filename, sum (self.word_count))
537         for i in self.includes:
538             s = i.update_word_counts (s)
539         return s
540
541     def texi_status (self, markup, numbering=SectionNumber ()):
542         s = '''
543  <tr align="center">
544   <th>%s</th>''' % self.print_title (numbering)
545         s += ''.join (['  <th>%s</th>\n' % l for l in sorted (self.translations.keys ())])
546         s += ' </tr>\n'
547         s += (' <tr align="left">\n  <td title="%%(filename)s">Section titles<br>(%d)</td>\n'
548               % sum (self.word_count)) % self.__dict__
549         s += self.texi_body (markup, numbering)
550         s += ' </tr>\n'
551         s += self.texi_includes (markup, numbering)
552         return markup.table (s) + markup.paragraph ()
553
554     def texi_includes (self, markup, numbering):
555         return ''.join ([i.texi_status (markup, numbering) for i in self.includes])
556
557     def texi_body (self, markup, numbering):
558         return (''.join ([self.translations[k].short_texi_status (markup)
559                           for k in sorted (self.translations.keys ())])
560                 + ' </tr>\n')
561
562     def text_status (self, markup, numbering=SectionNumber (), colspec=[48,12]):
563         s = (self.print_title (numbering) + ' ').ljust (colspec[0])
564         s += ''.join (['%s'.ljust (colspec[1]) % l
565                        for l in sorted (self.translations.keys ())])
566         s += '\n'
567         s += ('Section titles (%d)' % \
568                   sum (self.word_count)).ljust (colspec[0])
569         s += self.text_body (markup, numbering, colspec)
570         s += '\n'
571         return s
572
573     def text_body (self, markup, numbering, colspec):
574         return (''.join ([self.translations[k].text_status ().ljust(colspec[1])
575                           for k in sorted (self.translations.keys ())])
576                 + '\n\n'
577                 + ''.join ([i.text_status (markup, numbering) for i in self.includes]))
578
579 class IncludedMasterTelyDocument (MasterTelyDocument):
580     get_level = TelyDocument.get_level
581
582     def translated_factory (self, filename, parent):
583         if os.path.exists (filename):
584             return IncludedTranslatedTelyDocument (filename, self, parent)
585         return IncludedUntranslatedTelyDocument (filename, self, parent)
586
587     def texi_status (self, markup, numbering=SectionNumber ()):
588         if self.title != 'Untitled':
589             return ((' <tr align="left">\n  <td title=%%(filename)s>%s<br>(%d)</td>\n'
590                      % (self.print_title (numbering), sum (self.word_count))) % self.__dict__
591                     + self.texi_body (markup, numbering)
592                     + '</tr>'
593                     + self.texi_includes (markup, numbering))
594         return ''
595
596     def text_status (self, markup, numbering=SectionNumber (), colspec=[48,12]):
597         if self.title != 'Untitled':
598             return (('%s (%d) '
599                      % (self.print_title (numbering), sum (self.word_count)))
600                     + self.text_body (markup, numbering, colspec)
601                     ).ljust (colspec[0])
602         return ''
603
604
605 update_category_word_counts_re = re.compile (r'(?ms)^-(\d+)-(.*?\n)\d+ *total')
606
607 counts_re = re.compile (r'(?m)^(\d+) ')
608
609 def update_category_word_counts_sub (m):
610     return ('-' + m.group (1) + '-' + m.group (2)
611             + str (sum ([int (c)
612                          for c in counts_re.findall (m.group (2))])).ljust (6)
613             + 'total')
614
615 # urg 
616 # main () starts here-abouts
617
618 progress ("Reading documents...")
619
620 master_files = \
621     buildlib.read_pipe ("git ls-files | grep -E '[^/]*/?[^/]*[.](tely|texi)$'")[0].splitlines ()
622 master_files.sort ()
623 master_docs = [MasterTelyDocument (os.path.normpath (filename))
624                for filename in master_files]
625 master_docs = [doc for doc in master_docs if doc.translations]
626
627 enabled_languages = [l for l in langdefs.LANGDICT
628                      if langdefs.LANGDICT[l].enabled
629                      and l != 'en']
630
631 progress ("Generating status pages...")
632
633 date_time = buildlib.read_pipe ('LANG= date -u')[0]
634
635 markup = HTMLMarkup ()
636 #markup = TexiMarkup ()
637 main_status_body = last_updated_string % date_time
638 main_status_body += '\n'.join ([doc.texi_status (markup) for doc in master_docs])
639
640 texi_header = '''@c -*- coding: utf-8; mode: texinfo; -*-
641 @c This file was generated by translation-status.py -- DO NOT EDIT!
642 @ignore
643     Translation of GIT committish: 0
644 @end ignore
645
646 @ifnothtml
647 Translation status currently only available in HTML.
648 @end ifnothtml
649 @ifhtml
650 @html
651 '''
652
653 texi_footer = '''
654 @end html
655 @end ifhtml
656 '''
657
658 main_status_page = texi_header % locals () + main_status_body + texi_footer
659
660 open ('translations.itexi', 'w').write (main_status_page)
661
662 for l in enabled_languages:
663     date_time = buildlib.read_pipe ('LANG=%s date -u' % l)[0]
664     updated = translation[l] (last_updated_string) % date_time
665     texi_status = '\n'.join ([doc.translations[l].texi_status (markup)
666                               for doc in master_docs
667                               if l in doc.translations])
668     lang_status_page = texi_header + updated + texi_status + texi_footer
669     open (os.path.join (l, 'translations.itexi'), 'w').write (lang_status_page)
670
671 main_status_txt = '''Documentation translations status
672 Generated %s
673 NT = not translated
674 FT = fully translated
675
676 ''' % date_time
677
678 main_status_txt += '\n'.join ([doc.text_status (markup) for doc in master_docs])
679
680 status_txt_file = 'out/translations-status.txt'
681 progress ("Writing %s..." % status_txt_file)
682 open (status_txt_file, 'w').write (main_status_txt)
683
684 translation_instructions_file = 'contributor/doc-translation-list.itexi'
685 progress ("Updating %s..." % translation_instructions_file)
686 translation_instructions = open (translation_instructions_file).read ()
687
688 for doc in master_docs:
689     translation_instructions = doc.update_word_counts (translation_instructions)
690
691 for html_file in re.findall (r'(?m)^\d+ *(\S+?\.html\S*?)(?: |$)',
692                              translation_instructions):
693     word_count = sgml_word_count (open (html_file).read ())
694     translation_instructions = update_word_count (translation_instructions,
695                                                   html_file,
696                                                   word_count)
697
698 for po_file in re.findall (r'(?m)^\d+ *(\S+?\.po\S*?)(?: |$)',
699                            translation_instructions):
700     word_count = po_word_count (open (po_file).read ())
701     translation_instructions = update_word_count (translation_instructions,
702                                                   po_file,
703                                                   word_count)
704
705 translation_instructions = \
706     update_category_word_counts_re.sub (update_category_word_counts_sub,
707                                         translation_instructions)
708
709 open (translation_instructions_file, 'w').write (translation_instructions)
710 sys.exit (exit_code)