]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/translations-status.py
Merge branch 'master' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / buildscripts / translations-status.py
old mode 100644 (file)
new mode 100755 (executable)
index b9f62a7..68c55e8
@@ -1,4 +1,4 @@
-#!@PYTHON@
+#!/usr/bin/env python
 
 """
 USAGE: translations-status.py BUILDSCRIPT-DIR LOCALEDIR
@@ -18,7 +18,8 @@ import re
 import string
 import os
 import gettext
-import subprocess
+
+import langdefs
 
 def progress (str):
     sys.stderr.write (str + '\n')
@@ -26,31 +27,15 @@ def progress (str):
 progress ("translations-status.py")
 
 buildscript_dir = sys.argv[1]
-localedir = sys.argv[2]
 
 _doc = lambda s: s
 
 sys.path.append (buildscript_dir)
-import langdefs
+import buildlib
 
 # load gettext messages catalogs
-translation = {}
-for l in langdefs.LANGUAGES:
-    if l.enabled and l.code != 'en':
-        translation[l.code] = gettext.translation('lilypond-doc', localedir, [l.code]).gettext
-
-def read_pipe (command):
-    child = subprocess.Popen (command,
-                              stdout = subprocess.PIPE,
-                              stderr = subprocess.PIPE,
-                              shell = True)
-    (output, error) = child.communicate ()
-    code = str (child.wait ())
-    if not child.stdout or child.stdout.close ():
-        print "pipe failed: %(command)s" % locals ()
-    if code != '0':
-        error = code + ' ' + error
-    return (output, error)
+translation = langdefs.translation
+
 
 comments_re = re.compile (r'^@ignore\n(.|\n)*?\n@end ignore$|@c .*?$', re.M)
 space_re = re.compile (r'\s+', re.M)
@@ -59,7 +44,6 @@ node_re = re.compile ('^@node .*?$', re.M)
 title_re = re.compile ('^@(top|chapter|(?:sub){0,2}section|(?:unnumbered|appendix)(?:(?:sub){0,2}sec)?) (.*?)$', re.M)
 include_re = re.compile ('^@include (.*?)$', re.M)
 
-committish_re = re.compile ('GIT [Cc]ommittish: ([a-f0-9]+)')
 translators_re = re.compile (r'^@c\s+Translators\s*:\s*(.*?)$', re.M | re.I)
 checkers_re = re.compile (r'^@c\s+Translation\s*checkers\s*:\s*(.*?)$', re.M | re.I)
 status_re = re.compile (r'^@c\s+Translation\s*status\s*:\s*(.*?)$', re.M | re.I)
@@ -67,8 +51,6 @@ post_gdp_re = re.compile ('post.GDP', re.I)
 untranslated_node_str = 'UNTRANSLATED NODE: IGNORE ME'
 skeleton_str = '-- SKELETON FILE --'
 
-diff_cmd = 'git diff --no-color %(committish)s HEAD -- %(original)s | cat'
-
 format_table = {
     'not translated': {'color':'d0f0f8', 'short':_doc ('no'), 'abbr':'NT',
                        'long':_doc ('not translated')},
@@ -239,14 +221,7 @@ class TranslatedTelyDocument (TelyDocument):
         self.translation_percentage = 100 * translation_word_count / master_total_word_count
 
         ## calculate how much the file is outdated
-        m = committish_re.search (self.contents)
-        if not m:
-            sys.stderr.write ('error: ' + filename + \
-                                  ": no 'GIT committish: <hash>' found.\nPlease check " + \
-                                  'the whole file against the original in English, then ' + \
-                                  'fill in HEAD committish in the header.\n')
-            sys.exit (1)
-        (diff_string, error) = read_pipe (diff_cmd % {'committish':m.group (1), 'original':masterdocument.filename})
+        (diff_string, error) = buildlib.check_translated_doc (masterdocument.filename, self.contents)
         if error:
             sys.stderr.write ('warning: %s: %s' % (self.filename, error))
             self.uptodate_percentage = None
@@ -332,13 +307,13 @@ class TranslatedTelyDocument (TelyDocument):
         return ''
 
 class MasterTelyDocument (TelyDocument):
-    def __init__ (self, filename, parent_translations=dict ([(lang, None) for lang in langdefs.LANGDICT.keys()])):
+    def __init__ (self, filename, parent_translations=dict ([(lang, None) for lang in langdefs.LANGDICT])):
         TelyDocument.__init__ (self, filename)
         self.size = len (self.contents)
         self.word_count = tely_word_count (self.contents)
-        translations = dict ([(lang, os.path.join (lang, filename)) for lang in langdefs.LANGDICT.keys()])
+        translations = dict ([(lang, os.path.join (lang, filename)) for lang in langdefs.LANGDICT])
         self.translations = dict ([(lang, TranslatedTelyDocument (translations[lang], self, parent_translations.get (lang)))
-                                   for lang in langdefs.LANGDICT.keys() if os.path.exists (translations[lang])])
+                                   for lang in langdefs.LANGDICT if os.path.exists (translations[lang])])
         if self.translations:
             self.includes = [MasterTelyDocument (f, self.translations) for f in self.included_files]
         else:
@@ -357,7 +332,7 @@ class MasterTelyDocument (TelyDocument):
             s = '''<table align="center" border="2">
  <tr align="center">
   <th>%s</th>''' % self.print_title (numbering)
-            s += ''.join (['  <th>%s</th>\n' % l for l in self.translations.keys ()])
+            s += ''.join (['  <th>%s</th>\n' % l for l in self.translations])
             s += ' </tr>\n'
             s += ' <tr align="left">\n  <td>Section titles<br>(%d)</td>\n' \
                 % sum (self.word_count)
@@ -381,7 +356,7 @@ class MasterTelyDocument (TelyDocument):
         s = ''
         if self.level[1] == 0: # if self is a master document
             s += (self.print_title (numbering) + ' ').ljust (colspec[0])
-            s += ''.join (['%s'.ljust (colspec[1]) % l for l in self.translations.keys ()])
+            s += ''.join (['%s'.ljust (colspec[1]) % l for l in self.translations])
             s += '\n'
             s += ('Section titles (%d)' % sum (self.word_count)).ljust (colspec[0])
 
@@ -410,7 +385,7 @@ def update_category_word_counts_sub (m):
 
 progress ("Reading documents...")
 
-tely_files = read_pipe ("find -maxdepth 2 -name '*.tely'")[0].splitlines ()
+tely_files = buildlib.read_pipe ("find -maxdepth 2 -name '*.tely'")[0].splitlines ()
 master_docs = [MasterTelyDocument (os.path.normpath (filename)) for filename in tely_files]
 master_docs = [doc for doc in master_docs if doc.translations]
 
@@ -418,12 +393,12 @@ main_status_page = open ('translations.template.html.in').read ()
 
 ## TODO
 #per_lang_status_pages = dict ([(l, open (os.path.join (l, 'translations.template.html')). read ())
-#                               for l in langdefs.LANGDICT.keys ()
+#                               for l in langdefs.LANGDICT
 #                               if langdefs.LANGDICT[l].enabled])
 
 progress ("Generating status pages...")
 
-date_time = read_pipe ('LANG= date -u')[0]
+date_time = buildlib.read_pipe ('LANG= date -u')[0]
 
 main_status_html = ' <p><i>Last updated %s</i></p>\n' % date_time
 main_status_html += '\n'.join ([doc.html_status () for doc in master_docs])