commit 4cdbd7b6a8505c6ee16ae3850b19ac8a8d224b34
Author: Michal Srb <msrb(a)redhat.com>
Date: Tue Jun 3 10:18:39 2014 +0200
[artifact] Move get_xml_str() and get_xml_element() to AbstractArtifact
python/javapackages/pom/artifact.py | 35 ++++++++++++++++++++++++-----------
1 files changed, 24 insertions(+), 11 deletions(-)
---
diff --git a/python/javapackages/pom/artifact.py b/python/javapackages/pom/artifact.py
index 914ff8a..77d9f11 100644
--- a/python/javapackages/pom/artifact.py
+++ b/python/javapackages/pom/artifact.py
@@ -56,6 +56,27 @@ class AbstractArtifact(object):
return parts
+ def get_xml_element(self, root="abstractArtifact"):
+ """
+ Return XML Element node representation of the Artifact
+ """
+ root = Element(root)
+
+ members = self.__get_members()
+
+ for key in members:
+ if members[key]:
+ item = SubElement(root, key)
+ item.text = members[key]
+ return root
+
+ def get_xml_str(self, root="abstractArtifact"):
+ """
+ Return XML formatted string representation of the Artifact
+ """
+ root = self.get_xml_element(root)
+ return tostring(root, pretty_print=True)
+
def __get_members(self):
m = {'groupId': '',
'artifactId': '',
@@ -100,21 +121,13 @@ class Artifact(AbstractArtifact):
"""
Return XML Element node representation of the Artifact
"""
- root = Element(root)
-
- for key in ("artifactId", "groupId", "extension",
"version",
- "classifier"):
- if hasattr(self, key) and getattr(self, key):
- item = SubElement(root, key)
- item.text = getattr(self, key)
- return root
+ return AbstractArtifact.get_xml_element(self, root)
def get_xml_str(self, root="artifact"):
"""
Return XML formatted string representation of the Artifact
"""
- root = self.get_xml_element(root)
- return tostring(root, pretty_print=True)
+ return AbstractArtifact.get_xml_str(self, root)
def __eq__(self, other):
if type(other) is type(self):
@@ -178,6 +191,6 @@ class Artifact(AbstractArtifact):
Where last part is always considered to be version unless empty
"""
- p = cls.get_parts_from_mvn_str(mvnstr)
+ p = Artifact.get_parts_from_mvn_str(mvnstr)
return cls(p['groupId'], p['artifactId'],
p['extension'],
p['classifier'], p['version'])
Show replies by date