|
|
@@ -14,6 +14,7 @@ import re |
|
|
|
import sys |
|
|
|
import tempfile |
|
|
|
|
|
|
|
import nilmdb.utils.lock |
|
|
|
from . import rocket |
|
|
|
|
|
|
|
# Up to 256 open file descriptors at any given time. |
|
|
@@ -26,6 +27,8 @@ class BulkData(object): |
|
|
|
def __init__(self, basepath, **kwargs): |
|
|
|
self.basepath = basepath |
|
|
|
self.root = os.path.join(self.basepath, "data") |
|
|
|
self.lock = os.path.join(self.root, "lock") |
|
|
|
self.lockfile = None |
|
|
|
|
|
|
|
# Tuneables |
|
|
|
if "file_size" in kwargs: |
|
|
@@ -44,8 +47,18 @@ class BulkData(object): |
|
|
|
if not os.path.isdir(self.root): |
|
|
|
os.mkdir(self.root) |
|
|
|
|
|
|
|
# Create the lock |
|
|
|
self.lockfile = open(self.lock, "w") |
|
|
|
if not nilmdb.utils.lock.exclusive_lock(self.lockfile): |
|
|
|
raise IOError('database at "' + self.basepath + |
|
|
|
'" is already locked by another process') |
|
|
|
|
|
|
|
def close(self): |
|
|
|
self.getnode.cache_remove_all() |
|
|
|
if self.lockfile: |
|
|
|
nilmdb.utils.lock.exclusive_unlock(self.lockfile) |
|
|
|
self.lockfile.close() |
|
|
|
self.lockfile = None |
|
|
|
|
|
|
|
def _encode_filename(self, path): |
|
|
|
# Encode all paths to UTF-8, regardless of sys.getfilesystemencoding(), |
|
|
|