summaryrefslogtreecommitdiff
path: root/virtinst
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2022-08-03 10:45:18 -0400
committerCole Robinson <crobinso@redhat.com>2022-08-03 12:34:47 -0400
commitbfa37d006507ca818df5c4b73de5efb7b9d32ce3 (patch)
tree86b46203445f8010ee726d7dad051d4383452d85 /virtinst
parentd2b346370a03f0a06a85ca2309506feb011a8559 (diff)
downloadvirt-manager-bfa37d006507ca818df5c4b73de5efb7b9d32ce3.tar.gz
xmlutil: Take unindent_device_xml from details.py
We will use this in virt-xml soon Signed-off-by: Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'virtinst')
-rw-r--r--virtinst/xmlutil.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/virtinst/xmlutil.py b/virtinst/xmlutil.py
index ae57f0de..418e7b82 100644
--- a/virtinst/xmlutil.py
+++ b/virtinst/xmlutil.py
@@ -76,3 +76,23 @@ def diff(origstr, newstr, fromfile="Original", tofile="New"):
origstr.splitlines(1), newstr.splitlines(1),
fromfile=fromfile, tofile=tofile)
return "".join(dlist)
+
+
+def unindent_device_xml(xml):
+ import re
+ lines = xml.splitlines()
+ if not lines:
+ return xml # pragma: no cover
+
+ ret = ""
+ unindent = 0
+ for c in lines[0]:
+ if c != " ":
+ break
+ unindent += 1
+
+ for line in lines:
+ if re.match(r"^%s *<.*$" % (unindent * " "), line):
+ line = line[unindent:]
+ ret += line + "\n"
+ return ret