シリアル化された Python シェルフを生成するソフトウェア パッケージを使用しています。
シェルフが生成されるリモート マシンでは、シェルフを開いて完全に処理できます。ただし、それらをローカル マシンにコピーすると、開くことができなくなります。
問題を dbm サブモジュール ( https://docs.python.org/3.1/library/dbm.html ) まで追跡しました。リモートで、シェルブ (形式: data.db) で dbm.whichdb() をキャストすると、出力は「dbm.ndbm」になるため、ndbm がインストールされているようで、サードパーティの Oracle Berkeley が代わりに DB が使用されます。これは、dbm ライブラリのinit .py ファイルのソース コードから読み取ったものです (データ形式は .pag、.dir ではなく .db であるため)。
def whichdb(filename):
"""Guess which db package to use to open a db file.
Return values:
- None if the database file can't be read;
- empty string if the file can be read but can't be recognized
- the name of the dbm submodule (e.g. "ndbm" or "gnu") if recognized.
Importing the given module may still fail, and opening the
database using that module may still fail.
"""
# Check for ndbm first -- this has a .pag and a .dir file
try:
f = io.open(filename + ".pag", "rb")
f.close()
f = io.open(filename + ".dir", "rb")
f.close()
return "dbm.ndbm"
except OSError:
# some dbm emulations based on Berkeley DB generate a .db file
# some do not, but they should be caught by the bsd checks
try:
f = io.open(filename + ".db", "rb")
f.close()
# guarantee we can actually open the file using dbm
# kind of overkill, but since we are dealing with emulations
# it seems like a prudent step
if ndbm is not None:
d = ndbm.open(filename)
d.close()
return "dbm.ndbm"
except OSError:
pass
...
私のローカル マシンで同じコードを実行すると、data.bak、data.dat、および data.dir の 3 つのファイルが生成されます。それらに対して dbm.whichdb() を呼び出すと、「dbm.dumb」が生成されます。リモートからコピーされたファイルに dbm.whichdb() をキャストすると、「なし」が返されます。これは、ドキュメントによると、データベースが読み取れないか破損していることを意味します。
これらのデータベースを開くための何かが不足していると思われます。
dbm ライブラリでは、dum.py ファイルにコンテンツが含まれていますが、ndbm.py には
"""Provide the _dbm module as a dbm submodule."""
from _dbm import *
そして、ndbm サブモジュールを使用できるようにする何かが他にあるはずだと思います。
これらの ndbm / Berkeley DB データベースを開くにはどうすればよいですか?