Adding title, id, updated, and author elements for valid atom.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7470 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -6,6 +6,7 @@ import re
|
||||
import urllib2
|
||||
import time
|
||||
from xml.dom.minidom import Document
|
||||
from xml.etree import ElementTree
|
||||
|
||||
missing_deps = False
|
||||
try:
|
||||
@@ -14,6 +15,8 @@ try:
|
||||
except ImportError, E:
|
||||
missing_deps = E
|
||||
|
||||
feedName = "example-list.xml"
|
||||
feedPath = "http://openlayers.org/dev/examples/"
|
||||
|
||||
def getListOfOnlineExamples(baseUrl):
|
||||
"""
|
||||
@@ -82,36 +85,69 @@ def parseHtml(html,ids):
|
||||
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 @@ if __name__ == "__main__":
|
||||
|
||||
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 @@ if __name__ == "__main__":
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user