commit f2a8bf524e750fc7d79a8c1da93b84684735e4c8
parent a8f5a4d0e2d1e21e7b5d9f9d322c486b469bda00
Author: lash <dev@holbrook.no>
Date: Sun, 6 Nov 2022 21:17:56 +0000
Add state setters, list cmd
Diffstat:
5 files changed, 93 insertions(+), 14 deletions(-)
diff --git a/piknik/basket.py b/piknik/basket.py
@@ -50,19 +50,19 @@ class Basket:
return self.state.list(category)
- def doing(self, issue_id):
+ def state_doing(self, issue_id):
self.state.move(issue_id, self.state.DOING)
- def review(self, issue_id):
+ def state_review(self, issue_id):
self.state.move(issue_id, self.state.REVIEW)
- def backlog(self, issue_id):
+ def state_backlog(self, issue_id):
self.state.move(issue_id, self.state.BACKLOG)
- def finish(self, issue_id):
+ def state_finish(self, issue_id):
self.state.move(issue_id, self.state.FINISHED)
@@ -75,7 +75,6 @@ class Basket:
def unblock(self, issue_id):
if self.state.state(issue_id) & self.state.BLOCKED > 0:
- print('unset')
self.state.unset(issue_id, self.state.BLOCKED)
@@ -85,3 +84,7 @@ class Basket:
def blocked(self):
return self.list('blocked')
+
+
+ def states(self):
+ return self.state.all(pure=True)
diff --git a/piknik/runnable/add.py b/piknik/runnable/add.py
@@ -8,7 +8,7 @@ from piknik.store import FileStoreFactory
argp = argparse.ArgumentParser()
argp.add_argument('-d', type=str, help='Data directory')
-argp.add_argument('title', type=str, help='issue title')
+argp.add_argument('title', type=str, nargs='*', help='issue title')
arg = argp.parse_args(sys.argv[1:])
store_factory = FileStoreFactory(arg.d)
@@ -16,7 +16,14 @@ basket = Basket(store_factory.create)
def main():
- o = Issue(arg.title)
+ title = ''
+ for s in arg.title:
+ if s == ' ':
+ continue
+ if title != '':
+ title += ' '
+ title += s
+ o = Issue(title)
v = basket.add(o)
sys.stdout.write(v + '\n')
diff --git a/piknik/runnable/list.py b/piknik/runnable/list.py
@@ -0,0 +1,49 @@
+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('-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.create)
+
+
+def render_ini(b, r):
+ for k in r.keys():
+ print('[' + k + ']')
+
+ for v in r[k]:
+ o = b.get(v)
+ print('{}\t{}'.format(o.title, v))
+
+ print()
+
+
+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)
+
+ globals()['render_' + arg.renderer](basket, results)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/piknik/runnable/mod.py b/piknik/runnable/mod.py
@@ -8,6 +8,10 @@ from piknik.store import FileStoreFactory
argp = argparse.ArgumentParser()
argp.add_argument('-d', type=str, help='Data directory')
+argp.add_argument('--block', action='store_true', help='Set issue as blocked')
+argp.add_argument('--unblock', action='store_true', help='Set issue as unblocked')
+argp.add_argument('--finish', action='store_true', help='Set issue as finished (alias of -s finish)')
+argp.add_argument('-s', '--state', type=str, help='Move to state')
argp.add_argument('issue_id', type=str, help='Issue id to modify')
arg = argp.parse_args(sys.argv[1:])
@@ -18,6 +22,17 @@ basket = Basket(store_factory.create)
def main():
o = basket.get(arg.issue_id)
+ if arg.block:
+ basket.block(arg.issue_id)
+ elif arg.unblock:
+ basket.unblock(arg.issue_id)
+
+ if arg.state != None:
+ m = getattr(basket, 'state_' + arg.state)
+ m(arg.issue_id)
+ elif arg.finish:
+ basket.state_finish(arg.issue_id)
+
if __name__ == '__main__':
main()
diff --git a/tests/test_basic.py b/tests/test_basic.py
@@ -59,7 +59,7 @@ class TestBasic(unittest.TestCase):
v = self.b.add(o)
o_two = Issue('The second issue')
self.b.add(o_two)
- self.b.doing(v)
+ self.b.state_doing(v)
r = self.b.list('backlog')
self.assertEqual(len(r), 1)
@@ -71,16 +71,16 @@ class TestBasic(unittest.TestCase):
def test_jump(self):
o = Issue('The first issue')
v = self.b.add(o)
- self.b.doing(v)
+ self.b.state_doing(v)
r = self.b.list('doing')
self.assertEqual(len(r), 1)
- self.b.review(v)
+ self.b.state_review(v)
r = self.b.list('review')
self.assertEqual(len(r), 1)
- self.b.backlog(v)
+ self.b.state_backlog(v)
r = self.b.list('backlog')
self.assertEqual(len(r), 1)
- self.b.finish(v)
+ self.b.state_finish(v)
r = self.b.list('finished')
self.assertEqual(len(r), 1)
@@ -98,9 +98,14 @@ class TestBasic(unittest.TestCase):
def test_no_resurrect(self):
o = Issue('The first issue')
v = self.b.add(o)
- self.b.finish(v)
+ self.b.state_finish(v)
with self.assertRaises(DeadIssue):
- self.b.doing(v)
+ self.b.state_doing(v)
+
+
+ def test_states_list(self):
+ r = self.b.states()
+ self.assertEqual(len(r), 6)
if __name__ == '__main__':