[damned-lies] Fixed reading of source files from certain meson files



commit 1508561cda3c2f6da1169d0118a1126751cd87a7
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat May 19 12:16:37 2018 +0200

    Fixed reading of source files from certain meson files

 stats/utils.py |   40 +++++++++++++++++-----------------------
 1 files changed, 17 insertions(+), 23 deletions(-)
---
diff --git a/stats/utils.py b/stats/utils.py
index 0ee7239..5c34d0b 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -55,7 +55,7 @@ class DocFormat:
         self.makefile = makefile
         doc_id = makefile.read_variable("HELP_ID", "yelp.project_id")
         uses_itstool = doc_id is not None or isinstance(makefile, MesonfileWrapper)
-        has_page_files = any(f.suffix == '.page' for f in self.source_files(force_all=True))
+        has_page_files = any(f.suffix == '.page' for f in self.list_C_files())
         self.format = 'mallard' if has_page_files else 'docbook'
         self.tool = 'itstool' if uses_itstool else 'xml2po'
 
@@ -63,26 +63,19 @@ class DocFormat:
     def use_meson(self):
         return isinstance(self.makefile, MesonfileWrapper)
 
-    def source_files(self, force_all=False):
+    def list_C_files(self):
+        base_path = self.makefile.path.parent
+        return [p.relative_to(base_path) for p in (base_path / 'C').iterdir() if p.is_file()]
+
+    def source_files(self):
         """Return help source files, with path relative to help base dir."""
-        if force_all:
-            base_path = self.makefile.path.parent
-            return [p.relative_to(base_path) for p in (base_path / 'C').iterdir() if p.is_file()]
-        else:
-            sources = self.makefile.read_variable(self.include_var)
-            if not sources:
-                if self.format == "mallard":
-                    # fallback to directory listing
-                    sources = [
-                        f for f in self.source_files(force_all=True) if f.suffix == ".page"
-                    ]
-                if not sources:
-                    return []
-            if isinstance(sources, str):
-                sources = sources.split()
-            return [
-                Path('C', src) for src in sources if src not in ("", "$(NULL)")
-            ]
+        sources = self.makefile.read_variable(self.include_var)
+        if not sources and self.format == 'mallard':
+            # Fallback to directory listing
+            return [f for f in self.list_C_files() if f.suffix == '.page']
+        if isinstance(sources, str):
+            sources = sources.split()
+        return [Path('C', src) for src in sources if src not in ('', '$(NULL)')]
 
     def command(self, potfile, files):
         if self.tool == "itstool":
@@ -215,7 +208,9 @@ class MesonfileWrapper(MakefileWrapper):
         )
         # ignore if/endif sections
         content = re.sub(r"^if .*endif$", '', content, flags=re.M | re.S)
-        content = content.replace('true', 'True').replace('false', 'False').replace("i18n = import('i18n')", 
'')
+        content = content.replace('true', 'True').replace('false', 'False'
+            ).replace("i18n = import('i18n')", ''
+            ).replace("gnome = import('gnome')", '')
         return content
 
     @cached_property
@@ -419,8 +414,7 @@ def generate_doc_pot_file(branch, domain):
         if not files:
             # Last try: only one xml/docbook file in C/...
             xml_files = [
-                f for f in doc_format.source_files(force_all=True)
-                if f.suffix in (".xml", ".docbook")
+                f for f in doc_format.list_C_files() if f.suffix in ('.xml', '.docbook')
             ]
             if len(xml_files) == 1:
                 files.append(xml_files[0])


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