[damned-lies] Initialize DocFormat with branch and domain
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Initialize DocFormat with branch and domain
- Date: Sat, 23 Jun 2018 16:46:06 +0000 (UTC)
commit d18fecded269454c596835969a86c67cca307eeb
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Jun 23 15:13:02 2018 +0200
Initialize DocFormat with branch and domain
stats/utils.py | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
---
diff --git a/stats/utils.py b/stats/utils.py
index 8be65915..6747532f 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -50,11 +50,14 @@ 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>[^\"]*)\"")
- def __init__(self, makefile):
- # makefile is a MakefileWrapper (or subclass) instance)
- self.makefile = makefile
- doc_id = makefile.read_variable("HELP_ID", "yelp.project_id")
- uses_itstool = doc_id is not None or isinstance(makefile, MesonfileWrapper)
+ def __init__(self, domain, branch):
+ self.branch = branch
+ self.vcs_path = branch.domain_path(domain)
+ self.makefile = MakefileWrapper.find_file(branch, [self.vcs_path])
+ if self.makefile is None:
+ raise Exception(ugettext_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())
self.format = 'mallard' if has_page_files else 'docbook'
self.tool = 'itstool' if uses_itstool else 'xml2po'
@@ -64,8 +67,7 @@ class DocFormat:
return isinstance(self.makefile, MesonfileWrapper)
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()]
+ return [p.relative_to(self.vcs_path) for p in (self.vcs_path / 'C').iterdir() if p.is_file()]
def source_files(self):
"""Return help source files, with path relative to help base dir."""
@@ -396,17 +398,13 @@ def generate_doc_pot_file(branch, domain):
errors = []
vcs_path = branch.domain_path(domain)
moduleid = branch.module.name
- makefile = MakefileWrapper.find_file(branch, [vcs_path])
- if makefile is None:
- errors.append(
- ("error", ugettext_noop("Unable to find a makefile for module %s") % moduleid)
- )
- return "", errors, None
-
- doc_format = DocFormat(makefile)
+ try:
+ doc_format = DocFormat(domain, branch)
+ except Exception as err:
+ return "", [("error", str(err))], None
files = []
if doc_format.format == "docbook":
- modulename = makefile.read_variable(doc_format.module_var)
+ modulename = doc_format.makefile.read_variable(doc_format.module_var)
if not modulename:
modulename = moduleid
for index_page in ("index.docbook", modulename + ".xml", moduleid + ".xml"):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]