sitemap/resource: adding minus in path, adding video
[treecutter.git] / treecutter / docbook.py
index fd822ce8fe2cf6058fafa7528c56e0af0e38e0c8..32cff722ed72211e414d265250a72ece77202da0 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()
@@ -105,6 +121,16 @@ class Docbook():
                 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):