Get revision value if present,if not get default revision value
Question: INPUT:-

    
    
    <manifest>
    <default revision="jb_2.5.4" remote="quic"/>
    <project name="platform/vendor/google/proprietary/widevine"
             path="vendor/widevine"
             revision="refs/heads/jb_2.6"
             x-grease-customer="none"
             x-quic-dist="none"
             x-ship="none" />
    <project path="vendor/widevine" name="platform/vendor/google/proprietary/bluetooth" x-ship="none" x-quic-dist="none" x-grease-customer="none"/>
    
    </manifest>
    

I am trying to get the revision value from the input above if the revision tag
is present,if it is not present use the revision value in the default tag,I
have the following code and running into following error.. can anyone provide
inputs on what is wrong here?

    
    
    import shlex
    import os
    import sys
    import json
    import fileinput
    import pwd
    import itertools
    import subprocess
    from subprocess import Popen, PIPE, STDOUT
    import xml.etree.ElementTree as ET
    import re
    
    
    def manifest_data (name):
        pattern = re.compile('refs/heads/(.*)')
        tree = ET.parse('.repo/manifests/default.xml')
        root = tree.getroot()
        project = root.find("./project[@name='%s']" % name)
        revision = project.get('revision')
        res = pattern.match(revision)
        return res.group(1)
    
    def main ():
        branch_name = "jb_2.5.4"
        print "branch_name"
        print branch_name
        projects = ['platform/vendor/google/proprietary/widevine','platform/vendor/google/proprietary/bluetooth']
        for project in projects :
            branch = manifest_data(project)
            print branch
    
    if __name__ == '__main__':
        main()
    

Error:-

    
    
      File "branch_manifest.py", line 35, in <module>
        main()
      File "branch_manifest.py", line 32, in main
        branch = manifest_data(project)
      File "branch_manifest.py", line 18, in manifest_data
        project = root.find("./project[@name='%s']" % name)
      File "/usr/lib/python2.6/xml/etree/ElementTree.py", line 330, in find
        return ElementPath.find(self, path)
      File "/usr/lib/python2.6/xml/etree/ElementPath.py", line 186, in find
        return _compile(path).find(element)
      File "/usr/lib/python2.6/xml/etree/ElementPath.py", line 176, in _compile
        p = Path(path)
      File "/usr/lib/python2.6/xml/etree/ElementPath.py", line 93, in __init__
        "expected path separator (%s)" % (op or tag)
    SyntaxError: expected path separator ([)
    


Answer: It works well with python2.7, but got the same exception with python2.6.

You can renference [ElementTree XPath - Select Element based on
attribute](http://stackoverflow.com/questions/222375/elementtree-xpath-select-
element-based-on-attribute). It gives an answer: python2.6 do not support
syntax like `./project[@name='%s']`

