This blog post is 10 years old! Most likely, its content is outdated. Especially if it's technical.
This cost me some hair-pulling today as I was trying to write a custom test runner for a Django project I'm working on that creates a test Xapian database just for running the tests. Basically, you can't do this:
os.mkdir(database_file_path)
Because if you do you end up getting these strange DatabaseOpeningError exceptions. So, here's how you do it:
import xapian
xapian.WritableDatabase(database_file_path,
xapian.DB_CREATE_OR_OPEN)
Hopefully by blogging about this some other poor coder will save some time.
- Previous:
- Bookmarklet to replace the current domain with localhost:8000 17 January 2010
- Next:
- oplop - How Oplop works, explained in plain English and in technical detail 20 January 2010
- Related by category:
- fastest way to turn HTML into text in Python 08 January 2021 Python
- How much faster is Redis at storing a blob of JSON compared to PostgreSQL? 28 September 2019 Python
- Best practice with retries with requests 19 April 2017 Python
- Fastest way to find out if a file exists in S3 (with boto3) 16 June 2017 Python
- Interesting float/int casting in Python 25 April 2006 Python
Why would you mkdir a database's directory? Makes no sense.
Because the test runner doesn't work like a normal Django startup. Without first doing this, the first test that tries to open the database in read-only mode will fail. Perhaps there is a more appropriate way but I couldn't immediately find one.
I normally use xappy for xapian stuff, it makes it a lot easier, or at least I look at the source code if there is something that is bugging me. i.e http://code.google.com/p/xappy/source/browse/trunk/xappy/indexerconnection.py"
The makers of it also make xapian core, so xappy has got best use practices in it.
I'm currently using django-haystack to wrap Xapian. django-haystack actually wraps xapian-haystack.
I might reconsider this because I'm not getting the most out of django-haystack because so much of my work has been to patch and subclass django-haystack in various forms because I'm not using Django's ORM.
I will take a closer look at xappy as it might actually simplify the stack in this project.
Was going nuts because django didn't create it initially. Thanks!