From bbe793d9b1be3ad3b325026a26bcc0ea79247dc9 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 22 Aug 2013 17:57:26 +0000 Subject: [PATCH] Parse svn info output using XML format. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1389 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- tools/automate/automate.py | 14 +++++++------- tools/svn_util.py | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/automate/automate.py b/tools/automate/automate.py index 0e145794a..ca36a310f 100644 --- a/tools/automate/automate.py +++ b/tools/automate/automate.py @@ -12,6 +12,7 @@ import subprocess import sys import tempfile import urllib +import xml.etree.ElementTree as ET import zipfile # default URL values @@ -40,19 +41,18 @@ def check_url(url): return url sys.stderr.write('Invalid URL: '+url+"\n") raise Exception('Invalid URL: '+url) - + def get_svn_info(path): """ Retrieves the URL and revision from svn info. """ url = 'None' rev = 'None' if path[0:4] == 'http' or os.path.exists(path): try: - stream = os.popen('svn info '+path) - for line in stream: - if line[0:4] == "URL:": - url = check_url(line[5:-1]) - elif line[0:9] == "Revision:": - rev = str(int(line[10:-1])) + stream = os.popen('svn info --xml '+path) + tree = ET.ElementTree(ET.fromstring(stream.read())) + entry = tree.getroot().find('entry') + url = entry.find('url').text + rev = entry.attrib['revision'] except IOError, (errno, strerror): sys.stderr.write('Failed to read svn info: '+strerror+"\n") raise diff --git a/tools/svn_util.py b/tools/svn_util.py index 39f2dda82..159d7ed7e 100644 --- a/tools/svn_util.py +++ b/tools/svn_util.py @@ -5,6 +5,7 @@ import os import sys import urllib +import xml.etree.ElementTree as ET def check_url(url): """ Check the URL and raise an exception if invalid. """ @@ -22,12 +23,11 @@ def get_svn_info(path): rev = 'None' if path[0:4] == 'http' or os.path.exists(path): try: - stream = os.popen('svn info '+path) - for line in stream: - if line[0:4] == "URL:": - url = check_url(line[5:-1]) - elif line[0:9] == "Revision:": - rev = str(int(line[10:-1])) + stream = os.popen('svn info --xml '+path) + tree = ET.ElementTree(ET.fromstring(stream.read())) + entry = tree.getroot().find('entry') + url = entry.find('url').text + rev = entry.attrib['revision'] except IOError, (errno, strerror): sys.stderr.write('Failed to read svn info: '+strerror+"\n") raise