tools: adding error and warning calls
[treecutter.git] / treecutter / docbook.py
index fd822ce8fe2cf6058fafa7528c56e0af0e38e0c8..e7b6e9f6d833099ca504276a24970c3cb4d94447 100644 (file)
@@ -11,6 +11,7 @@ from time import time
 
 import treecutter.constants as const
 from treecutter.image import Image
+from treecutter.tools import warning
 
 class Docbook():
     """Class representing a docbook document"""
@@ -29,14 +30,28 @@ class Docbook():
         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()
@@ -68,7 +83,8 @@ class Docbook():
                 (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()