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:
+58
-16
@@ -6,6 +6,7 @@ import re
|
|||||||
import urllib2
|
import urllib2
|
||||||
import time
|
import time
|
||||||
from xml.dom.minidom import Document
|
from xml.dom.minidom import Document
|
||||||
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
missing_deps = False
|
missing_deps = False
|
||||||
try:
|
try:
|
||||||
@@ -14,6 +15,8 @@ try:
|
|||||||
except ImportError, E:
|
except ImportError, E:
|
||||||
missing_deps = E
|
missing_deps = E
|
||||||
|
|
||||||
|
feedName = "example-list.xml"
|
||||||
|
feedPath = "http://openlayers.org/dev/examples/"
|
||||||
|
|
||||||
def getListOfOnlineExamples(baseUrl):
|
def getListOfOnlineExamples(baseUrl):
|
||||||
"""
|
"""
|
||||||
@@ -82,36 +85,69 @@ def parseHtml(html,ids):
|
|||||||
classes = getRelatedClasses(html)
|
classes = getRelatedClasses(html)
|
||||||
d['classes'] = classes
|
d['classes'] = classes
|
||||||
return d
|
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):
|
def createFeed(examples):
|
||||||
doc = Document()
|
doc = Document()
|
||||||
feed = doc.createElementNS("http://www.w3.org/2005/Atom", "feed")
|
atomuri = "http://www.w3.org/2005/Atom"
|
||||||
feed.setAttribute("xmlns", "http://www.w3.org/2005/Atom") #ug, is this for real??
|
feed = doc.createElementNS(atomuri, "feed")
|
||||||
for example in examples:
|
feed.setAttribute("xmlns", atomuri)
|
||||||
s = os.stat("../examples/" + example["example"])
|
title = doc.createElementNS(atomuri, "title")
|
||||||
example["modified"] = s.st_mtime
|
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"])
|
examples.sort(key=lambda x:x["modified"])
|
||||||
for example in sorted(examples, key=lambda x:x["modified"], reverse=True):
|
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"]))
|
title.appendChild(doc.createTextNode(example["title"] or example["example"]))
|
||||||
entry.appendChild(title)
|
entry.appendChild(title)
|
||||||
|
|
||||||
link = doc.createElementNS("http://www.w3.org/2005/Atom", "link")
|
link = doc.createElementNS(atomuri, "link")
|
||||||
link.setAttribute("href", "http://openlayers.org/dev/examples/%s" % example["example"])
|
link.setAttribute("href", "%s%s" % (feedPath, example["example"]))
|
||||||
entry.appendChild(link)
|
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"]))
|
summary.appendChild(doc.createTextNode(example["shortdesc"] or example["example"]))
|
||||||
entry.appendChild(summary)
|
entry.appendChild(summary)
|
||||||
|
|
||||||
updated = doc.createElementNS("http://www.w3.org/2005/Atom", "updated")
|
updated = doc.createElementNS(atomuri, "updated")
|
||||||
updated.appendChild(doc.createTextNode(
|
updated.appendChild(doc.createTextNode(example["modified"]))
|
||||||
time.strftime("%Y-%m-%dT%I:%M:%SZ",time.gmtime(example["modified"]))))
|
|
||||||
entry.appendChild(updated)
|
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)
|
feed.appendChild(entry)
|
||||||
|
|
||||||
doc.appendChild(feed)
|
doc.appendChild(feed)
|
||||||
@@ -171,12 +207,18 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
examples = getListOfExamples(examplesLocation)
|
examples = getListOfExamples(examplesLocation)
|
||||||
|
|
||||||
|
modtime = time.strftime("%Y-%m-%dT%I:%M:%SZ", time.gmtime())
|
||||||
|
|
||||||
for example in examples:
|
for example in examples:
|
||||||
url = os.path.join(examplesLocation,example)
|
url = os.path.join(examplesLocation,example)
|
||||||
html = getExampleHtml(url)
|
html = getExampleHtml(url)
|
||||||
tagvalues = parseHtml(html,docIds)
|
tagvalues = parseHtml(html,docIds)
|
||||||
tagvalues['example'] = example
|
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)
|
exampleList.append(tagvalues)
|
||||||
|
|
||||||
print
|
print
|
||||||
@@ -191,8 +233,8 @@ if __name__ == "__main__":
|
|||||||
outFile.write(json)
|
outFile.write(json)
|
||||||
outFile.close()
|
outFile.close()
|
||||||
|
|
||||||
print "writing feed to ../examples/example-list.xml "
|
print "writing feed to ../examples/%s " % feedName
|
||||||
atom = open('../examples/example-list.xml','w')
|
atom = open('../examples/%s' % feedName, 'w')
|
||||||
doc = createFeed(exampleList)
|
doc = createFeed(exampleList)
|
||||||
atom.write(doc.toxml())
|
atom.write(doc.toxml())
|
||||||
atom.close()
|
atom.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user