import treecutter.constants as const
from treecutter.image import Image
+from treecutter.tools import warning
class Docbook():
"""Class representing a docbook document"""
return (t, ta)
def expand_imageobjects(self):
+ cwd = os.getcwd()
db = ElementMaker(namespace=const.DB_NS, nsmap=const.NSMAP)
images = self._doc.xpath(u"//db:imageobject/db:imagedata[@fileref]",namespaces=const.XPATH)
- for io in images:
- image = Image(io)
- link = db.link(image.infostr(),**{const.XLINK+"href": f})
- io = db.imageobject(
- db.imagedata(fileref=image.format(800,600), width=str(800), depth=str(600)),
- db.caption(db.para(image.caption())))
+ for i in images:
+ os.chdir(self._dirname)
+ im = i.get('fileref')
+ img = Image(im)
+ caption = db.caption()
+ for p in img.caption().split('\n\n'):
+ caption.append(db.para(p))
+ link = db.para(db.link(img.infostr(),
+ **{const.XLINK+"href": img.filename()}))
+ caption.append(link)
+ mo = db.mediaobject(db.imageobject(
+ db.imagedata(fileref=img.resize(800,600))),caption)
+ iop = i.getparent()
+ mop = iop.getparent()
+ mopp = mop.getparent()
+ mopp.insert(mopp.index(mop)+1,mo)
+ mopp.remove(mop)
+ os.chdir(cwd)
+
def parse_xincludes(self):
cwd = os.getcwd()
(stdout, stderr) = xml.communicate()
#print xml.returnvalue
if stderr:
- print " ".join(exe)+" ERROR : [ "+stderr+" ]"
+ warning("%s : %s" % (" ".join(exe),stderr))
+ warning(stdout)
exit
os.chdir(cwd)
te = time()
print "WARNING: File "+im+" is missing!"
return res
+ def collect_videos(self):
+ res = []
+ for i in self._doc.xpath(u"//db:videodata[@fileref]",namespaces=const.XPATH):
+ im = os.path.join(self._dirname,i.get('fileref'))
+ if os.path.isfile(im):
+ res.append(im)
+ else:
+ print "WARNING: File "+im+" is missing!"
+ return res
+
def collect_forms(self):
res = []
for i in self._doc.xpath(u"//html:form[@action]",namespaces=const.XPATH):