commit 8167ed7382ebad6c20e54860c12db484b73c329a
parent 213aa6792980336111e535295f683b9453aa7c70
Author: lash <dev@holbrook.no>
Date: Sat, 3 Dec 2022 11:56:19 +0000
Reinstate html recursive dump
Diffstat:
3 files changed, 83 insertions(+), 29 deletions(-)
diff --git a/piknik/render/html.py b/piknik/render/html.py
@@ -22,6 +22,7 @@ class Accumulator:
self.issue = None
self.msg = None
self.w = w
+ self.issues = []
def add(self, v, w=None):
@@ -45,9 +46,11 @@ class Accumulator:
elif v_id[:2] == 'i_':
logg.debug('issue now')
self.issue.add(v)
+ self.issues.append(v_id[2:])
elif v_id[:4] == 'd_i_':
self.category = v
self.msg = ol(_id='message_list')
+ self.issues.append(v_id[2:])
elif v_id[:2] == 'm_':
self.msg.add(li(v))
elif v_id[:4] == 'd_m_':
@@ -106,10 +109,10 @@ class Renderer(BaseRenderer):
r_r = ul()
for v in assigned:
o = v[0]
- s = o.id()
+ ss = o.id()
if o == owner:
- s += ' (owner)'
- r_r.add(li(s))
+ ss += ' (owner)'
+ r_r.add(li(ss))
s.add(dd(r_r))
r.add(s)
diff --git a/piknik/render/plain.py b/piknik/render/plain.py
@@ -2,6 +2,7 @@
import logging
import tempfile
import os
+import sys
# external imports
from mimeparse import parse_mime_type
@@ -26,9 +27,21 @@ def to_suffixed_file(d, s, data):
return r[1]
+class Accumulator:
+
+ def __init__(self, w=sys.stdout):
+ self.w = w
+
+
+ def add(self, v):
+ stream_accumulator(v, w=self.w)
+
+
class Renderer(BaseRenderer):
- def __init__(self, basket, dump_dir=None, accumulator=stream_accumulator, **kwargs):
+ def __init__(self, basket, dump_dir=None, accumulator=None, **kwargs):
+ if accumulator == None:
+ accumulator = Accumulator().add
super(Renderer, self).__init__(basket, accumulator=accumulator, **kwargs)
self.dump_dir = dump_dir
diff --git a/piknik/runnable/show.py b/piknik/runnable/show.py
@@ -14,7 +14,6 @@ from piknik import Basket
from piknik import Issue
from piknik.store import FileStoreFactory
from piknik.crypto import PGPSigner
-from piknik.render.plain import Renderer
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
@@ -22,11 +21,11 @@ logg = logging.getLogger()
argp = argparse.ArgumentParser()
argp.add_argument('-d', type=str, help='Data directory')
argp.add_argument('-f', '--files', dest='f', action='store_true', help='Save attachments to filesystem')
-argp.add_argument('-o', '--files-dir', dest='files_dir', type=str, default='.', help='Directory to output saved files to')
+argp.add_argument('-o', '--files-dir', dest='files_dir', type=str, help='Directory to output saved files to')
argp.add_argument('-r', '--renderer', type=str, default='default', help='Renderer module for output')
argp.add_argument('-s', '--state', type=str, action='append', default=[], help='Limit results to state(s)')
argp.add_argument('--show-finished', dest='show_finished', action='store_true', help='Include finished issues')
-argp.add_argument('--reverse', action='store_true', help='Sort comments by oldest first')
+#argp.add_argument('--reverse', action='store_true', help='Sort comments by oldest first')
argp.add_argument('issue_id', type=str, nargs='?', default=None, help='Issue id to show')
arg = argp.parse_args(sys.argv[1:])
@@ -35,37 +34,76 @@ basket = Basket(store_factory)
gpg_home = os.environ.get('GPGHOME')
+renderer_s = arg.renderer
+if renderer_s == 'default':
+ renderer_s = 'piknik.render.plain'
+elif renderer_s == 'html':
+ renderer_s = 'piknik.render.html'
-def main():
+m = None
+try:
+ m = importlib.import_module(renderer_s)
+except ModuleNotFoundError:
+ renderer_s = 'piknik.render.' + renderer_s
+ m = importlib.import_module(renderer_s)
+
+accumulator = None
+accumulator_f = None
+
+def set_accumulator(issue_id=None):
+ global accumulator_f
+ global accumulator
+ global m
+ if arg.files_dir != None:
+ fb = None
+ if issue_id == None:
+ fb = 'index.html'
+ else:
+ fb = issue_id + '.html'
+ fp = os.path.join(arg.files_dir, fb)
+ accumulator_f = open(fp, 'w')
+ accumulator = m.Accumulator(w=accumulator_f)
+ return accumulator.add
+ return None
- renderer = arg.renderer
- if renderer == 'default':
- renderer = 'piknik.render.plain'
- elif renderer == 'html':
- renderer = 'piknik.render.html'
- m = None
- try:
- m = importlib.import_module(renderer)
- except ModuleNotFoundError:
- renderer = 'piknik.render.' + renderer
- m = importlib.import_module(renderer)
+def reset_accumulator():
+ global accumulator_f
+ global accumulator
+ if accumulator_f != None:
+ accumulator_f.close()
+ accumulator_f = None
+ issues = accumulator.issues
+ accumulator = None
+ return issues
+ return []
+
+
+def main():
+ issues = []
+ if arg.issue_id:
+ issues.append(arg.issue_id)
if arg.issue_id == None:
- renderer = m.Renderer(basket)
+ accumulator = set_accumulator()
+ renderer = m.Renderer(basket, accumulator=accumulator)
renderer.apply()
- return
+ issues = reset_accumulator()
- issue = basket.get(arg.issue_id)
- tags = basket.tags(arg.issue_id)
- state = basket.get_state(arg.issue_id)
- verifier = PGPSigner(home_dir=gpg_home, skip_verify=False)
- renderer = m.Renderer(basket, wrapper=verifier)
+ for issue_id in issues:
+ accumulator = set_accumulator(issue_id=issue_id)
+ issue = basket.get(issue_id)
+ tags = basket.tags(issue_id)
+ state = basket.get_state(issue_id)
+ verifier = PGPSigner(home_dir=gpg_home, skip_verify=False)
+ renderer = m.Renderer(basket, wrapper=verifier, accumulator=accumulator)
- renderer.apply_begin()
- renderer.apply_issue(state, issue, tags)
- renderer.apply_end()
+ renderer.apply_begin()
+ renderer.apply_issue(state, issue, tags)
+ renderer.apply_end()
+
+ reset_accumulator()
if __name__ == '__main__':