[damned-lies] Slightly reworked LINGUAS check



commit 135cda3b1df853977d9cc30d929fe407af1cc9dc
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu Jun 25 19:45:46 2009 +0200

    Slightly reworked LINGUAS check
    
    One improvement is that the error about not found LINGUAS file is
    attached to pot and not to po files.
    LINGUAS retrieving for ui files is now done only once per domain.

 stats/models.py |   14 ++++++++------
 stats/utils.py  |   44 +++++++++++++++-----------------------------
 2 files changed, 23 insertions(+), 35 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index a212e1c..18ac03f 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -312,16 +312,20 @@ class Branch(models.Model):
             # ****************************
             if dom.dtype == 'ui':
                 potfile, errs = dom.generate_pot_file(domain_path)
+                linguas = utils.get_ui_linguas(self.co_path(), domain_path)
             elif dom.dtype == 'doc': # only gnome-doc-utils toolchain supported so far for docs
                 potfile, errs = utils.generate_doc_pot_file(domain_path, dom.potbase(), self.module.name, settings.DEBUG)
                 if not potfile:
                     print >> sys.stderr, "\n".join([e[1] for e in errs])
                     continue
-                doclinguas = utils.read_makefile_variable(domain_path, "DOC_LINGUAS").split()
+                linguas = {'langs': utils.read_makefile_variable(domain_path, "DOC_LINGUAS").split(),
+                           'error': ugettext_noop("DOC_LINGUAS list doesn't include this language.") }
             else:
                 print >> sys.stderr, "Unknown domain type '%s', ignoring domain '%s'" % (dom.dtype, dom.name)
                 continue
             errors.extend(errs)
+            if linguas['langs'] is None:
+                errors.append(("warn", linguas['error']))
 
             # Prepare statistics object
             try:
@@ -389,11 +393,9 @@ class Branch(models.Model):
                 utils.run_shell_command(realcmd)
 
                 langstats = utils.po_file_stats(outpo, True)
-                if dom.dtype == "ui":
-                    langstats['errors'].extend(utils.check_lang_support(self.co_path(), domain_path, lang))
-                elif dom.dtype == "doc":
-                    if lang not in doclinguas:
-                        langstats['errors'].append(("warn-ext", ugettext_noop("DOC_LINGUAS list doesn't include this language.")))
+                if linguas['langs'] is not None and lang not in linguas['langs']:
+                    langstats['errors'].append("warn-ext", linguas['error'])
+                if dom.dtype == "doc":
                     fig_stats = utils.get_fig_stats(outpo)
                     for fig in fig_stats:
                         trans_path = os.path.join(domain_path, lang, fig['path'])
diff --git a/stats/utils.py b/stats/utils.py
index dc2e0e0..bcd0ef3 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -265,35 +265,27 @@ def po_file_stats(pofile, msgfmt_checks = True):
     return res
 
 
-def check_lang_support(module_path, po_path, lang):
-    """Checks if language is listed in one of po/LINGUAS, configure.ac or configure.in"""
+def get_ui_linguas(module_path, po_path):
+    """Get language list in one of po/LINGUAS, configure.ac or configure.in"""
 
     LINGUAShere = os.path.join(po_path, "LINGUAS")
     LINGUASpo = os.path.join(module_path, "po", "LINGUAS") # if we're in eg. po-locations/
     configureac = os.path.join(module_path, "configure.ac")
     configurein = os.path.join(module_path, "configure.in")
 
-    errors = []
+    langs = []
 
     # is "lang" listed in either of po/LINGUAS, ./configure.ac(ALL_LINGUAS) or ./configure.in(ALL_LINGUAS)
-    in_config = 0
     for LINGUAS in [LINGUAShere, LINGUASpo]:
         if os.access(LINGUAS, os.R_OK):
             lfile = open(LINGUAS, "r")
-            for line in lfile:
-                line = line.strip()
-                if len(line) and line[0]=="#": continue
-                if lang in line.split(" "):
-                    if settings.DEBUG: print >>sys.stderr, "Language '%s' found in LINGUAS." % (lang)
-                    in_config = 1
-                    break
+            [langs.extend(line.split()) for line in lfile if line[:1]!='#']
             lfile.close()
-            if not in_config:
-                errors.append(("warn-ext", ugettext_noop("Entry for this language is not present in LINGUAS file.")))
-            return errors
+            return {'langs':langs,
+                    'error': ugettext_noop("Entry for this language is not present in LINGUAS file.") }
 
     for configure in [configureac, configurein]:
-        if not in_config and os.access(configure, os.R_OK):
+        if os.access(configure, os.R_OK):
             cfile = open(configure, "r")
             lines = []
             prev = ""
@@ -307,20 +299,14 @@ def check_lang_support(module_path, po_path, lang):
 
             for line in lines:
                 line = line.strip()
-                test = re.search('ALL_LINGUAS\s*[=,]\s*"([^"]*)"', line)
-                if test:
-                    value = test.groups(1)[0]
-                    if lang in value.split(" "):
-                        if settings.DEBUG: print >>sys.stderr, "Language '%s' found in %s." % (lang, configure)
-                        in_config = 1
-                    break
-            cfile.close()
-            if not in_config:
-                errors.append(("warn-ext", ugettext_noop("Entry for this language is not present in ALL_LINGUAS in configure file.")))
-            return errors
-
-    errors.append(("warn", ugettext_noop("Don't know where to look if this language is actually used, ask the module maintainer.")))
-    return errors
+                match = re.search('ALL_LINGUAS\s*[=,]\s*"([^"]*)"', line)
+                if match:
+                    langs = match.groups(1)[0].split()
+                    cfile.close()
+                    return {'langs':langs,
+                            'error': ugettext_noop("Entry for this language is not present in ALL_LINGUAS in configure file.") }
+    return {'langs':None,
+            'error': ugettext_noop("Don't know where to look if this language is actually used, ask the module maintainer.") }
 
 def get_fig_stats(pofile):
     """ Extract image strings from pofile and return a list of figures dict:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]