commit c6f5512115902803972a35999be0ae032ec6efe4
parent 17a4fee83a5bbde7c0ee56e071aaddd0b421f75f
Author: lash <dev@holbrook.no>
Date: Tue, 15 Nov 2022 08:01:50 +0000
Add commit tool for adding message
Diffstat:
8 files changed, 44 insertions(+), 12 deletions(-)
diff --git a/piknik/basket.py b/piknik/basket.py
@@ -144,11 +144,11 @@ class Basket:
def __get_msg(self, issue_id):
r = self.state.get(issue_id)
- print('issue {}'.format(r))
o = Issue.from_str(r)
try:
v = self.__msg.get(issue_id)
- return IssueMessage.parse(o, v.decode('utf-8'), verifier=self.__msg_verify)
+ m = IssueMessage.parse(o, v.decode('utf-8'), verifier=self.__msg_verify)
+ return m
except FileNotFoundError:
logg.debug('instantiating new message log for {}'.format(issue_id))
diff --git a/piknik/crypto.py b/piknik/crypto.py
@@ -23,10 +23,11 @@ class InvalidSignature(Exception):
class PGPSigner:
- def __init__(self, home_dir=None, default_key=None, passphrase=None):
+ def __init__(self, home_dir=None, default_key=None, passphrase=None, use_agent=False):
self.gpg = gnupg.GPG(gnupghome=home_dir)
self.default_key = default_key
self.passphrase = passphrase
+ self.use_agent = use_agent
def sign(self, msg, passphrase=None): # msg = IssueMessage object
diff --git a/piknik/issue.py b/piknik/issue.py
@@ -95,7 +95,6 @@ class Issue:
if self.owner_idx == i:
o['owner'] = aid
- print(o)
return json.dumps(o)
diff --git a/piknik/msg.py b/piknik/msg.py
@@ -34,7 +34,7 @@ class IssueMessage:
m = message_from_string(v)
if verifier != None:
verifier(m)
- o.__m
+ o.__m = m
return o
diff --git a/piknik/runnable/commit.py b/piknik/runnable/commit.py
@@ -0,0 +1,28 @@
+import sys
+import argparse
+
+from piknik import Basket
+from piknik import Issue
+from piknik.store import FileStoreFactory
+from piknik.crypto import PGPSigner
+
+
+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('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)
+
+
+def main():
+ basket.msg(arg.issue_id, 's:' + arg.message)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/piknik/store/__init__.py b/piknik/store/__init__.py
@@ -1,4 +1,6 @@
+# standard imports
import os
+import uuid
# external imports
from shep.store.file import SimpleFileStoreFactory
@@ -13,7 +15,7 @@ def default_formatter(hx):
class MsgDir(HexDir):
def __init__(self, root_path):
- super(MsgDir, self).__init__(root_path, 36, levels=2, prefix_length=0, formatter=default_formatter)
+ super(MsgDir, self).__init__(root_path, 16, levels=2, prefix_length=0, formatter=default_formatter)
def __check(self, key, content, prefix):
@@ -21,7 +23,8 @@ class MsgDir(HexDir):
def get(self, k):
- fp = self.to_filepath(k)
+ u = uuid.UUID(k)
+ fp = self.to_filepath(u.hex)
f = None
f = open(fp, 'rb')
r = f.read()
@@ -30,11 +33,13 @@ class MsgDir(HexDir):
def key_to_string(self, k):
- return k.decode('utf-8')
+ u = uuid.UUID(bytes=k)
+ return str(u)
def put(self, k, v):
- return self.add(k.encode('utf-8'), v)
+ u = uuid.UUID(k)
+ return self.add(u.bytes, v)
class FileStoreFactory:
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = piknik
-version = 0.1.2
+version = 0.1.3
description = CLI issue tracker
author = Louis Holbrook
author_email = dev@holbrook.no
diff --git a/tests/test_store.py b/tests/test_store.py
@@ -96,10 +96,9 @@ class TestStore(unittest.TestCase):
b = Basket(self.store_factory)
m = b.msg(v, 's:baz')
- print(m)
- def test_msg_resume_sig_verify(self):
+ def test_msg_sig_verify_resume(self):
(crypto, gpg, gpg_dir) = pgp_setup()
b = Basket(self.store_factory, message_wrapper=crypto.sign, message_verifier=crypto.verify)
o = Issue('foo')