[PATCH 0/3] Use lxml.etree instead of libxml2

That way we can remove libxml2-python package as Kimchi dependency and make XML manipulation consistent in the whole code. Aline Manera (3): Use lxml.etree on xmlutils/utils.py instead of xml.etree and libxml2 Use lxml.etree on gen-index.py script instead of libxml2 Remove libxml2-python as Kimchi dependency contrib/DEBIAN/control.in | 3 +-- contrib/kimchi.spec.fedora.in | 3 +-- contrib/kimchi.spec.suse.in | 3 +-- docs/README.md | 30 ++++++++++++++---------------- src/kimchi/xmlutils/utils.py | 18 ++++++------------ ui/pages/help/gen-index.py | 11 +++++------ 6 files changed, 28 insertions(+), 40 deletions(-) -- 1.9.3

xml.etree does not work well when the XML has non-registered namespaces. And as libvirt allows anyone to insert custom XML on <metadata> element it can be an easily point of failure while manipulating guest XML. To avoid problems with that use lxml.etree Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- src/kimchi/xmlutils/utils.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/kimchi/xmlutils/utils.py b/src/kimchi/xmlutils/utils.py index 2af1c2c..bfbe0c1 100644 --- a/src/kimchi/xmlutils/utils.py +++ b/src/kimchi/xmlutils/utils.py @@ -17,27 +17,21 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import libxml2 +import lxml.etree as ET from lxml import objectify -from xml.etree import ElementTree - - def xpath_get_text(xml, expr): - doc = libxml2.parseDoc(xml) - res = doc.xpathEval(expr) - ret = [None if x.children is None else x.children.content for x in res] - - doc.freeDoc() - return ret + doc = ET.fromstring(xml) + res = [x.text if not isinstance(x, str) else x for x in doc.xpath(expr)] + return res def xml_item_update(xml, xpath, value): - root = ElementTree.fromstring(xml) + root = ET.fromstring(xml) item = root.find(xpath) item.text = value - return ElementTree.tostring(root, encoding="utf-8") + return ET.tostring(root, encoding="utf-8") def dictize(xmlstr): -- 1.9.3

That way we remove all the occurrences of libxml2 on Kimchi code and then we don't need to depend on libxml2-python package anymore. Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- ui/pages/help/gen-index.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ui/pages/help/gen-index.py b/ui/pages/help/gen-index.py index cf7c5d7..ec7bdd2 100755 --- a/ui/pages/help/gen-index.py +++ b/ui/pages/help/gen-index.py @@ -18,7 +18,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import libxml2 +import lxml.etree as ET import sys @@ -44,14 +44,13 @@ def main(): input_files = sys.argv[1:] pages = {} + for f in sorted(input_files): with open(f) as fd: xml = fd.read() - doc = libxml2.parseDoc(xml) - node = doc.xpathEval('/cshelp/title')[0] - name = node.children.content - pages[f.replace('.dita', '.html')] = name - doc.freeDoc() + doc = ET.fromstring(xml) + name = doc.xpath('./title')[0].text + pages[f.replace('.dita', '.html')] = name.encode('utf-8') print HTML_HEAD for page, name in pages.iteritems(): -- 1.9.3

Kimchi is now always using python-lxml for XML manipulation. So there is not need to depend on libxml2-python Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- contrib/DEBIAN/control.in | 3 +-- contrib/kimchi.spec.fedora.in | 3 +-- contrib/kimchi.spec.suse.in | 3 +-- docs/README.md | 30 ++++++++++++++---------------- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/contrib/DEBIAN/control.in b/contrib/DEBIAN/control.in index 08ef72d..ecddc71 100644 --- a/contrib/DEBIAN/control.in +++ b/contrib/DEBIAN/control.in @@ -14,7 +14,6 @@ Depends: python-cherrypy3 (>= 3.2.0), libvirt-bin, nfs-common, python-m2crypto, - python-libxml2, qemu-kvm, python-pam, python-parted, @@ -30,7 +29,7 @@ Depends: python-cherrypy3 (>= 3.2.0), libguestfs-tools, spice-html5 Build-Depends: libxslt, - python-libxml2, + python-lxml, python-requests Maintainer: Aline Manera <alinefm@br.ibm.com> Description: Kimchi web server diff --git a/contrib/kimchi.spec.fedora.in b/contrib/kimchi.spec.fedora.in index 5579c7a..236c862 100644 --- a/contrib/kimchi.spec.fedora.in +++ b/contrib/kimchi.spec.fedora.in @@ -16,7 +16,6 @@ Requires: python-websockify Requires: novnc Requires: m2crypto Requires: python-imaging -Requires: libxml2-python Requires: PyPAM Requires: pyparted Requires: python-psutil >= 0.6.0 @@ -32,7 +31,7 @@ Requires: policycoreutils-python Requires: python-libguestfs Requires: libguestfs-tools BuildRequires: libxslt -BuildRequires: libxml2-python +BuildRequires: python-lxml BuildRequires: python-requests %if 0%{?rhel} == 6 || 0%{?fedora} >= 19 diff --git a/contrib/kimchi.spec.suse.in b/contrib/kimchi.spec.suse.in index b7144b3..96d3b4c 100644 --- a/contrib/kimchi.spec.suse.in +++ b/contrib/kimchi.spec.suse.in @@ -16,7 +16,6 @@ Requires: python-websockify Requires: novnc Requires: python-imaging Requires: python-M2Crypto -Requires: python-libxml2 Requires: python-pam Requires: python-parted Requires: python-psutil >= 0.6.0 @@ -31,7 +30,7 @@ Requires: open-iscsi Requires: python-libguestfs Requires: guestfs-tools BuildRequires: libxslt-tools -BuildRequires: python-libxml2 +BuildRequires: python-lxml BuildRequires: python-requests %if 0%{?sles_version} == 11 diff --git a/docs/README.md b/docs/README.md index 432cb4e..d18a946 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,12 +49,11 @@ Install Dependencies $ sudo yum install gcc make autoconf automake gettext-devel git \ python-cherrypy python-cheetah libvirt-python \ - libvirt libxml2-python python-imaging \ - PyPAM m2crypto python-jsonschema rpm-build \ - qemu-kvm python-psutil python-ethtool sos \ - python-ipaddr python-lxml nfs-utils \ - iscsi-initiator-utils libxslt pyparted nginx \ - policycoreutils-python python-libguestfs \ + libvirt python-imaging PyPAM m2crypto \ + python-jsonschema rpm-build qemu-kvm python-psutil \ + python-ethtool sos python-ipaddr python-lxml \ + nfs-utils iscsi-initiator-utils libxslt pyparted \ + nginx policycoreutils-python python-libguestfs \ libguestfs-tools python-requests python-websockify \ novnc @@ -78,9 +77,9 @@ for more information on how to configure your system to access this repository. $ sudo apt-get install gcc make autoconf automake gettext git \ python-cherrypy3 python-cheetah python-libvirt \ - libvirt-bin python-libxml2 python-imaging \ - python-pam python-m2crypto python-jsonschema \ - qemu-kvm libtool python-psutil python-ethtool \ + libvirt-bin python-imaging python-pam \ + python-m2crypto python-jsonschema qemu-kvm \ + libtool python-psutil python-ethtool \ sosreport python-ipaddr python-lxml nfs-common \ open-iscsi lvm2 xsltproc python-parted nginx \ firewalld python-guestfs libguestfs-tools \ @@ -94,13 +93,12 @@ for more information on how to configure your system to access this repository. $ sudo zypper install gcc make autoconf automake gettext-tools git \ python-CherryPy python-Cheetah libvirt-python \ - libvirt python-libxml2 python-imaging \ - python-pam python-M2Crypto python-jsonschema \ - rpm-build kvm python-psutil python-ethtool \ - python-ipaddr python-lxml nfs-client open-iscsi \ - libxslt-tools python-xml python-parted nginx \ - python-libguestfs guestfs-tools python-requests \ - python-websockify novnc + libvirt python-imaging python-pam python-M2Crypto \ + python-jsonschema rpm-build kvm python-psutil \ + python-ethtool python-ipaddr python-lxml \ + nfs-client open-iscsi libxslt-tools python-xml \ + python-parted nginx python-libguestfs \ + guestfs-tools python-requests python-websockify novnc Packages version requirement: python-psutil >= 0.6.0 -- 1.9.3

Reviewed-by: Daniel Barboza <danielhb@linux.vnet.ibm.com> Tested-by: Daniel Barboza <danielhb@linux.vnet.ibm.com> On 10/29/2014 02:09 PM, Aline Manera wrote:
That way we can remove libxml2-python package as Kimchi dependency and make XML manipulation consistent in the whole code.
Aline Manera (3): Use lxml.etree on xmlutils/utils.py instead of xml.etree and libxml2 Use lxml.etree on gen-index.py script instead of libxml2 Remove libxml2-python as Kimchi dependency
contrib/DEBIAN/control.in | 3 +-- contrib/kimchi.spec.fedora.in | 3 +-- contrib/kimchi.spec.suse.in | 3 +-- docs/README.md | 30 ++++++++++++++---------------- src/kimchi/xmlutils/utils.py | 18 ++++++------------ ui/pages/help/gen-index.py | 11 +++++------ 6 files changed, 28 insertions(+), 40 deletions(-)
participants (2)
-
Aline Manera
-
Daniel H Barboza