piknik

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit 92bc1b5da2c0ba4a358b5fb8abd64c92b4d3da96
parent 288af8c1aecdfae42040bf6c62514f043bb41160
Author: lash <dev@holbrook.no>
Date:   Mon, 21 Nov 2022 20:48:30 +0000

Add single issue render stub

Diffstat:
Mpiknik/crypto.py | 8++++++--
Mpiknik/render/html.py | 57++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mpiknik/render/plain.py | 4++--
Mpiknik/runnable/show.py | 26++++++++++++++++----------
4 files changed, 78 insertions(+), 17 deletions(-)

diff --git a/piknik/crypto.py b/piknik/crypto.py @@ -17,13 +17,14 @@ logging.getLogger('gnupg').setLevel(logging.ERROR) class PGPSigner: - def __init__(self, home_dir=None, default_key=None, passphrase=None, use_agent=False): + def __init__(self, home_dir=None, default_key=None, passphrase=None, use_agent=False, skip_verify=False): self.gpg = gnupg.GPG(gnupghome=home_dir) self.default_key = default_key self.passphrase = passphrase self.use_agent = use_agent self.__envelope_state = -1 # -1 not in envelope, 0 in outer envelope, 1 inner envelope, not (yet) valid, 2 envelope valid (with signature) self.__envelope = None + self.__skip_verify = skip_verify def sign(self, msg, passphrase=None): # msg = IssueMessage object @@ -79,7 +80,10 @@ class PGPSigner: if r.status == 'no public key': logg.warning('public key for {} not found, cannot verify'.format(r.fingerprint)) elif r.status != 'signature valid': - raise VerifyError('invalid signature') + if self.__skip_verify: + logg.warning('invalid signature for message {}'.format(message_id)) + else: + raise VerifyError('invalid signature for message {}'.format(message_id)) else: logg.debug('signature ok from {}'.format(r.fingerprint)) envelope.valid = True diff --git a/piknik/render/html.py b/piknik/render/html.py @@ -4,7 +4,7 @@ import os # external imports import dominate -from dominate.tags import div, p, a, meta, ul, ol, li, h1, h2, link +from dominate.tags import div, p, a, meta, ul, ol, li, h1, h2, link, dl, dd, dt, img from mimeparse import parse_mime_type # local imports @@ -56,8 +56,42 @@ class Renderer(BaseRenderer): close = True r = dominate.document(title='issue: {} ({})'.format(issue.title, issue.id)) r.add(h1(issue.title)) + + r_l = dl() + r_l.add(dt('id')) + r_l.add(dd(issue.id)) + + r_l.add(dt('tags')) + r_r = ul() + for v in tags: + if v == '(UNTAGGED)': + continue + r_r.add(li(v)) + + assigned = issue.get_assigned() + r_l.add(dd(r_r)) + + r_l.add(dt('assigned to')) + if len(assigned) == 0: + r_l.add(dd('not assigned')) + else: + owner = issue.owner() + r_r = ul() + for v in assigned: + o = v[0] + s = o.id() + if o == owner: + s += ' (owner)' + r_r.add(li(s)) + r_l.add(dd(r_r)) + + r.add(r_l) + + for i, v in enumerate(self.message_buf): + r.add(p(v)) + w.write(r.render()) - + if close: w.close() @@ -65,6 +99,8 @@ class Renderer(BaseRenderer): def apply_message_post(self, state, issue, tags, message, message_from, message_date, message_id, message_valid, w=sys.stdout): #r = ol() #w.write(self.message_buf.render()) + + pass @@ -72,11 +108,26 @@ class Renderer(BaseRenderer): m = parse_mime_type(message.get_content_type()) filename = message.get_filename() + r = div(_id=issue.id + '.' + message_id) if filename == None: v = message.get_payload() if message.get('Content-Transfer-Encoding') == 'BASE64': v = b64decode(v).decode() - self.message_buf.append(p(v)) + r.add(p(v)) + + else: + v = message.get_payload() + if m[0] == 'image': + img_src = 'data:{}/{};base64,'.format(m[0], m[1]) + img_src += v + r.add(p(img(src=img_src))) + + self.message_buf.append(r) + + #for i, v in enumerate(self.message_buf): + # r.add(p(v)) + #w.write(r.render()) + def apply_end(self, w=sys.stdout): diff --git a/piknik/render/plain.py b/piknik/render/plain.py @@ -16,9 +16,9 @@ class Renderer(BaseRenderer): def apply_issue(self, state, issue, tags, w=sys.stdout): - w.write("""id: {} -title: {} + w.write("""title: {} tags: {} +id: {} """.format( issue.id, diff --git a/piknik/runnable/show.py b/piknik/runnable/show.py @@ -15,7 +15,7 @@ from piknik.store import FileStoreFactory from piknik.crypto import PGPSigner from piknik.render.plain import Renderer -#logging.basicConfig(level=logging.DEBUG) +logging.basicConfig(level=logging.DEBUG) logg = logging.getLogger() argp = argparse.ArgumentParser() @@ -51,7 +51,8 @@ def to_suffixed_file(d, s, data): class PGPWrapper(PGPSigner): def __init__(self, renderer, state, issue, home_dir=None): - super(PGPWrapper, self).__init__(home_dir=home_dir) + #super(PGPWrapper, self).__init__(home_dir=home_dir) + super(PGPWrapper, self).__init__(home_dir=home_dir, skip_verify=True) self.message_date = None self.messages = [] self.part = [] @@ -123,19 +124,24 @@ class PGPWrapper(PGPSigner): gpg_home = os.environ.get('GPGHOME') -def render(renderer, basket, state, issue, tags): +def render(renderer, basket, issue, tags): renderer.apply_begin() + render_issue(renderer, basket, issue, tags) + renderer.apply_state_post(state) + renderer.apply_end() + + +def render_issue(renderer, basket, issue, tags): + state = basket.get_state(issue.id) renderer.apply_issue(state, issue, tags) verifier = PGPWrapper(renderer, state, issue, home_dir=gpg_home) m = basket.get_msg( - arg.issue_id, + issue.id, envelope_callback=verifier.envelope_callback, message_callback=verifier.message_callback, post_callback=verifier.post_callback, ) renderer.apply_issue_post(state, issue, tags) - renderer.apply_state_post(state) - renderer.apply_end() def render_states(renderer, basket, states): @@ -152,8 +158,9 @@ def render_states(renderer, basket, states): continue issue = basket.get(issue_id) tags = basket.tags(issue_id) - renderer.apply_issue(k, issue, tags) - renderer.apply_issue_post(k, issue, tags) + #renderer.apply_issue(k, issue, tags) + #renderer.apply_issue_post(k, issue, tags) + render_issue(renderer, basket, issue, tags) renderer.apply_state_post(k) @@ -190,10 +197,9 @@ def main(): issue = basket.get(arg.issue_id) tags = basket.tags(arg.issue_id) - state = basket.get_state(arg.issue_id) #globals()['render_' + arg.renderer](basket, state, issue, tags) - render(renderer, basket, state, issue, tags) + render(renderer, basket, issue, tags) if __name__ == '__main__':