util: Replace xml_indent with textwrap.indent

This commit is contained in:
Cole Robinson 2019-06-06 17:59:51 -04:00
parent 50addfebca
commit f47f6f3c7c
3 changed files with 5 additions and 17 deletions

View File

@ -146,8 +146,7 @@ class StoragePool(_StorageObject):
for source in sources.sources:
source_xml = source.get_xml()
pool_xml = "<pool>\n%s\n</pool>" % (
util.xml_indent(source_xml, 2))
pool_xml = "<pool>\n%s\n</pool>" % source_xml
parseobj = StoragePool(conn, parsexml=pool_xml)
parseobj.type = pool_type

View File

@ -23,18 +23,6 @@ def listify(l):
return l
def xml_indent(xmlstr, level):
"""
Indent the passed str the specified number of spaces
"""
xml = ""
if not xmlstr:
return xml
if not level:
return xmlstr
return "\n".join((" " * level + l) for l in xmlstr.splitlines())
def vm_uuid_collision(conn, uuid):
"""
Check if passed UUID string is in use by another guest of the connection

View File

@ -10,7 +10,8 @@ import collections
import logging
import os
import re
import string # pylint: disable=deprecated-module
import string
import textwrap
from .xmlapi import XMLAPI
from . import util
@ -691,7 +692,7 @@ class XMLBuilder(object):
use_xpath = obj._xmlstate.abs_xpath().rsplit("/", 1)[0]
indent = 2 * obj._xmlstate.abs_xpath().count("/")
self._xmlstate.xmlapi.node_add_xml(
util.xml_indent(xml, indent), use_xpath)
textwrap.indent(xml, indent * " "), use_xpath)
obj._parse_with_children(None, self._xmlstate)
def remove_child(self, obj):
@ -720,7 +721,7 @@ class XMLBuilder(object):
if not self._xmlstate.is_build:
xpath = origobj.get_xml_id()
indent = 2 * xpath.count("/")
xml = util.xml_indent(newobj.get_xml(), indent).strip()
xml = textwrap.indent(newobj.get_xml(), indent * " ").strip()
self._xmlstate.xmlapi.node_replace_xml(xpath, xml)
else:
origidx = origobj.get_xml_idx()