[yelp-tools] yelp-check: Added tool to check Mallard page licenses
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp-tools] yelp-check: Added tool to check Mallard page licenses
- Date: Wed, 29 Jan 2014 18:22:20 +0000 (UTC)
commit 34c6ceca3967fd845b8a42f4fe54309073273d4b
Author: Shaun McCance <shaunm gnome org>
Date: Wed Jan 29 13:21:52 2014 -0500
yelp-check: Added tool to check Mallard page licenses
tools/yelp-check.in | 82 ++++++++++++++++++++++++++++++++++++++++
xslt/Makefile.am | 1 +
xslt/mal-license.xsl | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 185 insertions(+), 0 deletions(-)
---
diff --git a/tools/yelp-check.in b/tools/yelp-check.in
index 1ad0c20..05531a6 100755
--- a/tools/yelp-check.in
+++ b/tools/yelp-check.in
@@ -17,6 +17,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
xsl_mal_link='@XSL_MAL_LINK@'
+xsl_mal_license='@DATADIR@/xslt/mal-license.xsl'
xsl_mal_status='@DATADIR@/xslt/mal-status.xsl'
xsl_mal_rng='@DATADIR@/xslt/mal-rng.xsl'
xsl_comments='@DATADIR@/xslt/comments.xsl'
@@ -108,6 +109,7 @@ yelp_usage () {
echo " comments Print the editorial comments in a document"
echo " hrefs Find broken external links in a document"
echo " ids Find Mallard page IDs that do not match file names"
+ echo " license Report the license of Mallard pages"
echo " links Find broken xref or linkend links in a document"
echo " orphans Find orphaned pages in a Mallard document"
echo " status Report the status of Mallard pages"
@@ -162,6 +164,25 @@ yelp_usage_comments () {
echo " comment element in Mallard and the remark element in DocBook."
) 1>&2
}
+yelp_usage_license () {
+ (
+ echo "Usage: yelp-check license <FILES>"
+ echo ""
+ echo " Report the license of the Mallard page files FILES. Each"
+ echo " matching page is reporting along with its status, reported"
+ echo " based on the href attribute of the license element. Common"
+ echo " licenses use a shortened identifier. Pages with multiple"
+ echo " licenses have the identifiers separated by spaces. Pages"
+ echo " with no license element report 'none'. Licenses with no"
+ echo " href attribute are reported as 'unknown'."
+ echo ""
+ echo "Options:"
+ echo " --only LICENSES Only show pages whose license is in LICENSES"
+ echo " --except LICENSES Exclude pages whose license is in LICENSES"
+ echo " --totals Show total counts for each license"
+ echo "LICENSES may be a comma- and/or space-separated list."
+ ) 1>&2
+}
yelp_usage_status () {
(
echo "Usage: yelp-check status <FILES>"
@@ -537,6 +558,64 @@ yelp_comments () {
done
}
+yelp_license_page () {
+ xsltproc --xinclude \
+ --stringparam only "$check_only" \
+ --stringparam except "$check_except" \
+ --stringparam totals "$check_totals" \
+ "$xsl_mal_license" "$1"
+}
+
+yelp_license () {
+ if [ "$#" = "0" -o "x$1" = "x--help" ]; then
+ yelp_usage_license
+ exit 1
+ fi
+ while [ "$#" != "0" ]; do
+ case "$1" in
+ "--only")
+ shift
+ check_only="$1"
+ shift
+ ;;
+ "--except")
+ shift
+ check_except="$1"
+ shift
+ ;;
+ "--totals")
+ check_totals="1"
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+ if [ "$#" = "0" -o "x$1" = "x--help" ]; then
+ yelp_usage_license
+ exit 1
+ fi
+ for xml in "$@"; do
+ ext=`echo "$1" | sed -e 's/.*\.//'`
+ if [ -d "$xml" ]; then
+ for page in "$xml"/*.page; do
+ yelp_license_page "$page" || gret="$?"
+ done
+ elif [ "x$ext" = "xpage" -o "x$ext" = "xcache" ]; then
+ yelp_license_page "$xml" || gret="$?"
+ else
+ echo "Unrecognized page " $xml 2>&1
+ exit 1
+ fi
+ done | if [ "x$check_totals" = "x1" ]; then
+ sort | uniq -c | sed -e 's/^ *//' | awk '{print $2 ": " $1}'
+ else
+ sort
+ fi
+ return 0
+}
+
yelp_status () {
if [ "$#" = "0" -o "x$1" = "x--help" ]; then
yelp_usage_status
@@ -730,6 +809,9 @@ case "x$cmd" in
"xorphans")
yelp_orphans "$@"
;;
+ "xlicense")
+ yelp_license "$@"
+ ;;
"xstatus")
yelp_status "$@"
;;
diff --git a/xslt/Makefile.am b/xslt/Makefile.am
index 5dd0ef4..d2dc1e3 100644
--- a/xslt/Makefile.am
+++ b/xslt/Makefile.am
@@ -5,6 +5,7 @@ xsl_DATA = \
mal-epub.xsl \
mal-opf.xsl \
mal-files.xsl \
+ mal-license.xsl \
mal-ncx.xsl \
mal-status.xsl \
mal-rng.xsl
diff --git a/xslt/mal-license.xsl b/xslt/mal-license.xsl
new file mode 100644
index 0000000..cf3a98d
--- /dev/null
+++ b/xslt/mal-license.xsl
@@ -0,0 +1,102 @@
+<xsl:stylesheet
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:mal="http://projectmallard.org/1.0/"
+ xmlns:str="http://exslt.org/strings"
+ xmlns:exsl="http://exslt.org/common"
+ version="1.0">
+
+<xsl:output method="text"/>
+
+<xsl:param name="only" select="''"/>
+<xsl:variable name="only_" select="concat(' ', translate($only, ',', ' '), ' ')"/>
+<xsl:param name="except" select="''"/>
+<xsl:variable name="except_" select="concat(' ', translate($except, ',', ' '), ' ')"/>
+<xsl:param name="totals" select="''"/>
+
+<xsl:template match="/">
+ <xsl:variable name="idents">
+ <xsl:if test="not(/mal:page/mal:info/mal:license)">
+ <ident>none</ident>
+ </xsl:if>
+ <xsl:for-each select="/mal:page/mal:info/mal:license">
+ <ident>
+ <xsl:call-template name="license.identifier"/>
+ </ident>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:variable name="display">
+ <xsl:for-each select="exsl:node-set($idents)/*">
+ <xsl:choose>
+ <xsl:when test="$only != ''">
+ <xsl:if test="contains($only_, concat(' ', ., ' '))">
+ <xsl:text>1</xsl:text>
+ </xsl:if>
+ </xsl:when>
+ <xsl:when test="$except != ''">
+ <xsl:if test="not(contains($except_, concat(' ', ., ' ')))">
+ <xsl:text>1</xsl:text>
+ </xsl:if>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>1</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:if test="$display != ''">
+ <xsl:choose>
+ <xsl:when test="$totals = ''">
+ <xsl:value-of select="concat(/mal:page/@id, ': ')"/>
+ <xsl:for-each select="exsl:node-set($idents)/*">
+ <xsl:if test="position() != 1">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
+ <xsl:value-of select="."/>
+ </xsl:for-each>
+ <xsl:text>
</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:for-each select="exsl:node-set($idents)/*">
+ <xsl:value-of select="."/>
+ <xsl:text>
</xsl:text>
+ </xsl:for-each>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template name="license.identifier">
+ <xsl:param name="href" select="@href"/>
+ <xsl:choose>
+ <xsl:when test="$href = ''">
+ <xsl:text>unknown</xsl:text>
+ </xsl:when>
+ <xsl:when test="starts-with($href, 'http://creativecommons.org/licenses/')">
+ <xsl:text>cc-</xsl:text>
+ <xsl:for-each select="str:split(substring-after($href, 'http://creativecommons.org/licenses/'), '/')">
+ <xsl:if test="position() != 1">
+ <xsl:text>-</xsl:text>
+ </xsl:if>
+ <xsl:value-of select="."/>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:when test="starts-with($href, 'http://www.gnu.org/licenses/')">
+ <xsl:variable name="basename">
+ <xsl:value-of select="substring-after($href, 'http://www.gnu.org/licenses/')"/>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="substring($basename, string-length($basename) - 4) = '.html'">
+ <xsl:value-of select="substring($basename, 1, string-length($basename) - 5)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$basename"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>unknown</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]