def generate_module_menu_def(module): menu_def = {} menu_def['intended_use'] = 'html' moddir = module['moddir'] menu_def["lang"] = module['lang'] menu_def["title"] = module['title'] menu_def["start_url"] = '' menu_def['moddir'] = moddir menu_def['description'] = module.get('description', '') menu_def['extra_description'] = '' size = float(module.get('ksize', '0')) * 1024.0 size = iiab.human_readable(size) files = module.get('file_count', 'undefined') if files == None: files = '' age = module.get('age_range', 'undefined') if age == None: age = '' menu_def['footnote'] = "Size: " + size + ', Files: ' + str( files) + ', Age: ' + age return menu_def
def write_zim_versions_idx(zim_versions, kiwix_library_xml, zim_version_idx_dir, zim_menu_defs): zims_installed, path_to_id_map = iiab.read_library_xml(kiwix_library_xml) # drives off of zim_versions which is what is in file system for perma_ref in zim_versions: zim_versions[perma_ref]['menu_item'] = zim_menu_defs.get( perma_ref, {}).get('name') articlecount, mediacount, size, tags, lang, date = \ get_substitution_data(perma_ref, zim_versions, zims_installed, path_to_id_map) zim_versions[perma_ref]['article_count'] = articlecount zim_versions[perma_ref]['media_count'] = mediacount size = iiab.human_readable(float(size) * 1024) # kiwix reports in K zim_versions[perma_ref]['size'] = size zim_versions[perma_ref]['tags'] = tags zim_versions[perma_ref]['language'] = lang zim_versions[perma_ref]['zim_date'] = date # Write Version Map if os.path.isdir(zim_version_idx_dir): with open(zim_version_idx_dir + CONST.zim_version_idx_file, 'w') as fp: fp.write(json.dumps(zim_versions, indent=2)) fp.close() else: print(zim_version_idx_dir + " not found.")