diff options
-rw-r--r-- | docs/promises.rst | 35 | ||||
-rw-r--r-- | lesana/collection.py | 15 | ||||
-rw-r--r-- | lesana/command.py | 15 | ||||
-rw-r--r-- | tests/test_collection.py | 28 |
4 files changed, 83 insertions, 10 deletions
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. diff --git a/lesana/collection.py b/lesana/collection.py index d3715d1..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 @@ -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..869828a 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( @@ -188,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 |