Parse svn info output using XML format.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1389 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2013-08-22 17:57:26 +00:00
parent 8902b25b61
commit bbe793d9b1
2 changed files with 13 additions and 13 deletions

View File

@ -12,6 +12,7 @@ import subprocess
import sys import sys
import tempfile import tempfile
import urllib import urllib
import xml.etree.ElementTree as ET
import zipfile import zipfile
# default URL values # default URL values
@ -47,12 +48,11 @@ def get_svn_info(path):
rev = 'None' rev = 'None'
if path[0:4] == 'http' or os.path.exists(path): if path[0:4] == 'http' or os.path.exists(path):
try: try:
stream = os.popen('svn info '+path) stream = os.popen('svn info --xml '+path)
for line in stream: tree = ET.ElementTree(ET.fromstring(stream.read()))
if line[0:4] == "URL:": entry = tree.getroot().find('entry')
url = check_url(line[5:-1]) url = entry.find('url').text
elif line[0:9] == "Revision:": rev = entry.attrib['revision']
rev = str(int(line[10:-1]))
except IOError, (errno, strerror): except IOError, (errno, strerror):
sys.stderr.write('Failed to read svn info: '+strerror+"\n") sys.stderr.write('Failed to read svn info: '+strerror+"\n")
raise raise

View File

@ -5,6 +5,7 @@
import os import os
import sys import sys
import urllib import urllib
import xml.etree.ElementTree as ET
def check_url(url): def check_url(url):
""" Check the URL and raise an exception if invalid. """ """ Check the URL and raise an exception if invalid. """
@ -22,12 +23,11 @@ def get_svn_info(path):
rev = 'None' rev = 'None'
if path[0:4] == 'http' or os.path.exists(path): if path[0:4] == 'http' or os.path.exists(path):
try: try:
stream = os.popen('svn info '+path) stream = os.popen('svn info --xml '+path)
for line in stream: tree = ET.ElementTree(ET.fromstring(stream.read()))
if line[0:4] == "URL:": entry = tree.getroot().find('entry')
url = check_url(line[5:-1]) url = entry.find('url').text
elif line[0:9] == "Revision:": rev = entry.attrib['revision']
rev = str(int(line[10:-1]))
except IOError, (errno, strerror): except IOError, (errno, strerror):
sys.stderr.write('Failed to read svn info: '+strerror+"\n") sys.stderr.write('Failed to read svn info: '+strerror+"\n")
raise raise