commit 5da82a12c2419fcfc0f8c45b52c64725d7b672bc
Author: Michal Srb <msrb(a)redhat.com>
Date: Tue Jun 3 10:54:12 2014 +0200
Code deduplication in Dependency and Exclusion
python/javapackages/pom/dependency.py | 22 ++++++++++++++--------
python/javapackages/pom/exclusion.py | 11 ++---------
2 files changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/python/javapackages/pom/dependency.py
b/python/javapackages/pom/dependency.py
index 970036b..a4fe69f 100644
--- a/python/javapackages/pom/dependency.py
+++ b/python/javapackages/pom/dependency.py
@@ -32,21 +32,27 @@ class Dependency(AbstractArtifact):
"""
Return XML Element node representation of the Artifact
"""
- root = Element(root)
+ root = AbstractArtifact.get_xml_element(self, 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)
+ if self.scope:
+ item = SubElement(root, "scope")
+ item.text = self.scope
+
+ if self.optional:
+ item = SubElement(root, "optional")
+ item.text = str(self.optional).lower()
+
+ exc_root = Element("exclusions")
+ if self.exclusions:
+ for e in self.exclusions:
+ exc_root.insert(len(exc_root), e.get_xml_element())
return 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 self.get_xml_str(root)
def __eq__(self, other):
if type(other) is type(self):
diff --git a/python/javapackages/pom/exclusion.py b/python/javapackages/pom/exclusion.py
index 2c237d7..79d657d 100644
--- a/python/javapackages/pom/exclusion.py
+++ b/python/javapackages/pom/exclusion.py
@@ -21,20 +21,13 @@ class Exclusion(AbstractArtifact):
"""
Return XML Element node representation of the Exclusion
"""
- root = Element(root)
-
- for key in ("artifactId", "groupId"):
- 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="exclusion"):
"""
Return XML formatted string representation of the Exclusion
"""
- 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):
Show replies by date