OpenLayers OpenLayers

Changeset 7470

Show
Ignore:
Timestamp:
07/07/08 10:32:55 (3 months ago)
Author:
tschaub
Message:

Adding title, id, updated, and author elements for valid atom.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/tools/exampleparser.py

    r7463 r7470  
    77import time 
    88from xml.dom.minidom import Document 
     9from xml.etree import ElementTree 
    910 
    1011missing_deps = False 
     
    1516    missing_deps = E  
    1617 
     18feedName = "example-list.xml" 
     19feedPath = "http://openlayers.org/dev/examples/" 
    1720 
    1821def getListOfOnlineExamples(baseUrl): 
     
    8386    d['classes'] = classes 
    8487    return d 
     88 
     89def 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 
    8599     
    86100def createFeed(examples): 
    87101    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 
    94121    examples.sort(key=lambda x:x["modified"]) 
    95122    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") 
    99126        title.appendChild(doc.createTextNode(example["title"] or example["example"])) 
    100127        entry.appendChild(title) 
    101128         
    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"])
    104131        entry.appendChild(link) 
    105132     
    106         summary = doc.createElementNS("http://www.w3.org/2005/Atom", "summary") 
     133        summary = doc.createElementNS(atomuri, "summary") 
    107134        summary.appendChild(doc.createTextNode(example["shortdesc"] or example["example"])) 
    108135        entry.appendChild(summary) 
    109136         
    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"])) 
    113139        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) 
    114150         
    115151        feed.appendChild(entry) 
     
    172208    examples = getListOfExamples(examplesLocation) 
    173209 
     210    modtime = time.strftime("%Y-%m-%dT%I:%M:%SZ", time.gmtime()) 
     211 
    174212    for example in examples: 
    175213        url = os.path.join(examplesLocation,example) 
     
    177215        tagvalues = parseHtml(html,docIds) 
    178216        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 
    180222        exampleList.append(tagvalues) 
    181223         
     
    192234    outFile.close() 
    193235 
    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') 
    196238    doc = createFeed(exampleList) 
    197239    atom.write(doc.toxml())