labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1519553 - in /labs/panopticon: src/asf/data/projects.py src/asf/utils/constants.py tests/test_projects.py
Date Tue, 03 Sep 2013 04:32:48 GMT
Author: adc
Date: Tue Sep  3 04:32:47 2013
New Revision: 1519553

URL: http://svn.apache.org/r1519553
Log:
Load info about PMCs

Added:
    labs/panopticon/src/asf/data/projects.py
    labs/panopticon/src/asf/utils/constants.py
    labs/panopticon/tests/test_projects.py

Added: labs/panopticon/src/asf/data/projects.py
URL: http://svn.apache.org/viewvc/labs/panopticon/src/asf/data/projects.py?rev=1519553&view=auto
==============================================================================
--- labs/panopticon/src/asf/data/projects.py (added)
+++ labs/panopticon/src/asf/data/projects.py Tue Sep  3 04:32:47 2013
@@ -0,0 +1,96 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+import os
+import xml.etree.ElementTree as etree
+
+from restkit import Resource
+
+from asf.utils.constants import VALID_URL_REGEX
+
+
+PMC_LIST_URL_ROOT = 'https://svn.apache.org/repos/asf/infrastructure/site-tools/trunk/projects'
+PMC_LIST_URL = os.path.join(PMC_LIST_URL_ROOT, 'pmc_list.xml')
+
+PMCS = None
+
+ASF_EXT_NS = 'http://projects.apache.org/ns/asfext#'
+FOAF_NS = 'http://xmlns.com/foaf/0.1/'
+RDF_NS = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
+
+
+class Pmc(object):
+    def __init__(self, about, name, homepage, charter):
+        self.about = about
+        self.name = name
+        self.homepage = homepage
+        self.charter = charter
+
+    def as_tuple(self):
+        return (self.about, self.name, self.homepage, self.charter)
+
+    def __eq__(self, other):
+        return self.as_tuple() == other.as_tuple()
+
+    def __hash__(self):
+        return hash(self.as_tuple())
+
+    def __repr__(self):
+        return 'Podling(%r, %r, %r, %r)' % self.as_tuple()
+
+    @classmethod
+    def from_rdf(cls, rdf_element):
+        pmc_element = rdf_element.find('{%s}PMC' % ASF_EXT_NS)
+        about = pmc_element.get('{%s}about' % RDF_NS)
+        name = pmc_element.find('{%s}name' % ASF_EXT_NS).text
+        homepage_element = pmc_element.find('{%s}homepage' % FOAF_NS)
+        if homepage_element is not None:
+            homepage = homepage_element.get('{%s}resource' % RDF_NS)
+        else:
+            homepage = None
+
+        charter_element = pmc_element.find('{%s}charter' % ASF_EXT_NS)
+        if charter_element is not None:
+            charter = charter_element.text
+        else:
+            charter = None
+
+        return cls(about, name, homepage, charter)
+
+    @classmethod
+    def from_file_handle(cls, file_handle):
+        return cls.from_rdf(etree.parse(file_handle).getroot())
+
+
+def get_pmcs():
+    global PMCS
+    if PMCS is None:
+        PMCS = {}
+
+        for list_element in etree.parse(Resource(PMC_LIST_URL).get().body_stream()).getroot():
+            if VALID_URL_REGEX.match(list_element.text):
+                rdf_url = list_element.text
+            else:
+                rdf_url = os.path.join(PMC_LIST_URL_ROOT, list_element.text)
+
+            pmc = Pmc.from_file_handle(Resource(rdf_url).get().body_stream())
+
+            PMCS[pmc.about] = pmc
+
+    return PMCS
+

Added: labs/panopticon/src/asf/utils/constants.py
URL: http://svn.apache.org/viewvc/labs/panopticon/src/asf/utils/constants.py?rev=1519553&view=auto
==============================================================================
--- labs/panopticon/src/asf/utils/constants.py (added)
+++ labs/panopticon/src/asf/utils/constants.py Tue Sep  3 04:32:47 2013
@@ -0,0 +1,28 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+import re
+
+
+VALID_URL_REGEX = re.compile(
+    r'^(?:http|ftp)s?://' # http:// or https://
+    r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
#domain...
+    r'localhost|' #localhost...
+    r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
+    r'(?::\d+)?' # optional port
+    r'(?:/?|[/?]\S+)$', re.IGNORECASE)

Added: labs/panopticon/tests/test_projects.py
URL: http://svn.apache.org/viewvc/labs/panopticon/tests/test_projects.py?rev=1519553&view=auto
==============================================================================
--- labs/panopticon/tests/test_projects.py (added)
+++ labs/panopticon/tests/test_projects.py Tue Sep  3 04:32:47 2013
@@ -0,0 +1,26 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+from asf.data.projects import get_pmcs
+
+
+def test_get_pmcs():
+    pmcs =  get_pmcs()
+
+    assert pmcs
+    assert 'geronimo' in pmcs



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message