[damned-lies] Support doap files where root is <rdf:RDF>
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Support doap files where root is <rdf:RDF>
- Date: Tue, 26 Oct 2010 20:32:14 +0000 (UTC)
commit a094cacd0933a75f8246ba8b4ba0b1d279d3a6ab
Author: Claude Paroz <claude 2xlibre net>
Date: Tue Oct 26 22:31:43 2010 +0200
Support doap files where root is <rdf:RDF>
stats/doap.py | 61 +++++++++++++++++++++++++++++++++-----------------------
1 files changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/stats/doap.py b/stats/doap.py
index e3f7e04..427c84a 100644
--- a/stats/doap.py
+++ b/stats/doap.py
@@ -5,29 +5,40 @@ from urllib import unquote
from people.models import Person
-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",
- "{http://api.gnome.org/doap-extensions#}userid"
- ]
- maintainers = []
- for maint in maint_tags:
- name, mbox, uid = [maint[0].find(attr) for attr in pers_attrs]
- 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
+class DoapParser(object):
+ def __init__(self, doap_path):
+ self.tree = parse(doap_path)
+ self.project_root = self.tree.getroot()
+ if not self.project_root.tag.endswith("Project"):
+ # Try to get Project from root children (root might be <rdf:RDF>)
+ for child in self.project_root.getchildren():
+ if child.tag.endswith("Project"):
+ self.project_root = child
+ break
-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 parse_maintainers(self):
+ maint_tags = self.project_root.findall("{http://usefulinc.com/ns/doap#}maintainer")
+ pers_attrs = [
+ "{http://xmlns.com/foaf/0.1/}name",
+ "{http://xmlns.com/foaf/0.1/}mbox",
+ "{http://api.gnome.org/doap-extensions#}userid"
+ ]
+ maintainers = []
+ for maint in maint_tags:
+ name, mbox, uid = [maint[0].find(attr) for attr in pers_attrs]
+ 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(self):
+ homepage_tag = self.project_root.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_doap_infos(module):
""" Should only be called inside an "update-stats" context of a master branch,
@@ -35,13 +46,13 @@ def update_doap_infos(module):
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
- tree = parse(doap_path)
+ tree = DoapParser(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)
+ doap_maintainers = tree.parse_maintainers()
current_maintainers = dict([(m.email or m.username, m) for m in module.maintainers.all()])
# Using email or username as unique identifier
@@ -65,7 +76,7 @@ def update_doap_infos(module):
module.maintainers.remove(maint)
# *********** Update homepage
- home = parse_homepage(tree)
+ home = tree.parse_homepage()
if home and home != module.homepage:
module.homepage = home
module.save()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]