incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [7/9] git commit: [#7208] ticket:556 Use xml.etree.ElementTree instead of datatree
Date Wed, 12 Mar 2014 20:48:05 GMT
[#7208] ticket:556 Use xml.etree.ElementTree instead of datatree


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/42bb8c0c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/42bb8c0c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/42bb8c0c

Branch: refs/heads/master
Commit: 42bb8c0c948c21f297223c5b4d5db3b60379c05b
Parents: 3f4a1fb
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Mar 10 20:12:24 2014 +0200
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed Mar 12 20:47:55 2014 +0000

----------------------------------------------------------------------
 Allura/allura/app.py                        | 21 +++----
 Allura/allura/model/project.py              | 75 +++++++++++-------------
 Allura/allura/tests/functional/test_rest.py | 11 ----
 requirements-common.txt                     |  1 -
 4 files changed, 42 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/42bb8c0c/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index f95e5f9..315ddc4 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -20,6 +20,7 @@ import logging
 from urllib import basejoin
 from cStringIO import StringIO
 from collections import defaultdict
+from xml.etree import ElementTree as ET
 
 import pkg_resources
 from tg import expose, redirect, flash, validate
@@ -29,7 +30,6 @@ from paste.deploy.converters import asbool, asint
 from bson import ObjectId
 from bson.errors import InvalidId
 from formencode import validators as V
-from datatree import Node
 
 from ming.orm import session
 from ming.utils import LazyProperty
@@ -624,22 +624,17 @@ class Application(object):
         """
         raise NotImplementedError, 'bulk_export'
 
-    def doap(self):
+    def doap(self, parent):
         """App's representation for DOAP API.
 
-        :rtype: datatree.Node
+        :param parent: Element to contain the results
+        :type parent: xml.etree.ElementTree.Element or xml.etree.ElementTree.SubElement
         """
-        app = Node('sf:Feature')
-        app << Node('name', self.config.options.mount_label)
-        app << Node('foaf:page', **{'rdf:resource': h.absurl(self.url)})
-        return Node('sf:feature') << app
+        feature = ET.SubElement(parent, 'sf:feature')
+        feature = ET.SubElement(feature, 'sf:Feature')
+        ET.SubElement(feature, 'name').text = self.config.options.mount_label
+        ET.SubElement(feature, 'foaf:page', {'rdf:resource': h.absurl(self.url)})
 
-    def additional_doap_entries(self):
-        """Additional DOAP entries to include in project's DOAP represention.
-
-        :rtype: list of datatree.Node
-        """
-        return []
 
 class DefaultAdminController(BaseController):
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/42bb8c0c/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index a4883ed..c7f0ee0 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -21,13 +21,13 @@ from datetime import datetime
 from copy import deepcopy
 import urllib
 import re
+from xml.etree import ElementTree as ET
 
 from tg import config
 from pylons import tmpl_context as c, app_globals as g
 from pylons import request
 from paste.deploy.converters import asbool
 import formencode as fe
-from datatree import Node
 
 from ming import schema as S
 from ming.utils import LazyProperty
@@ -985,11 +985,11 @@ class Project(MappedClass, ActivityNode, ActivityObject):
         )
 
     def doap(self):
-        root = Node('rdf:RDF', **{
+        root = ET.Element('rdf:RDF', {
             'xmlns:rdf': "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
             'xmlns:rdfs': "http://www.w3.org/2000/01/rdf-schema#",
         })
-        p = Node('Project', **{
+        project = ET.SubElement(root, 'Project', {
             'xmlns': "http://usefulinc.com/ns/doap#",
             'xmlns:foaf': "http://xmlns.com/foaf/0.1/",
             'xmlns:sf': "http://sourceforge.net/api/sfelements.rdf#",
@@ -998,37 +998,29 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             'xmlns:beer': "http://www.purl.org/net/ontology/beer.owl#",
             'rdf:about': "http://sourceforge.net/api/project/name/vivo/doap#",
         })
-        root << p
         # Basic fields
-        p << Node('name', self.name)
-        p << Node('sf:shortname', self.shortname)
-        p << Node('sf:id', str(self._id))
-        p << Node('sf:private', self.private)
-        p << Node('created', )
-        p << Node('shortdesc', self.short_description, **{'xml:lang': 'en'})
-        p << Node('description', self.description, **{'xml:lang': 'en'})
+        ET.SubElement(project, 'name').text = self.name
+        ET.SubElement(project, 'sf:shortname').text = self.shortname
+        ET.SubElement(project, 'sf:id').text = str(self._id)
+        ET.SubElement(project, 'sf:private').text = self.private
+        ET.SubElement(project, 'shortdesc', {'xml:lang': 'en'}).text = self.short_description
+        ET.SubElement(project, 'description', {'xml:lang': 'en'}).text = self.description
         if self.external_homepage:
-            p << Node('homepage', **{'rdf:resource': self.external_homepage})
-
-        # Additional entries provided by tools
-        apps = [self.app_instance(ac) for ac in self.app_configs if h.has_access(ac, 'read')]
-        for app in apps:
-            for entry in app.additional_doap_entries():
-                p << entry
+            ET.SubElement(project, 'homepage', {'rdf:resource': self.external_homepage})
 
         # Categories
         for cat in TroveCategory.query.find({'_id': {'$in': self.trove_audience}}):
-            p << Node('audience', cat.fullname)
+            ET.SubElement(project, 'audience').text = cat.fullname
         for cat in TroveCategory.query.find({'_id': {'$in': self.trove_os}}):
-            p << Node('os', cat.fullname)
+            ET.SubElement(project, 'os').text = cat.fullname
         for cat in TroveCategory.query.find({'_id': {'$in': self.trove_language}}):
-            p << Node('programming-language', cat.fullname)
+            ET.SubElement(project, 'programming-language').text = cat.fullname
         for cat in TroveCategory.query.find({'_id': {'$in': self.trove_license}}):
-            p << Node('license', cat.fullname)
+            ET.SubElement(project, 'license').text = cat.fullname
         for cat in TroveCategory.query.find({'_id': {'$in': self.trove_environment}}):
-            p << Node('sf:environment', cat.fullname)
+            ET.SubElement(project, 'sf:environment').text = cat.fullname
         for cat in TroveCategory.query.find({'_id': {'$in': self.trove_root_database}}):
-            p << Node('sf:database', cat.fullname)
+            ET.SubElement(project, 'sf:database').text = cat.fullname
         all_troves = (
             self.trove_root_database +
             self.trove_developmentstatus +
@@ -1041,41 +1033,42 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             self.trove_environment
         )
         for cat in TroveCategory.query.find({'_id': {'$in': all_troves}}):
-            p << Node('category', **{'rdf:resource': 'http://sourceforge.net/api/trove/index/rdf#%s'
% cat.trove_cat_id})
+            ET.SubElement(project, 'category', {'rdf:resource': 'http://sourceforge.net/api/trove/index/rdf#%s'
% cat.trove_cat_id})
 
         # Awards
         for a in self.accolades:
-            award = Node('beer:Award')
-            award << Node('beer:awardCategory', a.award.full)
-            award << Node('beer:awardedAt', a.granted_by_neighborhood.name)
-            p << (Node('sf:awarded') << award)
+            award = ET.SubElement(project, 'sf:awarded')
+            award = ET.SubElement(award, 'beer:Award')
+            ET.SubElement(award, 'beer:awardCategory').text = a.award.full
+            ET.SubElement(award, 'beer:awardedAt').text = a.granted_by_neighborhood.name
 
         # Maintainers
         for u in self.admins():
-            person = Node('foaf:Person', **{
+            person = ET.SubElement(project, 'maintainer')
+            person = ET.SubElement(person, 'foaf:Person', {
                 'xmlns:foaf': "http://xmlns.com/foaf/0.1/",
                 'xmlns:rdf': "http://www.w3.org/1999/02/22-rdf-syntax-ns#"})
-            person << Node('foaf:name', u.display_name)
-            person << Node('foaf:nick', u.username)
-            person << Node('foaf:homepage', **{'rdf:resource': h.absurl(u.url())})
-            p << (Node('maintainer') << person)
+            ET.SubElement(person, 'foaf:name').text = u.display_name
+            ET.SubElement(person, 'foaf:nick').text = u.username
+            ET.SubElement(person, 'foaf:homepage', {'rdf:resource': h.absurl(u.url())})
 
         # Developers
         devs = [u for u in self.users_with_role('Developer') if u not in self.admins()]
         for u in devs:
-            person = Node('foaf:Person', **{
+            person = ET.SubElement(project, 'developer')
+            person = ET.SubElement(person, 'foaf:Person', {
                 'xmlns:foaf': "http://xmlns.com/foaf/0.1/",
                 'xmlns:rdf': "http://www.w3.org/1999/02/22-rdf-syntax-ns#"})
-            person << Node('foaf:name', u.display_name)
-            person << Node('foaf:nick', u.username)
-            person << Node('foaf:homepage', **{'rdf:resource': h.absurl(u.url())})
-            p << (Node('developer') << person)
+            ET.SubElement(person, 'foaf:name').text = u.display_name
+            ET.SubElement(person, 'foaf:nick').text = u.username
+            ET.SubElement(person, 'foaf:homepage', {'rdf:resource': h.absurl(u.url())})
 
         # Basic tool info
+        apps = [self.app_instance(ac) for ac in self.app_configs if h.has_access(ac, 'read')]
         for app in apps:
-            p << app.doap()
+            app.doap(project)
 
-        return root.render(as_root=True)
+        return ET.tostring(root, encoding='utf-8')
 
 
 class AppConfig(MappedClass, ActivityObject):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/42bb8c0c/Allura/allura/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_rest.py b/Allura/allura/tests/functional/test_rest.py
index 500e88f..52d33ea 100644
--- a/Allura/allura/tests/functional/test_rest.py
+++ b/Allura/allura/tests/functional/test_rest.py
@@ -23,7 +23,6 @@ from pylons import app_globals as g
 import mock
 from nose.tools import assert_equal, assert_in, assert_not_in
 from ming.odm import ThreadLocalODMSession
-from datatree import Node
 
 from allura.tests import decorators as td
 from alluratest.controller import TestRestApiBase
@@ -280,13 +279,3 @@ class TestDoap(TestRestApiBase):
                  for t in tools]
         assert_in(('Tickets', 'http://localhost/p/test/bugs/'), tools)
         assert_not_in(('Tickets', 'http://localhost/p/test/private-bugs/'), tools)
-
-    @td.with_tool('test', 'Tickets', 'bugs')
-    def test_tools_additional_entries(self):
-        with mock.patch.object(ForgeTrackerApp, 'additional_doap_entries') as add:
-            add.return_value = [Node('additional-entry1', 'some text1'),
-                                Node('additional-entry2', 'some text2'),]
-            r = self.app.get('/rest/p/test?doap')
-        p = r.xml.find(self.ns + 'Project')
-        assert_equal(p.find(self.ns + 'additional-entry1').text, 'some text1')
-        assert_equal(p.find(self.ns + 'additional-entry2').text, 'some text2')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/42bb8c0c/requirements-common.txt
----------------------------------------------------------------------
diff --git a/requirements-common.txt b/requirements-common.txt
index 03ad5f3..7d8e70e 100644
--- a/requirements-common.txt
+++ b/requirements-common.txt
@@ -39,7 +39,6 @@ python-oembed==0.2.1
 requests==2.0.0
 oauthlib==0.4.2
 requests-oauthlib==0.4.0
-datatree==0.1.8.1
 
 # for taskd proc name switching
 setproctitle==1.1.7


Mime
View raw message