add option to save html dir (debug html to pdf)
authorJan Szejko <janek37@gmail.com>
Thu, 15 Mar 2018 14:43:54 +0000 (15:43 +0100)
committerJan Szejko <janek37@gmail.com>
Thu, 15 Mar 2018 14:43:54 +0000 (15:43 +0100)
librarian/weasy.py

index d2cd7e4..c924a8e 100644 (file)
@@ -623,11 +623,12 @@ class EduModuleWeasyFormat(Format):
     class MaterialNotFound(BaseException):
         pass
 
     class MaterialNotFound(BaseException):
         pass
 
-    def __init__(self, wldoc, media_root='', **kwargs):
+    def __init__(self, wldoc, media_root='', save_html_to=None, **kwargs):
         super(EduModuleWeasyFormat, self).__init__(wldoc, **kwargs)
         self.media_root = media_root
         self.materials_by_slug = None
         self.attachments = {}
         super(EduModuleWeasyFormat, self).__init__(wldoc, **kwargs)
         self.media_root = media_root
         self.materials_by_slug = None
         self.attachments = {}
+        self.save_html_to = save_html_to
 
     def get_html(self):
         self.attachments = {}
 
     def get_html(self):
         self.attachments = {}
@@ -656,6 +657,10 @@ class EduModuleWeasyFormat(Format):
 
     def get_pdf(self):
         temp = self.get_weasy_dir()
 
     def get_pdf(self):
         temp = self.get_weasy_dir()
+        if self.save_html_to:
+            save_path = os.path.join(self.save_html_to, 'weasy-html')
+            shutil.rmtree(save_path, ignore_errors=True)
+            shutil.copytree(temp, save_path)
         html_path = os.path.join(temp, 'doc.html')
         pdf_path = os.path.join(temp, 'doc.pdf')
         try:
         html_path = os.path.join(temp, 'doc.html')
         pdf_path = os.path.join(temp, 'doc.pdf')
         try: