Package: archmage
Version:  1:0.4.1-2
Severity: important
Tags: patch

The new archmage version breaks the documentation build of the keepass2
package.
This is due to the (maybe accidental) removal of the availity to render
html files from chm sources.

I have filed patch upstream to restore that ability:
https://github.com/dottedmag/archmage/pull/17

As it is required to update keepass2 and remove its python2 dependency,
could it be considered to add it to the package if upstream does not
react soon?

From 7591fd2427ebef2585347c7c567aa038a1fcab66 Mon Sep 17 00:00:00 2001
From: Julian Taylor <juliantaylor...@gmail.com>
Date: Sun, 9 Feb 2020 19:31:45 +0100
Subject: [PATCH] restore ability to render html from chm templates

add back the ability to export htlm files from chm templates via:

    python3 -c 'import archmage.CHM; archmage.CHM.CHMFile("chmdir").process_templates("output")'

Closes gh-16
---
 archmage/CHM.py | 45 ++++++++++++++++++++++++++++-----------------
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/archmage/CHM.py b/archmage/CHM.py
index 93b0591..fbd37c4 100644
--- a/archmage/CHM.py
+++ b/archmage/CHM.py
@@ -82,16 +82,24 @@ class CHMFile:
         return self.cache['entries']
 
     def _entries(self):
-        def get_name(chmfile, ui, out):
-            path = ui.path.decode('utf-8')
-            if path != '/':
-                out.append(path)
-            return chmlib.CHM_ENUMERATOR_CONTINUE
+        if self._chm is None:
+            entries = []
+            for root, dirs, files in os.walk(self.sourcename):
+                for f in files:
+                    fn = '/'.join((root.lstrip(self.sourcename), f))
+                    entries.append(fn)
+            return entries
+        else:
+            def get_name(chmfile, ui, out):
+                path = ui.path.decode('utf-8')
+                if path != '/':
+                    out.append(path)
+                return chmlib.CHM_ENUMERATOR_CONTINUE
 
-        out = []
-        if chmlib.chm_enumerate(self._chm, chmlib.CHM_ENUMERATE_ALL, get_name, out) == 0:
-            sys.exit('UnknownError: CHMLIB or PyCHM bug?')
-        return out
+            out = []
+            if chmlib.chm_enumerate(self._chm, chmlib.CHM_ENUMERATE_ALL, get_name, out) == 0:
+                sys.exit('UnknownError: CHMLIB or PyCHM bug?')
+            return out
 
     # retrieves the list of HTML files contained into the CHM file, **in order**
     # (that's the important bit).
@@ -327,14 +335,17 @@ class CHMEntry(object):
 
     def read(self):
         """Read CHM entry content"""
-        result, ui = chmlib.chm_resolve_object(self.parent._chm, self.name.encode('utf-8'))
-        if result != chmlib.CHM_RESOLVE_SUCCESS:
-            return None
-
-        size, content = chmlib.chm_retrieve_object(self.parent._chm, ui, 0, ui.length)
-        if size == 0:
-            return None
-        return content
+        if self.parent._chm:
+            result, ui = chmlib.chm_resolve_object(self.parent._chm, self.name.encode('utf-8'))
+            if result != chmlib.CHM_RESOLVE_SUCCESS:
+                return None
+
+            size, content = chmlib.chm_retrieve_object(self.parent._chm, ui, 0, ui.length)
+            if size == 0:
+                return None
+            return content
+        else:
+            return open(self.parent.sourcename + self.name).read()
 
     def lower_links(self, text):
         """Links to lower case"""
-- 
2.20.1


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to