[damned-lies] Add better fallbacks for documentation pot file generation



commit bac9f55e20b2b79434ded74db0cc3d788879a967
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Jan 11 10:10:31 2014 +0100

    Add better fallbacks for documentation pot file generation
    
    These changes allow generating a pot file even when the
    gnome-doc-utils/yelp-tools standard toolchain is not used (falling
    back to mallard/itstool).

 stats/utils.py |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/stats/utils.py b/stats/utils.py
index 07084d6..407c6f7 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -206,9 +206,10 @@ def generate_doc_pot_file(vcs_path, potbase, moduleid):
     """ Return the pot file for a document-type domain, and the error if any """
     errors = []
 
-    doc_id = read_makefile_variable([vcs_path], "HELP_ID")
+    doc_id = read_makefile_variable([vcs_path], "HELP_ID", default="NOTFOUND")
+    uses_itstool = doc_id == "NOTFOUND" or bool(doc_id)
     has_index_page = os.access(os.path.join(vcs_path, "C", "index.page"), os.R_OK)
-    doc_format = DocFormat(bool(doc_id), has_index_page)
+    doc_format = DocFormat(uses_itstool, has_index_page)
 
     files = []
     if doc_format.format == "mallard":
@@ -233,6 +234,10 @@ def generate_doc_pot_file(vcs_path, potbase, moduleid):
     includes = read_makefile_variable([vcs_path], doc_format.include_var)
     if includes:
         files.extend(filter(lambda x:x not in ("", "$(NULL)"), includes.split()))
+    else:
+        # fallback to directory listing
+        files = [f for f in os.listdir(os.path.join(vcs_path, "C")) if f.endswith(".page")]
+
     files = " ".join([os.path.join("C", f) for f in files])
     potfile = os.path.join(vcs_path, "C", potbase + ".pot")
     command = doc_format.command % {'dir': vcs_path, 'potfile': potfile, 'files': files}
@@ -252,7 +257,7 @@ def generate_doc_pot_file(vcs_path, potbase, moduleid):
     else:
         return potfile, errors, doc_format
 
-def read_makefile_variable(vcs_paths, variable):
+def read_makefile_variable(vcs_paths, variable, default=None):
     """ vcs_paths is a list of potential path where Makefile.am could be found """
     makefiles = [os.path.join(path, "Makefile.am") for path in vcs_paths]
     good_makefile = None
@@ -261,7 +266,7 @@ def read_makefile_variable(vcs_paths, variable):
             good_makefile = makefile
             break
     if not good_makefile:
-        return None # no file found
+        return default  # no file found
 
     return search_variable_in_file(good_makefile, variable)
 


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