Changeset 7470
- Timestamp:
- 07/07/08 10:32:55 (3 months ago)
- Files:
-
- trunk/openlayers/tools/exampleparser.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/tools/exampleparser.py
r7463 r7470 7 7 import time 8 8 from xml.dom.minidom import Document 9 from xml.etree import ElementTree 9 10 10 11 missing_deps = False … … 15 16 missing_deps = E 16 17 18 feedName = "example-list.xml" 19 feedPath = "http://openlayers.org/dev/examples/" 17 20 18 21 def getListOfOnlineExamples(baseUrl): … … 83 86 d['classes'] = classes 84 87 return d 88 89 def getSvnInfo(path): 90 h = os.popen("svn info %s --xml" % path) 91 tree = ElementTree.fromstring(h.read()) 92 h.close() 93 d = { 94 'url': tree.findtext('entry/url'), 95 'author': tree.findtext('entry/commit/author'), 96 'date': tree.findtext('entry/commit/date') 97 } 98 return d 85 99 86 100 def createFeed(examples): 87 101 doc = Document() 88 feed = doc.createElementNS("http://www.w3.org/2005/Atom", "feed") 89 feed.setAttribute("xmlns", "http://www.w3.org/2005/Atom") #ug, is this for real?? 90 for example in examples: 91 s = os.stat("../examples/" + example["example"]) 92 example["modified"] = s.st_mtime 93 102 atomuri = "http://www.w3.org/2005/Atom" 103 feed = doc.createElementNS(atomuri, "feed") 104 feed.setAttribute("xmlns", atomuri) 105 title = doc.createElementNS(atomuri, "title") 106 title.appendChild(doc.createTextNode("OpenLayers Examples")) 107 feed.appendChild(title) 108 link = doc.createElementNS(atomuri, "link") 109 link.setAttribute("rel", "self") 110 link.setAttribute("href", feedPath + feedName) 111 112 modtime = time.strftime("%Y-%m-%dT%I:%M:%SZ", time.gmtime()) 113 id = doc.createElementNS(atomuri, "id") 114 id.appendChild(doc.createTextNode("%s%s#%s" % (feedPath, feedName, modtime))) 115 feed.appendChild(id) 116 117 updated = doc.createElementNS(atomuri, "updated") 118 updated.appendChild(doc.createTextNode(modtime)) 119 feed.appendChild(updated) 120 94 121 examples.sort(key=lambda x:x["modified"]) 95 122 for example in sorted(examples, key=lambda x:x["modified"], reverse=True): 96 entry = doc.createElementNS( "http://www.w3.org/2005/Atom", "entry")97 98 title = doc.createElementNS( "http://www.w3.org/2005/Atom", "title")123 entry = doc.createElementNS(atomuri, "entry") 124 125 title = doc.createElementNS(atomuri, "title") 99 126 title.appendChild(doc.createTextNode(example["title"] or example["example"])) 100 127 entry.appendChild(title) 101 128 102 link = doc.createElementNS( "http://www.w3.org/2005/Atom", "link")103 link.setAttribute("href", " http://openlayers.org/dev/examples/%s" % example["example"])129 link = doc.createElementNS(atomuri, "link") 130 link.setAttribute("href", "%s%s" % (feedPath, example["example"])) 104 131 entry.appendChild(link) 105 132 106 summary = doc.createElementNS( "http://www.w3.org/2005/Atom", "summary")133 summary = doc.createElementNS(atomuri, "summary") 107 134 summary.appendChild(doc.createTextNode(example["shortdesc"] or example["example"])) 108 135 entry.appendChild(summary) 109 136 110 updated = doc.createElementNS("http://www.w3.org/2005/Atom", "updated") 111 updated.appendChild(doc.createTextNode( 112 time.strftime("%Y-%m-%dT%I:%M:%SZ",time.gmtime(example["modified"])))) 137 updated = doc.createElementNS(atomuri, "updated") 138 updated.appendChild(doc.createTextNode(example["modified"])) 113 139 entry.appendChild(updated) 140 141 author = doc.createElementNS(atomuri, "author") 142 name = doc.createElementNS(atomuri, "name") 143 name.appendChild(doc.createTextNode(example["author"])) 144 author.appendChild(name) 145 entry.appendChild(author) 146 147 id = doc.createElementNS(atomuri, "id") 148 id.appendChild(doc.createTextNode("%s%s#%s" % (feedPath, example["example"], example["modified"]))) 149 entry.appendChild(id) 114 150 115 151 feed.appendChild(entry) … … 172 208 examples = getListOfExamples(examplesLocation) 173 209 210 modtime = time.strftime("%Y-%m-%dT%I:%M:%SZ", time.gmtime()) 211 174 212 for example in examples: 175 213 url = os.path.join(examplesLocation,example) … … 177 215 tagvalues = parseHtml(html,docIds) 178 216 tagvalues['example'] = example 179 tagvalues['link'] = url 217 # add in svn info 218 d = getSvnInfo(url) 219 tagvalues["modified"] = d["date"] or modtime 220 tagvalues["author"] = d["author"] or "anonymous" 221 180 222 exampleList.append(tagvalues) 181 223 … … 192 234 outFile.close() 193 235 194 print "writing feed to ../examples/ example-list.xml "195 atom = open('../examples/ example-list.xml','w')236 print "writing feed to ../examples/%s " % feedName 237 atom = open('../examples/%s' % feedName, 'w') 196 238 doc = createFeed(exampleList) 197 239 atom.write(doc.toxml())
