[OpenLayers-Commits] r7470 - trunk/openlayers/tools
commits at openlayers.org
commits at openlayers.org
Mon Jul 7 10:32:55 EDT 2008
Author: tschaub
Date: 2008-07-07 10:32:55 -0400 (Mon, 07 Jul 2008)
New Revision: 7470
Modified:
trunk/openlayers/tools/exampleparser.py
Log:
Adding title, id, updated, and author elements for valid atom.
Modified: trunk/openlayers/tools/exampleparser.py
===================================================================
--- trunk/openlayers/tools/exampleparser.py 2008-07-07 13:44:56 UTC (rev 7469)
+++ trunk/openlayers/tools/exampleparser.py 2008-07-07 14:32:55 UTC (rev 7470)
@@ -6,6 +6,7 @@
import urllib2
import time
from xml.dom.minidom import Document
+from xml.etree import ElementTree
missing_deps = False
try:
@@ -14,6 +15,8 @@
except ImportError, E:
missing_deps = E
+feedName = "example-list.xml"
+feedPath = "http://openlayers.org/dev/examples/"
def getListOfOnlineExamples(baseUrl):
"""
@@ -82,36 +85,69 @@
classes = getRelatedClasses(html)
d['classes'] = classes
return d
+
+def getSvnInfo(path):
+ h = os.popen("svn info %s --xml" % path)
+ tree = ElementTree.fromstring(h.read())
+ h.close()
+ d = {
+ 'url': tree.findtext('entry/url'),
+ 'author': tree.findtext('entry/commit/author'),
+ 'date': tree.findtext('entry/commit/date')
+ }
+ return d
def createFeed(examples):
doc = Document()
- feed = doc.createElementNS("http://www.w3.org/2005/Atom", "feed")
- feed.setAttribute("xmlns", "http://www.w3.org/2005/Atom") #ug, is this for real??
- for example in examples:
- s = os.stat("../examples/" + example["example"])
- example["modified"] = s.st_mtime
+ atomuri = "http://www.w3.org/2005/Atom"
+ feed = doc.createElementNS(atomuri, "feed")
+ feed.setAttribute("xmlns", atomuri)
+ title = doc.createElementNS(atomuri, "title")
+ title.appendChild(doc.createTextNode("OpenLayers Examples"))
+ feed.appendChild(title)
+ link = doc.createElementNS(atomuri, "link")
+ link.setAttribute("rel", "self")
+ link.setAttribute("href", feedPath + feedName)
+ modtime = time.strftime("%Y-%m-%dT%I:%M:%SZ", time.gmtime())
+ id = doc.createElementNS(atomuri, "id")
+ id.appendChild(doc.createTextNode("%s%s#%s" % (feedPath, feedName, modtime)))
+ feed.appendChild(id)
+
+ updated = doc.createElementNS(atomuri, "updated")
+ updated.appendChild(doc.createTextNode(modtime))
+ feed.appendChild(updated)
+
examples.sort(key=lambda x:x["modified"])
for example in sorted(examples, key=lambda x:x["modified"], reverse=True):
- entry = doc.createElementNS("http://www.w3.org/2005/Atom", "entry")
+ entry = doc.createElementNS(atomuri, "entry")
- title = doc.createElementNS("http://www.w3.org/2005/Atom", "title")
+ title = doc.createElementNS(atomuri, "title")
title.appendChild(doc.createTextNode(example["title"] or example["example"]))
entry.appendChild(title)
- link = doc.createElementNS("http://www.w3.org/2005/Atom", "link")
- link.setAttribute("href", "http://openlayers.org/dev/examples/%s" % example["example"])
+ link = doc.createElementNS(atomuri, "link")
+ link.setAttribute("href", "%s%s" % (feedPath, example["example"]))
entry.appendChild(link)
- summary = doc.createElementNS("http://www.w3.org/2005/Atom", "summary")
+ summary = doc.createElementNS(atomuri, "summary")
summary.appendChild(doc.createTextNode(example["shortdesc"] or example["example"]))
entry.appendChild(summary)
- updated = doc.createElementNS("http://www.w3.org/2005/Atom", "updated")
- updated.appendChild(doc.createTextNode(
- time.strftime("%Y-%m-%dT%I:%M:%SZ",time.gmtime(example["modified"]))))
+ updated = doc.createElementNS(atomuri, "updated")
+ updated.appendChild(doc.createTextNode(example["modified"]))
entry.appendChild(updated)
+ author = doc.createElementNS(atomuri, "author")
+ name = doc.createElementNS(atomuri, "name")
+ name.appendChild(doc.createTextNode(example["author"]))
+ author.appendChild(name)
+ entry.appendChild(author)
+
+ id = doc.createElementNS(atomuri, "id")
+ id.appendChild(doc.createTextNode("%s%s#%s" % (feedPath, example["example"], example["modified"])))
+ entry.appendChild(id)
+
feed.appendChild(entry)
doc.appendChild(feed)
@@ -171,12 +207,18 @@
examples = getListOfExamples(examplesLocation)
+ modtime = time.strftime("%Y-%m-%dT%I:%M:%SZ", time.gmtime())
+
for example in examples:
url = os.path.join(examplesLocation,example)
html = getExampleHtml(url)
tagvalues = parseHtml(html,docIds)
tagvalues['example'] = example
- tagvalues['link'] = url
+ # add in svn info
+ d = getSvnInfo(url)
+ tagvalues["modified"] = d["date"] or modtime
+ tagvalues["author"] = d["author"] or "anonymous"
+
exampleList.append(tagvalues)
print
@@ -191,8 +233,8 @@
outFile.write(json)
outFile.close()
- print "writing feed to ../examples/example-list.xml "
- atom = open('../examples/example-list.xml','w')
+ print "writing feed to ../examples/%s " % feedName
+ atom = open('../examples/%s' % feedName, 'w')
doc = createFeed(exampleList)
atom.write(doc.toxml())
atom.close()
More information about the Commits
mailing list