[damned-lies] Provide for cases where maintainer has no email or no id in doap file



commit ed5a1071cf189edf9585772107f58b069767fd2f
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Oct 23 15:41:53 2010 +0200

    Provide for cases where maintainer has no email or no id in doap file

 README                                       |    2 +-
 stats/doap.py                                |   26 ++++++++++++++++++--------
 stats/tests/__init__.py                      |    2 ++
 stats/tests/git/gnome-hello/gnome-hello.doap |    3 ---
 4 files changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/README b/README
index a4e5561..f220bb1 100644
--- a/README
+++ b/README
@@ -23,7 +23,7 @@ Requirements
     * jQuery growfield (http://kuindji.com/jquery/growfield/growfield.xml)
       in /media/js/jquery.growfield2.js
 
-4 - South >= 0.6 - http://south.aeracode.org/
+4 - South >= 0.7 - http://south.aeracode.org/
     South is a Django extension that allows you to track changes in your models
     over time, and to update the database to reflect those changes.
 
diff --git a/stats/doap.py b/stats/doap.py
index 58ff618..d859ceb 100644
--- a/stats/doap.py
+++ b/stats/doap.py
@@ -1,4 +1,5 @@
 import os
+import re
 from xml.etree.ElementTree import parse
 from urllib import unquote
 
@@ -14,8 +15,12 @@ def parse_maintainers(doap_tree):
     maintainers = []
     for maint in maint_tags:
         name, mbox, uid = [maint[0].find(attr) for attr in pers_attrs]
-        name, mbox, uid = name.text, mbox.items()[0][1].replace("mailto:";, ""), uid.text
-        maintainers.append({'name': name, 'email': unquote(mbox), 'account': uid})
+        maint = {'name': name.text, 'email': None, 'account': None}
+        if mbox is not None:
+            maint['email'] = unquote(mbox.items()[0][1].replace("mailto:";, ""))
+        if uid is not None:
+            maint['account'] = uid.text
+        maintainers.append(maint)
     return maintainers
 
 def parse_homepage(doap_tree):
@@ -33,19 +38,24 @@ def update_doap_infos(module):
     tree = parse(doap_path)
 
     # *********** Update maintainers
+    def slugify(val):
+        value = unicode(re.sub('[^\w\s-]', '', val).strip().lower())
+        return re.sub('[-\s]+', '-', value)
     doap_maintainers = parse_maintainers(tree)
-    current_maintainers = dict([(m.email, m) for m in module.maintainers.all()])
+    current_maintainers = dict([(m.email or m.username, m) for m in module.maintainers.all()])
 
-    # Using email as unique identifier
+    # Using email or username as unique identifier
     for maint in doap_maintainers:
-        if maint['email'] in current_maintainers.keys():
-            del current_maintainers[maint['email']]
+        maint_key = maint['email'] or maint['account'] or slugify(maint['name'])
+        if maint_key in current_maintainers.keys():
+            del current_maintainers[maint_key]
         else:
             # Add new maintainer
+            query_param = {maint['email'] and 'email' or 'username': maint_key }
             try:
-                pers = Person.objects.get(email=maint['email'])
+                pers = Person.objects.get(**query_param)
             except Person.DoesNotExist:
-                pers = Person(username=maint['account'], email=maint['email'],
+                pers = Person(username=maint['account'] or slugify(maint['name']), email=maint['email'] or '',
                               password='!', svn_account=maint['account'], last_name=maint['name'])
                 pers.save()
             module.maintainers.add(pers)
diff --git a/stats/tests/__init__.py b/stats/tests/__init__.py
index f7dafa5..2c29d85 100644
--- a/stats/tests/__init__.py
+++ b/stats/tests/__init__.py
@@ -197,6 +197,8 @@ class ModuleTestCase(TestCase):
         self.mod.maintainers.add(pers)
         update_doap_infos(self.mod)
         self.assertEquals(self.mod.maintainers.count(), 6)
+        claude = self.mod.maintainers.get(email='claude 2xlibre net')
+        self.assertEquals(claude.username, 'claudep')
 
     def testUpdateDoapInfos(self):
         from stats.doap import update_doap_infos
diff --git a/stats/tests/git/gnome-hello/gnome-hello.doap b/stats/tests/git/gnome-hello/gnome-hello.doap
index ddf9765..21b51a2 100644
--- a/stats/tests/git/gnome-hello/gnome-hello.doap
+++ b/stats/tests/git/gnome-hello/gnome-hello.doap
@@ -16,15 +16,12 @@
   <maintainer>
     <foaf:Person>
       <foaf:name>Andre Klapper</foaf:name>
-      <foaf:mbox rdf:resource="mailto:a9016009%40gmx.de"; />
-      <gnome:userid>aklapper</gnome:userid>
     </foaf:Person>
   </maintainer>
 
   <maintainer>
     <foaf:Person>
       <foaf:name>Baptiste Mille-Mathias</foaf:name>
-      <foaf:mbox rdf:resource="mailto:baptiste.millemathias%40gmail.com"; />
       <gnome:userid>baptistem</gnome:userid>
     </foaf:Person>
   </maintainer>



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