piknik

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

commit bc7d5b3cd2def836fe3785e083ec2a8773f587bf
parent adb2c7aeeddb2687483d1a24e1b498a1af0daf9e
Author: lash <dev@holbrook.no>
Date:   Sat, 19 Nov 2022 09:22:30 +0000

Move list cmd code to show cmd

Diffstat:
Mpiknik/render/base.py | 8++++----
Mpiknik/render/html.py | 18++++++++++++------
Mpiknik/render/ini.py | 4++--
Mpiknik/render/plain.py | 4++--
Dpiknik/runnable/list.py | 65-----------------------------------------------------------------
Mpiknik/runnable/show.py | 58+++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msetup.cfg | 1-
7 files changed, 73 insertions(+), 85 deletions(-)

diff --git a/piknik/render/base.py b/piknik/render/base.py @@ -15,15 +15,15 @@ class Renderer: pass - def apply_issue_pre(self, state, issue_id, issue, tags, w=sys.stdout): + def apply_issue_pre(self, state, issue, tags, w=sys.stdout): pass - def apply_issue(self, state, issue_id, issue, tags, w=sys.stdout): + def apply_issue(self, state, issue, tags, w=sys.stdout): pass - def apply_issue_post(self, state, issue_id, issue, tags, w=sys.stdout): + def apply_issue_post(self, state, issue, tags, w=sys.stdout): pass @@ -31,5 +31,5 @@ class Renderer: pass - def apply_end(self, state, w=sys.stdout): + def apply_end(self, w=sys.stdout): pass diff --git a/piknik/render/html.py b/piknik/render/html.py @@ -30,22 +30,28 @@ class Renderer(BaseRenderer): self.state_buf.append(r) - def apply_issue(self, state, issue_id, issue, tags, w=sys.stdout): - v = li(a(issue.title, href=issue_id + '.html')) + def apply_issue(self, state, issue, tags, w=sys.stdout): + v = li(a(issue.title, href=issue.id + '.html')) self.issue_buf.append(v) - def apply_message(self, state, issue_id, issue, tags, message, w=None): + def apply_message(self, state, issue, tags, message, w=None): + pass + def apply_message_part(self, state, issue, envelope, message, message_date, message_id, dump_dir=None, w=sys.stdout): + m = parse_mime_type(message.get_content_type()) + filename = message.get_filename() - def apply_issue_post(self, state, issue_id, issue, tags, w=None): + + + def apply_issue_post(self, state, issue, tags, w=None): close = False if w == None: - fp = os.path.join(self.outdir, issue_id + '.html') + fp = os.path.join(self.outdir, issue.id + '.html') w = open(fp, 'w') close = True - r = dominate.document(title='issue: {} ({})'.format(issue.title, issue_id)) + r = dominate.document(title='issue: {} ({})'.format(issue.title, issue.id)) r.add(h1(issue.title)) w.write(r.render()) diff --git a/piknik/render/ini.py b/piknik/render/ini.py @@ -9,8 +9,8 @@ class Renderer(BaseRenderer): w.write('[' + state + ']\n') - def apply_issue(self, state, issue_id, issue, tags, w=sys.stdout): - w.write('{}\t{}\t{}\n'.format(issue.title, ','.join(tags), issue_id)) + def apply_issue(self, state, issue, tags, w=sys.stdout): + w.write('{}\t{}\t{}\n'.format(issue.title, ','.join(tags), issue.id)) def apply_state_post(self, state, w=sys.stdout): diff --git a/piknik/render/plain.py b/piknik/render/plain.py @@ -10,7 +10,7 @@ from .base import Renderer as BaseRenderer class Renderer(BaseRenderer): - def apply_issue(self, state, issue_id, issue, tags, w=sys.stdout): + def apply_issue(self, state, issue, tags, w=sys.stdout): w.write("""id: {} title: {} tags: {} @@ -38,7 +38,7 @@ tags: {} w.write('\t' + str(s)) - def apply_message(self, state, issue_id, issue, tags, message, w=sys.stdout): + def apply_message(self, state, issue, tags, message, w=sys.stdout): pass diff --git a/piknik/runnable/list.py b/piknik/runnable/list.py @@ -1,65 +0,0 @@ -import sys -import argparse - -from piknik import Basket -from piknik import Issue -from piknik.store import FileStoreFactory - - -argp = argparse.ArgumentParser() -argp.add_argument('-d', type=str, help='Data directory') -argp.add_argument('-s', '--state', type=str, action='append', default=[], help='Include state in list') -argp.add_argument('--show-finished', dest='show_finished', action='store_true', help='Include finished issues') -argp.add_argument('-r', '--renderer', type=str, default='ini', help='Renderer module for output') -arg = argp.parse_args(sys.argv[1:]) - -store_factory = FileStoreFactory(arg.d) -basket = Basket(store_factory) - - -def render(b, r, m): - m.apply_begin() - - for k in basket.states(): - if k == 'FINISHED' and not arg.show_finished: - continue - - m.apply_state(k) - - for v in r[k]: - if k != 'BLOCKED' and v in r['BLOCKED']: - continue - o = b.get(v) - t = b.tags(v) - m.apply_issue(k, v, o, t) - m.apply_issue_post(k, v, o, t) - - m.apply_state_post(k) - - m.apply_end() - - -def main(): - results = {} - states = [] - for s in arg.state: - states.append(s.upper()) - - l = len(states) - for s in basket.states(): - - if results.get(s) == None: - results[s] = [] - - if l == 0 or s in states: - for v in basket.list(category=s): - results[s].append(v) - - import piknik.render.html - m = piknik.render.html.Renderer() - #globals()['render_' + arg.renderer](basket, results, m) - render(basket, results, m) - - -if __name__ == '__main__': - main() diff --git a/piknik/runnable/show.py b/piknik/runnable/show.py @@ -23,8 +23,10 @@ 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('-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('issue_id', type=str, help='Issue id to show') +argp.add_argument('issue_id', type=str, nargs='?', default=None, help='Issue id to show') arg = argp.parse_args(sys.argv[1:]) store_factory = FileStoreFactory(arg.d) @@ -127,24 +129,70 @@ gpg_home = os.environ.get('GPGHOME') def render(renderer, basket, state, issue, tags): - renderer.apply_issue(state, arg.issue_id, issue, tags) + renderer.apply_issue(state, issue, tags) verifier = PGPWrapper(renderer, state, issue, home_dir=gpg_home) m = basket.get_msg( arg.issue_id, envelope_callback=verifier.envelope_callback, message_callback=verifier.message_callback, post_callback=verifier.post_callback, - ) + ) + +def render_states(renderer, basket, states): + renderer.apply_begin() + + for k in basket.states(): + if k == 'FINISHED' and not arg.show_finished: + continue + + renderer.apply_state(k) + + for issue_id in states[k]: + if k != 'BLOCKED' and issue_id in states['BLOCKED']: + 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_state_post(k) + + renderer.apply_end() + + +def process_states(renderer, basket): + results = {} + states = [] + for s in arg.state: + states.append(s.upper()) + + l = len(states) + for s in basket.states(): + + if results.get(s) == None: + results[s] = [] + + if l == 0 or s in states: + for v in basket.list(category=s): + results[s].append(v) + + render_states(renderer, basket, results) def main(): + if arg.issue_id == None: + import piknik.render.html + renderer = piknik.render.html.Renderer() + return process_states(renderer, basket) + + import piknik.render.plain + renderer = piknik.render.plain.Renderer() + 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) - import piknik.render.plain - renderer = piknik.render.plain.Renderer() render(renderer, basket, state, issue, tags) diff --git a/setup.cfg b/setup.cfg @@ -34,6 +34,5 @@ packages = console_scripts = piknik-add = piknik.runnable.add.py:main piknik-mod = piknik.runnable.mod.py:main - piknik-list = piknik.runnable.list.py:main piknik-show = piknik.runnable.show.py:main piknik-comment = piknik.runnable.comment.py:main