[damned-lies] Catch DocFormat exception in can_build_docs



commit 0aee7b2e7d2ac8ba8c09d00ca37ac05d9ba1b324
Author: Claude Paroz <claude 2xlibre net>
Date:   Mon Sep 17 11:39:18 2018 +0200

    Catch DocFormat exception in can_build_docs

 stats/models.py | 7 +++++--
 stats/utils.py  | 8 +++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 9e79271d..5ca2e1da 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -23,7 +23,7 @@ from django.utils import dateformat
 from django.db import models
 
 from common.fields import DictionaryField, JSONField
-from common.utils import is_site_admin, run_shell_command
+from common.utils import UndetectableDocFormat, is_site_admin, run_shell_command
 from stats import utils, signals
 from stats.doap import update_doap_infos
 from people.models import Person
@@ -786,7 +786,10 @@ class Domain(models.Model):
                 self.dtype == 'doc' and self.layout == 'help/{lang}/{lang}.po')
 
     def can_build_docs(self, branch):
-        return self.dtype == 'doc' and self.doc_format(branch).format == 'mallard'
+        try:
+            return self.dtype == 'doc' and self.doc_format(branch).format == 'mallard'
+        except UndetectableDocFormat:
+            return False
 
     def get_po_path(self, locale):
         """
diff --git a/stats/utils.py b/stats/utils.py
index 2d9fbd05..69db65e5 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -46,6 +46,10 @@ def patchedAddunit(self, unit):
 TranslationStore.addunit = patchedAddunit
 
 
+class UndetectableDocFormat(Exception):
+    pass
+
+
 class DocFormat:
     itstool_regex = re.compile("^msgid \"external ref=\'(?P<path>[^\']*)\' md5=\'(?P<hash>[^\']*)\'\"")
     xml2po_regex = re.compile("^msgid \"@@image: \'(?P<path>[^\']*)\'; md5=(?P<hash>[^\"]*)\"")
@@ -55,7 +59,9 @@ class DocFormat:
         self.vcs_path = branch.domain_path(domain)
         self.makefile = MakefileWrapper.find_file(branch, [self.vcs_path])
         if self.makefile is None:
-            raise Exception(gettext_noop("Unable to find a makefile for module %s") % branch.module.name)
+            raise UndetectableDocFormat(
+                gettext_noop("Unable to find a makefile for module %s") % branch.module.name
+            )
         doc_id = self.makefile.read_variable("HELP_ID", "yelp.project_id")
         uses_itstool = doc_id is not None or self.use_meson
         has_page_files = any(f.suffix == '.page' for f in self.list_C_files())


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