[kupfer] help: Read Makefile.am for DOC_* variable definitions



commit a7c2f50d7ba3eade8b4ef142ebedfe7e722c5f98
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Mar 6 14:53:34 2010 +0100

    help: Read Makefile.am for DOC_* variable definitions
    
    Now our mallard build configuration reads Makefile.am for variable
    definitions.
    
    The file help/Makefile.am defines needed variables for gnome
    translation infrastructure.
    
    We read DOC_ID for the documentation package name
    We read DOC_PAGES and warn if an existing C/*.page file is not listed
    We read DOC_LINGUAS and use as the list of translated languages

 help/Makefile.am |   13 ++++++++++
 help/wscript     |   68 ++++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 62 insertions(+), 19 deletions(-)
---
diff --git a/help/Makefile.am b/help/Makefile.am
index 989a521..a49ab43 100644
--- a/help/Makefile.am
+++ b/help/Makefile.am
@@ -1,3 +1,14 @@
+#
+# This file defines variables and files for Kupfer's
+# mallard documentation.
+#
+# This file is needed for Gnome's translation infrastructure,
+# but it is never used as a real Makefile.
+#
+# Define all languages for translation in the variable DOC_LINGUAS
+#
+
+
 include $(top_srcdir)/gnome-doc-utils.make
 
 DOC_ID = kupfer
@@ -13,4 +24,6 @@ DOC_PAGES = \
 
 
 DOC_LINGUAS = de
+
+
 dist-hook: doc-dist-hook
diff --git a/help/wscript b/help/wscript
index 002f361..0e08f7a 100644
--- a/help/wscript
+++ b/help/wscript
@@ -1,32 +1,47 @@
-#! /usr/bin/env python
+#!/usr/bin/env python
+
+## Mallard functionality definitions ##
 import os
 import Task
-from TaskGen import extension, feature, after
+import TaskGen
 
-LINGUAS = """
-de
-""".split()
+def _read_makefile_am(filename):
+	"read a Makefile.am file for DOC_* variable definitions, return a dict"
+	varstring = open(filename).read()
+	varstring = varstring.replace("\\\n", " ")
+	varlines = [L for L in varstring.splitlines() if L.startswith("DOC")]
+	return dict(tuple(map(str.strip, var.split("=", 1))) for var in varlines)
 
-Task.simple_task_type('xml2po','${XML2PO} ${XML2POFLAGS} ${SRC} > ${TGT}',color='BLUE')
+def init_mallard(self):
+	mf_am = self.path.find_resource(self.variable_definitions)
+	DOC_VAR = _read_makefile_am(mf_am.abspath())
 
-def configure(conf):
-	xml2po = conf.find_program('xml2po', var='XML2PO')
-	conf.env['XML2POFLAGS'] = '-e -p'
+	require_vars = "DOC_ID DOC_LINGUAS DOC_PAGES".split()
+	have_vars = set(var for var in DOC_VAR if DOC_VAR[var])
+	missing_vars = set(require_vars).difference(have_vars)
+	if missing_vars:
+		print "Missing DOC variable declarations in %s:" % (mf_am.abspath())
+		print "\n".join(missing_vars)
 
-def set_options(opt):
-	pass
-
-def init_mallard(self):
-	self.default_install_path='${PREFIX}/share/gnome/help/${PACKAGE}'
+	self.bld.env.update(DOC_VAR)
+	self.default_install_path='${PREFIX}/share/gnome/help/${DOC_ID}'
 
 def apply_mallard(self):
-	lst = self.to_list(self.doc_linguas)
 	bld = self.bld
+	lst = self.to_list(bld.env["DOC_LINGUAS"])
 	cnode = self.path.find_dir("C")
 	self.bld.rescan(cnode)
 
 	pages = [p for p in self.bld.cache_dir_contents[cnode.id]
 			if (os.path.splitext(p)[-1].lower()) == ".page"]
+
+	# Check if the declared page list is consistent
+	declared_pages = self.to_list(bld.env["DOC_PAGES"])
+	missing_pages = set(pages).difference(declared_pages)
+	if missing_pages:
+		print "Warning: Some pages not declared:"
+		print "\n".join(missing_pages)
+
 	for lang in lst:
 		node = self.path.find_resource("%s/%s.po" % (lang, lang))
 		for page in pages:
@@ -44,13 +59,28 @@ def apply_mallard(self):
 			instdir = os.path.join(self.install_path, "C")
 			bld.install_files(instdir, out)
 
-feature("mallard")(init_mallard)
-feature("mallard")(apply_mallard)
-after('init_mallard')(apply_mallard)
+Task.simple_task_type('xml2po', '${XML2PO} ${XML2POFLAGS} ${SRC} > ${TGT}',
+		color='BLUE')
+
+TaskGen.feature("mallard")(init_mallard)
+TaskGen.feature("mallard")(apply_mallard)
+TaskGen.after('init_mallard')(apply_mallard)
+
+## End Mallard functionality ##
+
+
+# Build Configuration
+
+def set_options(opt):
+	pass
+
+def configure(conf):
+	xml2po = conf.find_program('xml2po', var='XML2PO')
+	conf.env['XML2POFLAGS'] = '-e -p'
 
 def build(bld):
 	if bld.env["XML2PO"]:
 		task = bld.new_task_gen(
 			features="mallard",
-			doc_linguas=LINGUAS,
+			variable_definitions="Makefile.am",
 		)



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