mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-21 09:34:12 +03:00
xmlutil: Take unindent_device_xml from details.py
We will use this in virt-xml soon Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
d2b346370a
commit
bfa37d0065
@ -4,8 +4,6 @@
|
||||
# This work is licensed under the GNU GPLv2 or later.
|
||||
# See the COPYING file in the top-level directory.
|
||||
|
||||
import re
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
import libvirt
|
||||
@ -320,25 +318,6 @@ def _get_performance_icon_name():
|
||||
return icon
|
||||
|
||||
|
||||
def _unindent_device_xml(xml):
|
||||
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
|
||||
|
||||
|
||||
class vmmDetails(vmmGObjectUI):
|
||||
def __init__(self, vm, builder, topwin, is_customize_dialog):
|
||||
vmmGObjectUI.__init__(self, "details.ui",
|
||||
@ -1693,7 +1672,8 @@ class vmmDetails(vmmGObjectUI):
|
||||
try:
|
||||
dev = row[HW_LIST_COL_DEVICE]
|
||||
if dev:
|
||||
self._xmleditor.set_xml(_unindent_device_xml(dev.get_xml()))
|
||||
self._xmleditor.set_xml(
|
||||
virtinst.xmlutil.unindent_device_xml(dev.get_xml()))
|
||||
else:
|
||||
self._xmleditor.set_xml_from_libvirtobject(self.vm)
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user