No longer read an existing zanata.xml

There is code in ZanataUtils that will read an existing zanata.xml,
and parse the details into an instance to support changing an
existing XML file. We have never made use of this functionality,
and it just tripped me up when testing a change for the last time,
destroy it.

Change-Id: Ie3e3ba3d8171ae912f2706dfeb756c007b51b703
This commit is contained in:
Steve Kowalik
2015-09-22 14:57:31 +10:00
parent ef7d5cfcdb
commit c5c2c5e39a

View File

@@ -101,9 +101,7 @@ class ZanataRestService:
class ProjectConfig: class ProjectConfig:
"""Object that stores zanata.xml per-project configuration. """Object that stores zanata.xml per-project configuration.
Given an existing zanata.xml, read in the values and make Write out a zanata.xml file for the project given the supplied values.
them accessible. Otherwise, write out a zanata.xml file
for the project given the supplied values.
Attributes: Attributes:
zconfig (IniConfig): zanata.ini values zconfig (IniConfig): zanata.ini values
@@ -114,12 +112,9 @@ class ProjectConfig:
self.rest_service = ZanataRestService(zconfig, verify=verify) self.rest_service = ZanataRestService(zconfig, verify=verify)
self.xmlfile = xmlfile self.xmlfile = xmlfile
self.rules = self._parse_rules(rules) self.rules = self._parse_rules(rules)
if os.path.isfile(os.path.abspath(xmlfile)): for key, value in kwargs.items():
self._load_config() setattr(self, key, value)
else: self._create_config()
for key, value in kwargs.items():
setattr(self, key, value)
self._create_config()
def _get_tag_prefix(self, root): def _get_tag_prefix(self, root):
"""XML utility method """XML utility method
@@ -137,29 +132,6 @@ class ProjectConfig:
""" """
return [{'pattern': rule[0], 'rule': rule[1]} for rule in rules] return [{'pattern': rule[0], 'rule': rule[1]} for rule in rules]
def _load_config(self):
"""Load configuration from an existing zanata.xml
Load and store project configuration from zanata.xml
"""
try:
with open(self.xmlfile, 'r') as f:
xml = etree.parse(f)
except IOError:
raise ValueError('Cannot load zanata.xml for this project')
except etree.ParseError:
raise ValueError('Cannot parse zanata.xml for this project')
root = xml.getroot()
tag_prefix = self._get_tag_prefix(root)
self.project = root.find('%sproject' % tag_prefix).text
self.version = root.find('%sproject-version' % tag_prefix).text
self.srcdir = root.find('%ssrc-dir' % tag_prefix).text
self.txdir = root.find('%strans-dir' % tag_prefix).text
rules = root.find('%srules' % tag_prefix)
self.rules = self._parse_rules([(tag.get('pattern', tag.text))
for tag in rules.getchildren()])
def _create_config(self): def _create_config(self):
"""Create zanata.xml """Create zanata.xml