From f6692e9842f7a4d5c2b414e61159eb454d0e20b2 Mon Sep 17 00:00:00 2001
From: Michal Srb <msrb@redhat.com>
Date: Tue, 6 Jan 2015 14:35:28 +0100
Subject: [PATCH 1/3] Do not try to produce "pretty" XML with Python < 2.7
---
java-utils/maven_depmap.py | 4 ++--
java-utils/mvn_artifact.py | 5 ++---
python/javapackages/common/util.py | 11 +++++++++++
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/java-utils/maven_depmap.py b/java-utils/maven_depmap.py
index 8f6b11f..9a25211 100644
--- a/java-utils/maven_depmap.py
+++ b/java-utils/maven_depmap.py
@@ -51,6 +51,7 @@ from javapackages.metadata.artifact import MetadataArtifact
from javapackages.metadata.alias import MetadataAlias
import javapackages.metadata.pyxbmetadata as m
+import javapackages.common.util as util
import pyxb
@@ -199,8 +200,7 @@ def write_metadata(metadata_file, artifacts):
root.artifacts = pyxb.BIND(*artifacts)
with open(metadata_file, 'w') as f:
- dom = root.toDOM(None)
- f.write(dom.toprettyxml(indent=" "))
+ util.write_metadata(f, root)
if __name__ == "__main__":
diff --git a/java-utils/mvn_artifact.py b/java-utils/mvn_artifact.py
index 424252b..0bd97e0 100644
--- a/java-utils/mvn_artifact.py
+++ b/java-utils/mvn_artifact.py
@@ -42,7 +42,7 @@ from javapackages.maven.pom import POM, PomLoadingException
from javapackages.ivy.ivyfile import IvyFile
from javapackages.xmvn.xmvn_resolve import XMvnResolve, ResolutionResult, ResolutionRequest
-from javapackages.common.util import args_to_unicode
+from javapackages.common.util import args_to_unicode, write_metadata
import sys
import os
@@ -316,5 +316,4 @@ if __name__ == "__main__":
add_artifact_elements(metadata, art, pom_path, jar_path)
with open(config, 'w') as f:
- dom = metadata.toDOM(None)
- f.write(dom.toprettyxml(indent=" "))
+ write_metadata(f, metadata)
diff --git a/python/javapackages/common/util.py b/python/javapackages/common/util.py
index f893cc4..37942a4 100644
--- a/python/javapackages/common/util.py
+++ b/python/javapackages/common/util.py
@@ -128,3 +128,14 @@ def get_logger(name):
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
+
+
+def write_metadata(fileobj, metadata):
+ dom = metadata.toDOM(None)
+
+ # minidom in Python < 2.6 adds unnecessary whitespace
+ # see: http://bugs.python.org/issue4147
+ if sys.version_info < (2, 7):
+ fileobj.write(dom.toxml())
+ else:
+ fileobj.write(dom.toprettyxml(indent=" "))
--
2.1.0