database: attempt to install lmdb if missing
When attempting a conversion, install the lmdb package if its missing. This should resolve issues with containers or new installations that want to migrate a previous db to sqlite. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
5332eab258
commit
3b1c21a72d
|
@ -121,16 +121,33 @@ def generate_lmdb_entries(
|
||||||
return
|
return
|
||||||
MAX_LMDB_NAMESPACES = 100
|
MAX_LMDB_NAMESPACES = 100
|
||||||
MAX_LMDB_SIZE = 200 * 2**20
|
MAX_LMDB_SIZE = 200 * 2**20
|
||||||
|
inst_attempted: bool = False
|
||||||
|
while True:
|
||||||
try:
|
try:
|
||||||
import lmdb
|
import lmdb
|
||||||
lmdb_env: LmdbEnvironment = lmdb.open(
|
lmdb_env: LmdbEnvironment = lmdb.open(
|
||||||
str(db_folder), map_size=MAX_LMDB_SIZE, max_dbs=MAX_LMDB_NAMESPACES
|
str(db_folder), map_size=MAX_LMDB_SIZE, max_dbs=MAX_LMDB_NAMESPACES
|
||||||
)
|
)
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
if inst_attempted:
|
||||||
|
logging.info(
|
||||||
|
"Attempt to install LMDB failed, aborting conversion."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
import sys
|
||||||
|
from ..utils import pip_utils
|
||||||
|
inst_attempted = True
|
||||||
|
logging.info("LMDB module not found, attempting installation...")
|
||||||
|
pip_cmd = f"{sys.executable} -m pip"
|
||||||
|
pip_exec = pip_utils.PipExecutor(pip_cmd, logging.info)
|
||||||
|
pip_exec.install_packages(["lmdb"])
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception(
|
logging.exception(
|
||||||
"Failed to open lmdb database, aborting conversion"
|
"Failed to open lmdb database, aborting conversion"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
break
|
||||||
lmdb_namespaces: List[Tuple[str, object]] = []
|
lmdb_namespaces: List[Tuple[str, object]] = []
|
||||||
with lmdb_env.begin(buffers=True) as txn:
|
with lmdb_env.begin(buffers=True) as txn:
|
||||||
# lookup existing namespaces
|
# lookup existing namespaces
|
||||||
|
|
Loading…
Reference in New Issue