aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lesana/collection.py12
-rw-r--r--lesana/command.py2
-rw-r--r--tests/test_collection.py5
3 files changed, 16 insertions, 3 deletions
diff --git a/lesana/collection.py b/lesana/collection.py
index 3bc7503..2a80072 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -263,7 +263,10 @@ class Collection(object):
enquire = xapian.Enquire(cache)
enquire.set_query(query)
# FIXME: if more items are returned, something is wrong?
- return self._match_to_entry(enquire.get_mset(0, 1)[0])
+ try:
+ return self._match_to_entry(enquire.get_mset(0, 1)[0])
+ except IndexError:
+ return None
def remove_entries(self, uids):
cache = xapian.WritableDatabase(
@@ -272,8 +275,11 @@ class Collection(object):
)
for uid in uids:
entry = self.entry_from_uid(uid)
- cache.delete_document(entry.idterm)
- os.remove(os.path.join(self.itemdir, entry.fname))
+ if not entry is None:
+ cache.delete_document(entry.idterm)
+ os.remove(os.path.join(self.itemdir, entry.fname))
+ else:
+ logging.warning("No such entry: {}, ignoring".format(uid))
cache.commit()
cache.close()
diff --git a/lesana/command.py b/lesana/command.py
index 2553915..6d31b34 100644
--- a/lesana/command.py
+++ b/lesana/command.py
@@ -98,6 +98,8 @@ class Edit(guacamole.Command):
def invoked(self, ctx):
collection = Collection(ctx.args.collection)
entry = collection.entry_from_uid(ctx.args.uid)
+ if entry is None:
+ return "No such entry: {}".format(ctx.args.uid)
filepath = os.path.join(
collection.itemdir,
entry.fname
diff --git a/tests/test_collection.py b/tests/test_collection.py
index a37a696..a197237 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -105,6 +105,11 @@ class testCollection(unittest.TestCase):
self.assertEqual(len(cm.output), 1)
self.assertIn("non_existing_file", cm.output[0])
+ def test_get_entry_missing_uid(self):
+ self.collection = lesana.Collection('tests/data/simple')
+ entry = self.collection.entry_from_uid('this is not an uid')
+ self.assertIsNone(entry)
+
class testEntries(unittest.TestCase):
def setUp(self):