python - Get revision value if present,if not get default revision value -


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 trying revision value input above if revision tag present,if not present use revision value in default tag,i have following code , running following error.. can provide inputs on wrong here?

import shlex import os import sys import json import fileinput import pwd import itertools import subprocess subprocess import popen, pipe, stdout import xml.etree.elementtree 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']     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 ([) 

it works python2.7, got same exception python2.6.

you can renference elementtree xpath - select element based on attribute. gives answer: python2.6 not support syntax ./project[@name='%s']


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -