Bcfg2/bcfg2 — pull request #57 by zenazn (2013-01-14 05:20:26+00:00)
Title: "AttributeError: 'Element' object has no attribute 'getparent'" if lxml is not installed

Got this traceback upon running `bcfg2` on a fresh Precise install using the testing PPA (`bcfg2 1.3.0rc1 on Python 2.7.3`):

Traceback (most recent call last):
File "/usr/sbin/bcfg2", line 29, in
sys.exit(main())
File "/usr/sbin/bcfg2", line 26, in main
return Client(setup).run()
File "/usr/lib/pymodules/python2.7/Bcfg2/Client/Client.py", line 307, in run
self.tools.Execute()
File "/usr/lib/pymodules/python2.7/Bcfg2/Client/Frame.py", line 499, in Execute
self.InstallImportant()
File "/usr/lib/pymodules/python2.7/Bcfg2/Client/Frame.py", line 236, in InstallImportant
parent = cfile.getparent()
AttributeError: 'Element' object has no attribute 'getparent'

Arises because of this check:

parent = cfile.getparent()
if ((parent.tag == "Bundle" and
((self.setup['bundle'] and
parent.get("name") not in self.setup['bundle']) or
(self.setup['skipbundle'] and
parent.get("name") in self.setup['skipbundle']))) or
(parent.tag == "Independent" and
(self.setup['bundle'] or self.setup['skipindep']))):
continue

However, `getparent()` only works if you have `lxml.etree` installed—`xml.etree` in the Python standard library (the fallback include) doesn't support this method.

Not confident enough in my understanding of what this code is doing to offer a patch, but hopefully it's a pretty straightforward fix.