def bundle(self, structure, data_bundle_hdf_path, buffer_size=int(1e+9),
structure_config=None):
if structure_config is None:
structure_config = {}
def _bundle_data(structure, structure_config, dset_name=""):
if isinstance(structure, basestring) and dset_name != "":
(self.get_handler(structure)
.bundle(structure, data_bundle_hdf_path, dset_name))
elif isinstance(structure, list):
if structure_config.get('concat', False):
self.fill_concat_data(data_bundle_hdf_path, dset_name,
structure, buffer_size)
else:
for data_key in structure:
(self.get_handler(data_key)
.bundle(data_key, data_bundle_hdf_path,
dset_name + "/" + data_key))
elif isinstance(structure, dict):
for key, val in six.viewitems(structure):
_bundle_data(val, structure_config.get(key, {}),
dset_name + "/" + key)
else:
raise TypeError("The bundle structure only support "
"dict, list and str (except the first layer).")
if os.path.isfile(data_bundle_hdf_path):
os.remove(data_bundle_hdf_path)
with SimpleTimer("Bundling data"):
_bundle_data(structure, structure_config)
评论列表
文章目录