aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2016-12-10 22:20:14 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2016-12-10 22:20:14 +0100
commitad04af4812bbdebe47ce58333cc48332197e61b1 (patch)
treecad2eaad18cb24cb13223826bdfcf069cbe69940
parentbc0989de6007876630bcd0c1db6b7c123bf1524a (diff)
Open a lesana directory
-rw-r--r--lesana/__init__.py1
-rw-r--r--lesana/collection.py29
-rw-r--r--tests/data/empty/.gitignore0
-rw-r--r--tests/data/simple/schema.yaml12
-rw-r--r--tests/test_collection.py28
5 files changed, 62 insertions, 8 deletions
diff --git a/lesana/__init__.py b/lesana/__init__.py
index e69de29..969ac3f 100644
--- a/lesana/__init__.py
+++ b/lesana/__init__.py
@@ -0,0 +1 @@
+from .collection import Collection
diff --git a/lesana/collection.py b/lesana/collection.py
new file mode 100644
index 0000000..df38e89
--- /dev/null
+++ b/lesana/collection.py
@@ -0,0 +1,29 @@
+import os
+
+import ruamel.yaml
+import xapian
+
+
+class Collection(object):
+ """
+ """
+
+ def __init__(self, directory=None):
+ self.basedir = directory or os.getcwd()
+ try:
+ with open(os.path.join(self.basedir, 'schema.yaml')) as fp:
+ self.schema = ruamel.yaml.load(fp, ruamel.yaml.RoundTripLoader)
+ except FileNotFoundError:
+ self.schema = ruamel.yaml.load("")
+ os.makedirs(os.path.join(self.basedir, '.lesana'), exist_ok=True)
+ self.cache = xapian.WritableDatabase(
+ os.path.join(self.basedir, '.lesana/xapian'),
+ xapian.DB_CREATE_OR_OPEN
+ )
+
+ def update_cache(self, files=None):
+ """
+ Update the xapian db with the data in files.
+
+ If no files have been passed, add everything.
+ """
diff --git a/tests/data/empty/.gitignore b/tests/data/empty/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/data/empty/.gitignore
diff --git a/tests/data/simple/schema.yaml b/tests/data/simple/schema.yaml
new file mode 100644
index 0000000..177aa92
--- /dev/null
+++ b/tests/data/simple/schema.yaml
@@ -0,0 +1,12 @@
+name: "Simple lesana collection"
+lang: 'english'
+fields:
+ - name: name
+ type: string
+ index: free
+ - name: description
+ type: text
+ index: free
+ - name: position
+ type: string
+ index: facet
diff --git a/tests/test_collection.py b/tests/test_collection.py
index 63820d5..64dd293 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -1,10 +1,22 @@
-from __future__ import division
-from __future__ import absolute_import
-from __future__ import print_function
-from __future__ import unicode_literals
-
+import os.path
+import shutil
import unittest
-class testCollection(unittest.TestCase):
- def test_noting(self):
- pass
+import lesana
+
+
+class testCollectionLoading(unittest.TestCase):
+ def tearDown(self):
+ shutil.rmtree(os.path.join(self.collection.basedir, '.lesana'))
+
+ def test_empty(self):
+ self.collection = lesana.Collection('tests/data/empty')
+ self.assertIsNone(self.collection.schema)
+ self.assertIsNotNone(self.collection.cache)
+
+ def test_simple(self):
+ self.collection = lesana.Collection('tests/data/simple')
+ self.assertIsNotNone(self.collection.schema)
+ self.assertEqual(self.collection.schema['name'], "Simple lesana collection")
+ self.assertEqual(len(self.collection.schema['fields']), 3)
+ self.assertIsNotNone(self.collection.cache)