From bf8476a78727b3442fb27fb10e67e8e4b364f07f Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 12 Apr 2010 22:22:21 +0200 Subject: [PATCH] translations-status.py: Add non-used visitor parameter to markup functions. Enables factoring-out of html codes. --- scripts/auxiliar/translations-status.py | 72 +++++++++++++------------ 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/scripts/auxiliar/translations-status.py b/scripts/auxiliar/translations-status.py index 9e5970fd31..c244fd693e 100755 --- a/scripts/auxiliar/translations-status.py +++ b/scripts/auxiliar/translations-status.py @@ -177,6 +177,11 @@ def tely_word_count (tely_doc): nodes = node_re.split (tely_doc) return [len (space_re.split (n)) for n in nodes] +class TexiMarkup (object): + pass + +class HTMLMarkup (TexiMarkup): + pass class TelyDocument (object): def __init__ (self, filename): @@ -360,7 +365,7 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative)) else: return self.translation (format_table['pre-GDP']) - def short_texi_status (self): + def short_texi_status (self, markup): s = ' ' % self.__dict__ if self.partially_translated: s += '
\n '.join (self.translators) + '
\n' @@ -387,7 +392,7 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative)) s += self.uptodateness ('abbr')['abbr'] + ' ' return s - def texi_status (self, numbering=SectionNumber ()): + def texi_status (self, markup, numbering=SectionNumber ()): s = '''''' % self.print_title (numbering) @@ -397,30 +402,30 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative)) s += (' \n \n' % (self.translation (section_titles_string), sum (self.masterdocument.word_count))) % self.__dict__ - s += self.texi_body (numbering) + s += self.texi_body (markup, numbering) s += '
%s
%s
(%d)
\n

\n' return s - def texi_body (self, numbering): - return (self.texi_translators () - + self.texi_completeness () - + self.texi_uptodateness () - + self.texi_gdp () - + self.texi_translations (numbering)) + def texi_body (self, markup, numbering): + return (self.texi_translators (markup) + + self.texi_completeness (markup) + + self.texi_uptodateness (markup) + + self.texi_gdp (markup) + + self.texi_translations (markup, numbering)) - def texi_translators (self): + def texi_translators (self, markup): if self.partially_translated: return (' ' + '
\n '.join (self.translators) + '\n' + ' ' + '
\n '.join (self.checkers) + '\n') return ' \n' * 2 - def texi_completeness (self): + def texi_completeness (self, markup): c = self.completeness (['color', 'short'], translated=True) return ' \ %(short)s\n' % {'color': c['color'], 'short': c['short']} - def texi_uptodateness (self): + def texi_uptodateness (self, markup): if self.partially_translated: u = self.uptodateness (['short', 'color'], translated=True) return ' \ @@ -428,22 +433,22 @@ setting to %d %%" % (self.filename, self.uptodate_percentage, alternative)) 'short': u['short']} return ' \n' - def texi_gdp (self): + def texi_gdp (self, markup): return ' ' + self.gdp_status () + '\n \n' - def texi_translations (self, numbering): - return ''.join ([i.translations[self.language].texi_status (numbering) + def texi_translations (self, markup, numbering): + return ''.join ([i.translations[self.language].texi_status (markup, numbering) for i in self.masterdocument.includes if self.language in i.translations]) class IncludedTranslatedTelyDocument (TranslatedTelyDocument): get_level = TelyDocument.get_level - def texi_status (self, numbering=SectionNumber ()): + def texi_status (self, markup, numbering=SectionNumber ()): if self.title != 'Untitled': return ((' \n %s
(%d)\n' % (self.print_title (numbering), sum (self.masterdocument.word_count))) % self.__dict__ - + self.texi_body (numbering)) + + self.texi_body (markup, numbering)) return '' class UntranslatedTelyDocument (TranslatedTelyDocument): @@ -490,7 +495,7 @@ class MasterTelyDocument (TelyDocument): s = i.update_word_counts (s) return s - def texi_status (self, numbering=SectionNumber ()): + def texi_status (self, markup, numbering=SectionNumber ()): s = '''''' % self.print_title (numbering) @@ -498,32 +503,32 @@ class MasterTelyDocument (TelyDocument): s += ' \n' s += (' \n \n' % sum (self.word_count)) % self.__dict__ - s += self.texi_body (numbering) + s += self.texi_body (markup, numbering) s += '
%s
Section titles
(%d)
\n

\n' return s - def texi_body (self, numbering): - return (''.join ([self.translations[k].short_texi_status () + def texi_body (self, markup, numbering): + return (''.join ([self.translations[k].short_texi_status (markup) for k in sorted (self.translations.keys ())]) + ' \n' - + ''.join ([i.texi_status (numbering) for i in self.includes])) + + ''.join ([i.texi_status (markup, numbering) for i in self.includes])) - def text_status (self, numbering=SectionNumber (), colspec=[48,12]): + def text_status (self, markup, numbering=SectionNumber (), colspec=[48,12]): s = (self.print_title (numbering) + ' ').ljust (colspec[0]) s += ''.join (['%s'.ljust (colspec[1]) % l for l in sorted (self.translations.keys ())]) s += '\n' s += ('Section titles (%d)' % \ sum (self.word_count)).ljust (colspec[0]) - s += self.text_body (numbering, colspec) + s += self.text_body (markup, numbering, colspec) s += '\n' return s - def text_body (self, numbering, colspec): + def text_body (self, markup, numbering, colspec): return (''.join ([self.translations[k].text_status ().ljust(colspec[1]) for k in sorted (self.translations.keys ())]) + '\n\n' - + ''.join ([i.text_status (numbering) for i in self.includes])) + + ''.join ([i.text_status (markup, numbering) for i in self.includes])) class IncludedMasterTelyDocument (MasterTelyDocument): get_level = TelyDocument.get_level @@ -533,18 +538,18 @@ class IncludedMasterTelyDocument (MasterTelyDocument): return IncludedTranslatedTelyDocument (filename, self, parent) return IncludedUntranslatedTelyDocument (filename, self, parent) - def texi_status (self, numbering=SectionNumber ()): + def texi_status (self, markup, numbering=SectionNumber ()): if self.title != 'Untitled': return ((' \n %s
(%d)\n' % (self.print_title (numbering), sum (self.word_count))) % self.__dict__ - + self.texi_body (numbering)) + + self.texi_body (markup, numbering)) return '' - def text_status (self, numbering=SectionNumber (), colspec=[48,12]): + def text_status (self, markup, numbering=SectionNumber (), colspec=[48,12]): if self.title != 'Untitled': return (('%s (%d) ' % (self.print_title (numbering), sum (self.word_count))) - + self.text_body (numbering, colspec) + + self.text_body (markup, numbering, colspec) ).ljust (colspec[0]) return '' @@ -579,8 +584,9 @@ progress ("Generating status pages...") date_time = buildlib.read_pipe ('LANG= date -u')[0] +markup = HTMLMarkup () main_status_body = last_updated_string % date_time -main_status_body += '\n'.join ([doc.texi_status () for doc in master_docs]) +main_status_body += '\n'.join ([doc.texi_status (markup) for doc in master_docs]) texi_header = '''@c -*- coding: utf-8; mode: texinfo; -*- @c This file was generated by translation-status.py -- DO NOT EDIT! @@ -607,7 +613,7 @@ open ('translations.itexi', 'w').write (main_status_page) for l in enabled_languages: date_time = buildlib.read_pipe ('LANG=%s date -u' % l)[0] updated = translation[l] (last_updated_string) % date_time - texi_status = '\n'.join ([doc.translations[l].texi_status () + texi_status = '\n'.join ([doc.translations[l].texi_status (markup) for doc in master_docs if l in doc.translations]) lang_status_page = texi_header + updated + texi_status + texi_footer @@ -620,7 +626,7 @@ FT = fully translated ''' % date_time -main_status_txt += '\n'.join ([doc.text_status () for doc in master_docs]) +main_status_txt += '\n'.join ([doc.text_status (markup) for doc in master_docs]) status_txt_file = 'out/translations-status.txt' progress ("Writing %s..." % status_txt_file) -- 2.39.2