From f6efcd152635aa6655538c7fa316cfc80b6701e9 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sat, 15 Apr 2017 09:08:53 +0200 Subject: Code stability promises --- docs/promises.rst | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 docs/promises.rst diff --git a/docs/promises.rst b/docs/promises.rst new file mode 100644 index 0000000..92ab5aa --- /dev/null +++ b/docs/promises.rst @@ -0,0 +1,35 @@ +Promises +======== + +Semantic versioning +------------------- + +This project uses semver_. + +.. _semver: http://semver.org/ + +Collection format stability +--------------------------- + +Future versions of lesana will be able to read collections written by +older versions. + +Older versions in the same mayor release will also be able to work +concurrently on the same repository. + +If in the future a change of formats will be required, conversions +scripts will be written in a way that will make them as stable as +possibile, and will have enought test data to keep them maintained for +the time being. + +Disposable cache +---------------- + +Contrary to the yaml files, the xapian cache is considered disposable: +from time to time there may be a need to delete the cache and reindex +everything, either because of an upgrade or to perform repository +mainteinance. + +Of course, effort will be made to reduce the need for this so that it +only happens sporadically, but it will probably never completely +disappear. -- cgit v1.2.3 From 9b5d3da213ce261a98109c90160929c70f0a4d04 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sat, 22 Apr 2017 19:18:41 +0200 Subject: Pass settings to Collection.init --- lesana/collection.py | 10 +++++++++- tests/test_collection.py | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lesana/collection.py b/lesana/collection.py index 1f488bc..5b80d3b 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -304,7 +304,13 @@ class Collection(object): cache.close() @classmethod - def init(cls, directory=None, git_enabled=True, edit_file=None): + def init( + cls, + directory=None, + git_enabled=True, + edit_file=None, + settings={} + ): """ Initialize a lesana repository @@ -316,6 +322,7 @@ class Collection(object): own errors. """ c_dir = os.path.abspath(directory or '.') + os.makedirs(c_dir, exist_ok=True) if git_enabled: # Try to initalize a git repo if git_available: @@ -351,6 +358,7 @@ class Collection(object): ).decode('utf-8') skel_dict = ruamel.yaml.load(skel, ruamel.yaml.RoundTripLoader) skel_dict['git'] = git_enabled + skel_dict.update(settings) with open(filepath, 'w') as fp: ruamel.yaml.dump( skel_dict, diff --git a/tests/test_collection.py b/tests/test_collection.py index e17e044..bcd45e7 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -298,6 +298,25 @@ class testCollectionCreation(unittest.TestCase): self.assertTrue(self._find_file_in_git_index(fname, repo.index)) shutil.rmtree(tmpdir) + def test_init_custom_settings(self): + tmpdir = tempfile.mkdtemp() + collection = lesana.Collection.init( + tmpdir, + edit_file=self.do_nothing, + settings={ + 'name': 'A different name', + 'fields': [ + {'name': 'title', 'type': 'string'}, + {'name': 'author', 'type': 'string'}, + ], + }, + ) + self.assertIsInstance(collection, lesana.Collection) + self.assertTrue(os.path.isfile(os.path.join(tmpdir, 'settings.yaml'))) + self.assertEqual(collection.settings['name'], 'A different name') + self.assertEqual(len(collection.settings['fields']), 2) + shutil.rmtree(tmpdir) + if __name__ == '__main__': unittest.main() -- cgit v1.2.3 From 9d6c7b5ef7f651a64e27db3d676a3a0153a85e7b Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sun, 21 May 2017 13:01:23 +0200 Subject: Fix creation of an entry with uid but no filename --- lesana/collection.py | 3 ++- tests/test_collection.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lesana/collection.py b/lesana/collection.py index 5b80d3b..d3715d1 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -26,7 +26,8 @@ class Entry(object): self.uid, ext = os.path.splitext(os.path.basename(self.fname)) else: self.uid = uuid.uuid4().hex - self.fname = self.uid + '.yaml' + if not self.fname: + self.fname = self.uid + '.yaml' def __str__(self): label = self.collection.settings.get('entry_label', None) diff --git a/tests/test_collection.py b/tests/test_collection.py index bcd45e7..891a439 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -164,6 +164,30 @@ class testEntries(unittest.TestCase): '{uid}: {name}'.format(uid=uid, name='Another item') ) + def test_entry_creation_uid_but_no_filename(self): + fname = '11189ee47ddf4796b718a483b379f976.yaml' + with open(os.path.join(self.basepath, fname)) as fp: + data = ruamel.yaml.safe_load(fp) + data['uid'] = '11189ee47ddf4796b718a483b379f976' + entry = lesana.Entry(self.collection, data=data) + self.assertEqual(entry.fname, fname) + + def test_entry_creation_no_uid_no_filename(self): + fname = '11189ee47ddf4796b718a483b379f976.yaml' + with open(os.path.join(self.basepath, fname)) as fp: + data = ruamel.yaml.safe_load(fp) + entry = lesana.Entry(self.collection, data=data) + self.assertIsNotNone(entry.uid) + self.assertIsNotNone(entry.fname) + + def test_entry_creation_filename_but_no_uid(self): + fname = '11189ee47ddf4796b718a483b379f976.yaml' + uid = '11189ee47ddf4796b718a483b379f976' + with open(os.path.join(self.basepath, fname)) as fp: + data = ruamel.yaml.safe_load(fp) + entry = lesana.Entry(self.collection, data=data, fname=fname) + self.assertEqual(entry.uid, uid) + class testComplexCollection(unittest.TestCase): @classmethod -- cgit v1.2.3 From 96465262f72b1b4230513e978d8412d0affc75a1 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sun, 4 Jun 2017 22:49:54 +0200 Subject: Search for all entries --- lesana/collection.py | 7 +++++++ lesana/command.py | 15 +++++++++------ tests/test_collection.py | 8 ++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lesana/collection.py b/lesana/collection.py index d3715d1..da001ae 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -263,6 +263,13 @@ class Collection(object): yield self._match_to_entry(match) offset += pagesize + def get_all_documents(self): + cache = self._get_cache() + postlist = cache.postlist("") + for post in postlist: + doc = cache.get_document(post.docid) + yield self._doc_to_entry(doc) + def _match_to_entry(self, match): return self._doc_to_entry(match.document) diff --git a/lesana/command.py b/lesana/command.py index 41448b3..2915d30 100644 --- a/lesana/command.py +++ b/lesana/command.py @@ -198,13 +198,16 @@ class Search(guacamole.Command): offset = ctx.args.offset or 0 pagesize = ctx.args.pagesize or 12 collection = Collection(ctx.args.collection) - collection.start_search(' '.join(ctx.args.query)) - if ctx.args.all: - results = collection.get_all_search_results() + if ctx.args.query == ['*']: + results = collection.get_all_documents() else: - results = collection.get_search_results( - offset, - pagesize) + collection.start_search(' '.join(ctx.args.query)) + if ctx.args.all: + results = collection.get_all_search_results() + else: + results = collection.get_search_results( + offset, + pagesize) if ctx.args.template: env = jinja2.Environment( loader=jinja2.FileSystemLoader( diff --git a/tests/test_collection.py b/tests/test_collection.py index 891a439..5c326e3 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -87,6 +87,14 @@ class testCollection(unittest.TestCase): matches = list(self.collection.get_all_search_results()) self.assertEqual(matches, []) + def test_all_entries(self): + self.collection = lesana.Collection('tests/data/simple') + res = self.collection.get_all_documents() + matches = list(res) + self.assertEqual(len(matches), 3) + for m in matches: + self.assertIsInstance(m, lesana.Entry) + def test_entry_from_uid(self): self.collection = lesana.Collection('tests/data/simple') entry = self.collection.entry_from_uid( -- cgit v1.2.3 From c2885894c06e15a5be0b6a00edd8e0de7746b4a9 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sat, 5 Aug 2017 16:58:45 +0200 Subject: Fix printing Entry id when data includes the id --- lesana/collection.py | 8 ++++---- tests/test_collection.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lesana/collection.py b/lesana/collection.py index da001ae..2ac99aa 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -33,10 +33,10 @@ class Entry(object): label = self.collection.settings.get('entry_label', None) if label: t = jinja2.Template(label) - return t.render( - uid=self.uid, - fname=self.fname, - **self.data) + data = self.data + data['uid'] = self.uid + data['fname'] = self.fname + return t.render(**data) else: return self.uid diff --git a/tests/test_collection.py b/tests/test_collection.py index 5c326e3..869828a 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -196,6 +196,26 @@ class testEntries(unittest.TestCase): entry = lesana.Entry(self.collection, data=data, fname=fname) self.assertEqual(entry.uid, uid) + def test_entry_str_filename_and_uid(self): + fname = '11189ee47ddf4796b718a483b379f976.yaml' + with open(os.path.join(self.basepath, fname)) as fp: + data = ruamel.yaml.safe_load(fp) + data['uid'] = '11189ee47ddf4796b718a483b379f976' + entry = lesana.Entry(self.collection, data=data) + self.assertEqual(str(entry), data['uid']) + self.collection.settings['entry_label'] = '{{ uid }}: {{ name }}' + self.assertEqual(str(entry), data['uid'] + ': Another item') + + def test_entry_str_filename_no_uid(self): + fname = '11189ee47ddf4796b718a483b379f976.yaml' + with open(os.path.join(self.basepath, fname)) as fp: + data = ruamel.yaml.safe_load(fp) + entry = lesana.Entry(self.collection, data=data) + uid = entry.uid + self.assertEqual(str(entry), uid) + self.collection.settings['entry_label'] = '{{ uid }}: {{ name }}' + self.assertEqual(str(entry), uid + ': Another item') + class testComplexCollection(unittest.TestCase): @classmethod -- cgit v1.2.3