I stick with the NMBPREFIX environment variable for consistency with
nmbug itself. I also drop 'app.debug = True', to avoid trouble like:
$ ./nmhive.py
* Running on http://0.0.0.0:5000/
* Restarting with reloader
A Xapian exception occurred opening database: Unable to get write
lock on /.../xapian: already locked
Traceback (most recent call last):
File "./nmhive.py", line 83, in <module>
mode=notmuch.Database.MODE.READ_WRITE)
File "/.../notmuch/database.py", line 154, in __init__
self.open(path, mode)
File "/.../notmuch/database.py", line 214, in open
raise NotmuchError(status)
notmuch.errors.XapianError
because with 'debug = True', Flask tries to run two instances of this
process simultaneously, but only one can hold the write lock at a
time. If we want to scale this up to multiple writing
threads/processes, we'll probably want to make the persistant Database
instance read-only, and either acquire a write lock as necessary, or
just instantiate a read/write database for each PUT. For now, it's
easy enough to just have a single thread.
import json
import mailbox
+import os
import tempfile
import urllib.request
import flask
import flask_cors
+import notmuch
app = flask.Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'
flask_cors.CORS(app)
-
-_AVAILABLE_TAGS = {
- 'bug',
- 'needs-review',
- 'obsolete',
- 'patch',
- }
+TAG_PREFIX = os.getenv('NMBPREFIX', 'notmuch::')
+NOTMUCH = None
_TAGS = {}
@app.route('/tags', methods=['GET'])
def tags():
+ tags = set()
+ for t in NOTMUCH.get_all_tags():
+ if t.startswith(TAG_PREFIX):
+ tags.add(t[len(TAG_PREFIX):])
return flask.Response(
- response=json.dumps(sorted(_AVAILABLE_TAGS)),
+ response=json.dumps(sorted(tags)),
mimetype='application/json')
if __name__ == '__main__':
- app.debug = True
+ NOTMUCH = notmuch.Database(
+ path=None,
+ mode=notmuch.Database.MODE.READ_WRITE)
app.run(host='0.0.0.0')