piknik

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

commit a8f5a4d0e2d1e21e7b5d9f9d322c486b469bda00
parent 2ae43ba4b7ecbc313f4f0a1c230b2c19874b8d9b
Author: lash <dev@holbrook.no>
Date:   Sun,  6 Nov 2022 16:37:31 +0000

Issue serialization, sync file store on instance

Diffstat:
Mpiknik/basket.py | 8++++++--
Mpiknik/issue.py | 21+++++++++++++++++++--
Mpiknik/runnable/add.py | 9+++++----
Apiknik/runnable/mod.py | 23+++++++++++++++++++++++
Mrequirements.txt | 1-
Arun_tests.sh | 14++++++++++++++
Dtest/test_issue.py | 18------------------
Dtest/test_store.py | 40----------------------------------------
Rtest/test_basic.py -> tests/test_basic.py | 0
Atests/test_issue.py | 28++++++++++++++++++++++++++++
Atests/test_store.py | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 files changed, 151 insertions(+), 67 deletions(-)

diff --git a/piknik/basket.py b/piknik/basket.py @@ -1,6 +1,7 @@ import shep from .error import DeadIssue +from .issue import Issue class Basket: @@ -17,6 +18,8 @@ class Basket: self.state.alias('doingblocked', self.state.DOING | self.state.BLOCKED) self.state.alias('pendingblocked', self.state.PENDING | self.state.BLOCKED) + self.state.sync() + self.limit = self.state.FINISHED self.issues_rev = {} @@ -30,12 +33,13 @@ class Basket: def add(self, issue): issue_id = str(issue.id) self.state.put(issue_id, contents=str(issue)) - self.issues_rev[issue_id] = issue return issue_id def get(self, issue_id): - return self.issues_rev[issue_id] + r = self.state.get(issue_id) + o = Issue.from_str(r) + return o def list(self, category=None): diff --git a/piknik/issue.py b/piknik/issue.py @@ -4,13 +4,30 @@ import json class Issue: - def __init__(self, title): - self.id = uuid.uuid4() + def __init__(self, title, issue_id=None): + if issue_id == None: + issue_id = str(uuid.uuid4()) + self.id = issue_id self.title = title + @staticmethod + def from_str(s): + r = json.loads(s) + o = Issue(title=r['title'], issue_id=r['id']) + return o + + def __str__(self): return json.dumps({ 'id': str(self.id), 'title': self.title, }) + + + def __eq__(self, o): + if o.id != self.id: + return False + if o.title != self.title: + return False + return True diff --git a/piknik/runnable/add.py b/piknik/runnable/add.py @@ -3,21 +3,22 @@ import argparse from piknik import Basket from piknik import Issue -from piknik.cli import FileStoreFactory +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') arg = argp.parse_args(sys.argv[1:]) - -store_factory = FileStoreFactory() +store_factory = FileStoreFactory(arg.d) basket = Basket(store_factory.create) def main(): o = Issue(arg.title) - basket.add(o) + v = basket.add(o) + sys.stdout.write(v + '\n') if __name__ == '__main__': diff --git a/piknik/runnable/mod.py b/piknik/runnable/mod.py @@ -0,0 +1,23 @@ +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('issue_id', type=str, help='Issue id to modify') +arg = argp.parse_args(sys.argv[1:]) + +store_factory = FileStoreFactory(arg.d) +basket = Basket(store_factory.create) + + +def main(): + o = basket.get(arg.issue_id) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt @@ -1,2 +1 @@ shep~=0.2.11 -confini~=0.6.3 diff --git a/run_tests.sh b/run_tests.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -a +set -e +set -x +default_pythonpath=$PYTHONPATH:. +export PYTHONPATH=${default_pythonpath:-.} +>&2 echo using pythonpath $PYTHONPATH +for f in `ls tests/*.py`; do + python $f +done +set +x +set +e +set +a diff --git a/test/test_issue.py b/test/test_issue.py @@ -1,18 +0,0 @@ -import unittest -import logging - -logging.basicConfig(level=logging.DEBUG) -logg = logging.getLogger() - -from piknik import Issue - - -class TestIssue(unittest.TestCase): - - def test_basic(self): - o = Issue('foo') - v = o.serialize() - - -if __name__ == '__main__': - unittest.main() diff --git a/test/test_store.py b/test/test_store.py @@ -1,40 +0,0 @@ -import unittest -import shep -import logging -import tempfile - -logging.basicConfig(level=logging.DEBUG) -logg = logging.getLogger() - -from piknik import ( - Basket, - Issue, - ) -from piknik.error import DeadIssue -from piknik.store import FileStoreFactory - - -def debug_out(self, k, v): - logg.debug('TRACE: {} {}'.format(k, v)) - - -class TestStore(unittest.TestCase): - - def setUp(self): - self.d = tempfile.mkdtemp() - store_factory = FileStoreFactory(self.d) - self.b = Basket(store_factory.create) - - - def tearDown(self): - logg.debug('tempdir is {}'.format(self.d)) - pass - - - def test_basic(self): - o = Issue('foo') - v = self.b.add(o) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/test_basic.py b/tests/test_basic.py diff --git a/tests/test_issue.py b/tests/test_issue.py @@ -0,0 +1,28 @@ +import unittest +import logging +import json + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + +from piknik import Issue + + +class TestIssue(unittest.TestCase): + + def test_basic(self): + o = Issue('foo') + r = json.loads(str(o)) + self.assertEqual(str(o.id), r['id']) + self.assertEqual(o.title, r['title']) + + + def test_from_str(self): + o = Issue('foo') + v = str(o) + r = Issue.from_str(v) + self.assertTrue(o == r) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_store.py b/tests/test_store.py @@ -0,0 +1,56 @@ +import unittest +import shep +import logging +import tempfile +import shutil + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + +from piknik import ( + Basket, + Issue, + ) +from piknik.error import DeadIssue +from piknik.store import FileStoreFactory + + +def debug_out(self, k, v): + logg.debug('TRACE: {} {}'.format(k, v)) + + +class TestStore(unittest.TestCase): + + def setUp(self): + self.d = tempfile.mkdtemp() + logg.debug('tempdir is {}'.format(self.d)) + self.store_factory = FileStoreFactory(self.d) + self.b = Basket(self.store_factory.create) + + + def tearDown(self): + shutil.rmtree(self.d) + pass + + + def test_basic(self): + o = Issue('foo') + v = self.b.add(o) + + + def test_load(self): + o = Issue('foo') + va = self.b.add(o) + + o = Issue('bar') + vb = self.b.add(o) + + self.b.advance(va) + + b = Basket(self.store_factory.create) + print('get va {}'.format(va)) + r = b.get(va) + + +if __name__ == '__main__': + unittest.main()