[damned-lies] Also update homepage info from doap file



commit d7d63f0b227cc8fa8bb848dddbc19432d3d8f823
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Oct 23 14:29:09 2010 +0200

    Also update homepage info from doap file

 docs/DataModel.odg                           |  Bin 27301 -> 26643 bytes
 stats/doap.py                                |   23 ++++++++++++++++++-----
 stats/models.py                              |   12 +++++++-----
 stats/tests/__init__.py                      |   11 +++++++++--
 stats/tests/git/gnome-hello/gnome-hello.doap |    1 +
 5 files changed, 35 insertions(+), 12 deletions(-)
---
diff --git a/docs/DataModel.odg b/docs/DataModel.odg
index 4e1fe8f..161a25a 100644
Binary files a/docs/DataModel.odg and b/docs/DataModel.odg differ
diff --git a/stats/doap.py b/stats/doap.py
index f011f2e..58ff618 100644
--- a/stats/doap.py
+++ b/stats/doap.py
@@ -4,9 +4,8 @@ from urllib import unquote
 
 from people.models import Person
 
-def parse_maintainers(doap_path):
-    tree = parse(doap_path)
-    maint_tags = tree.getroot().findall("{http://usefulinc.com/ns/doap#}maintainer";)
+def parse_maintainers(doap_tree):
+    maint_tags = doap_tree.getroot().findall("{http://usefulinc.com/ns/doap#}maintainer";)
     pers_attrs = [
         "{http://xmlns.com/foaf/0.1/}name";,
         "{http://xmlns.com/foaf/0.1/}mbox";,
@@ -19,14 +18,22 @@ def parse_maintainers(doap_path):
         maintainers.append({'name': name, 'email': unquote(mbox), 'account': uid})
     return maintainers
 
+def parse_homepage(doap_tree):
+    homepage_tag = doap_tree.getroot().find("{http://usefulinc.com/ns/doap#}homepage";)
+    if homepage_tag is not None:
+        return homepage_tag.attrib.get('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource')
+    return None
 
-def update_maintainers(module):
+def update_doap_infos(module):
     """ Should only be called inside an "update-stats" context of a master branch,
         so there is no need for any extra checkout/locking strategy """
     doap_path = os.path.join(module.get_head_branch().co_path(), "%s.doap" % module.name)
     if not os.access(doap_path, os.F_OK):
         return
-    doap_maintainers = parse_maintainers(doap_path)
+    tree = parse(doap_path)
+
+    # *********** Update maintainers
+    doap_maintainers = parse_maintainers(tree)
     current_maintainers = dict([(m.email, m) for m in module.maintainers.all()])
 
     # Using email as unique identifier
@@ -46,3 +53,9 @@ def update_maintainers(module):
     for key, maint in current_maintainers.items():
         # Drop maintainers not in doap file
         module.maintainers.remove(maint)
+
+    # *********** Update homepage
+    home = parse_homepage(tree)
+    if home and home != module.homepage:
+        module.homepage = home
+        module.save()
diff --git a/stats/models.py b/stats/models.py
index bda2667..5fda25d 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -34,7 +34,7 @@ from django.db import models, connection
 
 from common.fields import DictionaryField
 from stats import utils, signals
-from stats.doap import update_maintainers
+from stats.doap import update_doap_infos
 from people.models import Person
 from languages.models import Language
 
@@ -54,7 +54,8 @@ BRANCH_HEAD_NAMES = (
 
 class Module(models.Model):
     name = models.CharField(max_length=50)
-    homepage = models.URLField(null=True, blank=True)
+    homepage    = models.URLField(null=True, blank=True,
+                      help_text="Automatically updated if the module contains a doap file.")
     description = models.TextField(null=True, blank=True)
     comment = models.TextField(null=True, blank=True)
     bugs_base = models.CharField(max_length=50, null=True, blank=True)
@@ -66,7 +67,8 @@ class Module(models.Model):
     vcs_web = models.URLField()
 
     maintainers = models.ManyToManyField(Person, db_table='module_maintainer',
-        related_name='maintains_modules', blank=True)
+        related_name='maintains_modules', blank=True,
+        help_text="Automatically updated if the module contains a doap file.")
 
     class Meta:
         db_table = 'module'
@@ -159,7 +161,7 @@ class Branch(models.Model):
     vcs_subpath = models.CharField(max_length=50, null=True, blank=True)
     module      = models.ForeignKey(Module)
     weight      = models.IntegerField(default=0, help_text="Smaller weight is displayed first")
-    file_hashes = DictionaryField(default='', blank=True)
+    file_hashes = DictionaryField(default='', blank=True, editable=False)
     # 'releases' is the backward relation name from Release model
 
     # May be set to False by test suite
@@ -478,7 +480,7 @@ class Branch(models.Model):
                         stat.information_set.add(Information(type=err[0], description=err[1]))
             # Check if doap file changed
             if self.file_changed("%s.doap" % self.module.name):
-                update_maintainers(self.module)
+                update_doap_infos(self.module)
 
     def _exists(self):
         """ Determine if branch (self) already exists (i.e. already checked out) on local FS """
diff --git a/stats/tests/__init__.py b/stats/tests/__init__.py
index 829d34d..f7dafa5 100644
--- a/stats/tests/__init__.py
+++ b/stats/tests/__init__.py
@@ -188,12 +188,19 @@ class ModuleTestCase(TestCase):
         self.assertFalse(self.mod.get_head_branch().file_changed("gnome-hello.doap"))
 
     def testUpdateMaintainersFromDoapFile(self):
-        from stats.doap import update_maintainers
+        from stats.doap import update_doap_infos
         from people.models import Person
         settings.SCRATCHDIR = os.path.dirname(os.path.abspath(__file__))
         # Add a maintainer which will be removed
         pers = Person(username="toto")
         pers.save()
         self.mod.maintainers.add(pers)
-        update_maintainers(self.mod)
+        update_doap_infos(self.mod)
         self.assertEquals(self.mod.maintainers.count(), 6)
+
+    def testUpdateDoapInfos(self):
+        from stats.doap import update_doap_infos
+        settings.SCRATCHDIR = os.path.dirname(os.path.abspath(__file__))
+        update_doap_infos(self.mod)
+        self.assertEquals(self.mod.homepage, "http://git.gnome.org/browse/gnome-hello";)
+
diff --git a/stats/tests/git/gnome-hello/gnome-hello.doap b/stats/tests/git/gnome-hello/gnome-hello.doap
index 02eea05..ddf9765 100644
--- a/stats/tests/git/gnome-hello/gnome-hello.doap
+++ b/stats/tests/git/gnome-hello/gnome-hello.doap
@@ -6,6 +6,7 @@
 
   <name xml:lang="en">gnome-hello</name>
   <shortdesc xml:lang="en">GNOME demo programme</shortdesc>
+  <homepage rdf:resource="http://git.gnome.org/browse/gnome-hello"; />
   <mailing-list rdf:resource="http://mail.gnome.org/mailman/listinfo/desktop-devel-list"; />
   <download-page rdf:resource="http://download.gnome.org/sources/gnome-hello/"; />
   <category rdf:resource="http://api.gnome.org/doap-extensions#development"; />



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