输入:-
<?xml version="1.0" encoding="UTF-8"?>
<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="external/dbus" name="platform/external/bus" revision="refs/heads/jb_2.5" x-ship="oss" x-quic-dist="la" x-grease-customer="none"/>
<project path="external/connectivity" name="platform/test/code" x-ship="oss" x-quic-dist="la" x-grease-customer="none"/>
</manifest>
你好,
如果上面显示的输入存在,我有以下代码获取修订值,如果没有“revision =”字段,它会退出并显示下面显示的错误..当没有“revision =”标签时我想要在输入中获取“默认版本”标签..有关如何在不更改现有功能的情况下执行此操作的任何输入?
CODE:-
import shlex
import os
import sys
import json
import fileinput
import pwd
import itertools
import subprocess
import shutil
from subprocess import Popen, PIPE, STDOUT
import xml.etree.ElementTree as ET
import re
def manifest_data (name):
print name
pattern = re.compile('refs/heads/(.*)')
tree = ET.parse('.repo/manifests/test.xml')
root = tree.getroot()
project = root.find("./project[@name='%s']" % name)
print project
if project != None:
revision = project.get('revision')
res = pattern.match(revision)
return res.group(1)
else:
default = root.find("./default")
return default.attrib.get('revision')
def main ():
branch_name = "jb_mr2"
print "branch_name"
print branch_name
projects = ['platform/vendor/google/proprietary/widevine','platform/external/bus','platform/test/code']
#if os.path.isdir('.repo') :
#print "Deleting .repo"
#shutil.rmtree('.repo')
RepoInitCmd = 'repo init -u git://git.quicinc.com/platform/manifest.git -b ' + branch_name
proc = subprocess.Popen(shlex.split(RepoInitCmd), stderr=subprocess.PIPE)
out, error = proc.communicate()
for project in projects :
branch = manifest_data(project)
print branch
if __name__ == '__main__':
main()
错误:-
Traceback (most recent call last):
File "branch_manifest.py", line 45, in <module>
main()
File "branch_manifest.py", line 41, in main
branch = manifest_data(project)
File "branch_manifest.py", line 23, in manifest_data
res = pattern.match(revision)
TypeError: expected string or buffer