commit 324077a10a01ae95db092aaffa54c0c63b8c9d00
parent c6f5512115902803972a35999be0ae032ec6efe4
Author: lash <dev@holbrook.no>
Date: Tue, 15 Nov 2022 09:17:27 +0000
Add file attachment in issue commit, preserve order
Diffstat:
2 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/piknik/msg.py b/piknik/msg.py
@@ -58,6 +58,7 @@ class IssueMessage:
if mime_type[1] != None:
m.set_charset(mime-type[1])
m.add_header('Content-Transfer-Encoding', 'BASE64')
+ m.add_header('Content-Disposition', 'attachment; filename="{}"'.format(v))
f = open(v, 'rb')
r = f.read()
diff --git a/piknik/runnable/commit.py b/piknik/runnable/commit.py
@@ -1,28 +1,63 @@
+# standard imports
import sys
import argparse
+import logging
+# local imports
from piknik import Basket
from piknik import Issue
from piknik.store import FileStoreFactory
from piknik.crypto import PGPSigner
+next_i = 1
+def next_message_arg():
+ global next_i
+ print('next {}'.format(next_i))
+
+ r = sys.argv[next_i]
+
+ if r[0] != '-':
+ next_i += 1
+ return None
+
+ if r[1] not in ['r', 'i', 't', 'f']:
+ next_i += 1
+ return None
+
+ v = sys.argv[next_i+1]
+ next_i += 2
+ return (r[1], v,)
+
argp = argparse.ArgumentParser()
argp.add_argument('-d', type=str, help='Data directory')
argp.add_argument('-s', '--sign-as', dest='s', type=str, help='PGP fingerprint of key to sign issue update with')
-argp.add_argument('-m', '--message', type=str, required=True, help='Add literal message text')
+argp.add_argument('-r', type=str, action='append', default=[], help='Add literal message text')
+argp.add_argument('-f', type=str, action='append', default=[], help='Add arbitrary file as content')
argp.add_argument('issue_id', type=str, help='Issue id to modify')
arg = argp.parse_args(sys.argv[1:])
signer = PGPSigner(default_key=arg.s, use_agent=True)
store_factory = FileStoreFactory(arg.d)
-#basket = Basket(store_factory, message_wrapper=wrapper, message_verifier=verifier)
-basket = Basket(store_factory, message_wrapper=signer.sign)
+basket = Basket(store_factory, message_wrapper=signer.sign, message_verifier=signer.verify)
def main():
- basket.msg(arg.issue_id, 's:' + arg.message)
-
+ while True:
+ try:
+ r = next_message_arg()
+ except IndexError:
+ break
+ if r == None:
+ continue
+
+ messages = []
+ if r[0] == 'r':
+ messages.append('s:' + r[1])
+ elif r[0] == 'f':
+ messages.append('f:' + r[1])
+
+ basket.msg(arg.issue_id, *messages)
if __name__ == '__main__':
main()