[sysadmin-bin: 97/168] Validate DOAP files



commit 6bc661b2750e477559db0af3e1cee38ce02ef3a3
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Fri Apr 24 18:44:10 2009 -0400

    Validate DOAP files
    
    validate-doap: GNOME module DOAP file validation program
    pre-receive-check-maintainers: If a DOAP file is found, validate it and
      ignore MAINTAINERS, otherwise, validate MAINTAINERS

 pre-receive-check-maintainers |   36 +++++++++++++--
 validate-doap                 |   99 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 130 insertions(+), 5 deletions(-)
---
diff --git a/pre-receive-check-maintainers b/pre-receive-check-maintainers
index 42e42f1..441e071 100755
--- a/pre-receive-check-maintainers
+++ b/pre-receive-check-maintainers
@@ -1,5 +1,19 @@
 #!/bin/bash
 
+# This checks to see if the module has maintainer information. Maintainer
+# information can be provided one of two ways:
+#
+#  - A <modulename>.doap file
+#  - A MAINTAINERS file (deprecated)
+
+BINDIR=/home/admin/gitadmin-bin
+
+GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
+
+# Use the directory name with .git stripped as a short identifier
+absdir=$(cd $GIT_DIR && pwd)
+projectshort=$(basename ${absdir%.git})
+
 check_maintainers() {
     oldrev=$1
     newrev=$2
@@ -12,12 +26,12 @@ check_maintainers() {
     fi
 
     if [ "$branchname" != "master" ] ; then
-	# MAINTAINERS only required on the master branch
+	# maintainer info only required on the master branch
 	return 0
     fi
 
     if expr $oldrev : "^0\+$" > /dev/null 2>&1; then
-        # Don't require MAINTAINERS for initial imports; keeps things simple
+        # Don't require maintainer info for initial imports; keeps things simple
 	return 0
     fi
 
@@ -31,9 +45,21 @@ check_maintainers() {
 	return 0
     fi
 
-    if ! git cat-file blob $newrev:MAINTAINERS 2>/dev/null | /bin/grep -q "^Userid:" ; then
-        echo "A valid MAINTAINERS file is required. See http://live.gnome.org/MaintainersCorner#maintainers"; >&2
-        return 1
+    if git cat-file -e $newrev:$projectshort.doap 2>/dev/null ; then
+	# There's a DOAP file. For performance reasons and to allow having fairly
+	# strict validation without being annoying, we only validate the DOAP file
+        # if it changed
+	if git diff-tree --name-only -r $oldrev $newrev | grep -q $projectshort.doap ; then
+	    if ! git cat-file blob $newrev:$projectshort.doap | $BINDIR/validate-doap $projectshort ; then
+		return 1
+	    fi
+	fi
+    else
+        # See if there is a old-style MAINTAINERS file
+	if ! git cat-file blob $newrev:MAINTAINERS 2>/dev/null | /bin/grep -q "^Userid:" ; then
+            echo "A valid $projectshort.doap file is required. See http://live.gnome.org/MaintainersCorner#maintainers"; >&2
+            return 1
+	fi
     fi
 }
 
diff --git a/validate-doap b/validate-doap
new file mode 100755
index 0000000..1c3e546
--- /dev/null
+++ b/validate-doap
@@ -0,0 +1,99 @@
+#!/usr/bin/python
+
+from cStringIO import StringIO
+import os
+import sys
+
+script_path = os.path.realpath(os.path.abspath(sys.argv[0]))
+script_dir = os.path.dirname(script_path)
+sys.path.insert(0, script_dir)
+
+import semi_rdf
+
+DOAP = "http://usefulinc.com/ns/doap#";
+FOAF = "http://xmlns.com/foaf/0.1/";
+GNOME = "http://api.gnome.org/doap-extensions#";
+
+groups = {
+    (GNOME + 'admin'): 'admin',
+    (GNOME + 'bindings'): 'platform',
+    (GNOME + 'deprecated'): 'deprecated',
+    (GNOME + 'desktop'): 'desktop',
+    (GNOME + 'development'): 'development',
+    (GNOME + 'infrastructure'): 'infrastructure',
+    (GNOME + 'platform'): 'platform',
+    (GNOME + 'productivity'): 'productivity'
+    }
+
+def die(message):
+    print >>sys.stderr, "---"
+    print >>sys.stderr, "ERROR: %s.doap is not valid:" % modulename
+    print >>sys.stderr, "  ", message
+    print >>sys.stderr
+    print >>sys.stderr, "Please see:"
+    print >>sys.stderr, "   http://live.gnome.org/MaintainersCorner#maintainers";
+    print >>sys.stderr, "---"
+    sys.exit(1)
+
+def is_literal(value):
+    return isinstance(value, basestring) and not isinstance(value, semi_rdf.UrlResource)
+
+def is_resource(value):
+    # Should really accept a node with rdf:about, but the rest of our
+    # code can't handle that, so we just require rdf:resource
+    return isinstance(value, semi_rdf.UrlResource)
+
+if len(sys.argv) < 2:
+    print >>sys.stderr, "Usage: validate-doap <modulename>"
+    sys.exit(1)
+
+modulename = sys.argv[1]
+
+nodes = semi_rdf.read_rdf(sys.stdin)
+seen_project = False
+for node in nodes:
+    if node.name != (DOAP, "Project"):
+        continue
+
+    if seen_project:
+        die("Multiple doap:Project nodes")
+
+    shortdesc = node.find_property((DOAP, "shortdesc"))
+    if not shortdesc:
+        die("Missing required doap:shortdesc property")
+    if not is_literal(shortdesc):
+        die("Invalid doap:shortdesc property (should be a string literal)")
+
+    group = node.find_property((DOAP, "category"))
+    if group:
+        if not is_resource(group):
+            die("Invalid doap:category property (should be an URL)")
+
+        if not group in groups:
+            die("doap:category property should be one of the standard GNOME categories")
+
+    have_maintainer = False
+    for (n, l, v) in node.properties:
+        if n == (DOAP, "maintainer"):
+            maintainer = v
+            name = maintainer.find_property((FOAF, "name"))
+            if name is None:
+                die("doap:maintainer property value should have a foaf:name property")
+            if not is_literal(name):
+                die("Invalid foaf:name property (should be a string literal)")
+            uid = maintainer.find_property((GNOME, "userid"))
+            if uid is not None:
+                if not is_literal(uid):
+                    die("Invalid gnome:userid property (should be a string literal)")
+                have_maintainer = True
+            mbox = maintainer.find_property((FOAF, "mbox"))
+            if mbox is not None:
+                if not is_resource(mbox):
+                    die("Invalid foaf:mbox property (should be an URL)")
+                if not mbox.startswith("mailto:";):
+                    die("Invalid foaf:mbox property should be a mailto: URL")
+
+    if not have_maintainer:
+        die("Must have at least one doap:maintainer property with a gnome:userid property")
+
+    seen_project = True



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