def main(): zim_path = iiab.CONST.zim_path zim_version_idx_dir = "" if adm_cons_installed: zim_version_idx_dir = adm.CONST.zim_version_idx_dir args = parse_args() # args.device is either value or None if args.device: # allow override of path zim_path = args.device + zim_path zim_version_idx_dir = args.device + zim_version_idx_dir kiwix_library_xml = zim_path + "/library.xml" if not args.no_tmp: # don't append .tmp kiwix_library_xml += ".tmp" # remove existing file if force if args.force: try: os.remove(kiwix_library_xml) except OSError: pass zims_installed = {} path_to_id_map = {} else: zims_installed, path_to_id_map = iiab.read_library_xml( kiwix_library_xml) zim_files, zim_versions = iiab.get_zim_list(zim_path) # Remove zims not in file system from library.xml remove_list_str = "" for item in path_to_id_map: if item not in zim_files: iiab.rem_libr_xml(path_to_id_map[item], kiwix_library_xml) # Add zims from file system that are not in library.xml for item in zim_files: if item not in path_to_id_map: iiab.add_libr_xml(kiwix_library_xml, zim_path, item, zim_files[item]) # Create zim_versions_idx if Admin Console installed if adm_cons_installed: print("Writing zim_versions_idx") iiab.read_lang_codes() # needed by following zim_menu_defs = adm.get_zim_menu_defs() # read all menu defs adm.write_zim_versions_idx(zim_versions, kiwix_library_xml, zim_version_idx_dir, zim_menu_defs) sys.exit()
def put_kiwix_enabled_into_menu_json(): # steps: # 1. Make sure all downloaded zims are in zim_verion_idx # 2. Look for a back link to perma_ref in menu_defs_dir # 3. If back link exist update, otherwise create new menuDef # check for un-indexed zims in zims/content/,write to zim_versions_idx.json iiab.read_lang_codes() # initialize zim_menu_defs = get_zim_menu_defs() # read all menu defs zim_files, zim_versions = iiab.get_zim_list(iiab.CONST.zim_path) write_zim_versions_idx(zim_versions, iiab.CONST.kiwix_library_xml, CONST.zim_version_idx_dir, zim_menu_defs) zims_installed, path_to_id_map = iiab.read_library_xml( iiab.CONST.kiwix_library_xml) # use that data zim_idx = CONST.zim_version_idx_dir + CONST.zim_version_idx_file if os.path.isfile(zim_idx): with open(zim_idx, "r") as zim_fp: zim_versions_info = json.loads(zim_fp.read()) for perma_ref in zim_versions_info: #print(perma_ref) # if other zims exist, do not add test zim if len(zim_versions_info) > 1 and perma_ref == 'tes': continue # check if menu def exists for this perma_ref menu_item_name = zim_menu_defs.get(perma_ref, {}).get('name') if menu_item_name == None: # no menu def points to this perma_ref # create the canonical menu_item name lang = zim_versions_info[perma_ref].get('language', 'en') new_def_name = lang + '-' + perma_ref new_def_name = new_def_name.replace( '.', '_') # handle embedded '.' if new_def_name in zim_menu_defs: # name already taken new_def_name += '1' # OK this could exist too, but really path = zim_versions[perma_ref].get('file_name') + '.zim' zim_id = path_to_id_map['content/' + path] zim_info = zims_installed[zim_id] new_menu_def = generate_zim_menu_def( perma_ref, new_def_name, zim_info) new_menu_def = format_menu_item_def( new_def_name, new_menu_def) print("Creating %s" % new_def_name) write_menu_item_def(new_def_name, new_menu_def, change_ref='generated') menu_item_name = new_def_name update_menu_json(menu_item_name) # add to menu
import json import subprocess import shlex from datetime import date import base64 import iiab.iiab_lib as iiab import iiab.adm_lib as adm try: adm.pcgvtd9() except: print("Unable to contact Server") sys.exit(1) # load lang codes iiab.read_lang_codes() local_menu_item_defs = adm.get_local_menu_item_defs() # returns dict menu_def_repo_data = adm.get_menu_def_repo_data() # returns dict repo_menu_item_defs = menu_def_repo_data['defs'] obsolete_menu_item_defs = adm.read_json(adm.CONST.obsolete_menu_defs) changes_made = False # download menu item defs from repo that are not present for menu_item_def_name in repo_menu_item_defs: if menu_item_def_name not in local_menu_item_defs: if menu_item_def_name in obsolete_menu_item_defs: print('Skipping obsolete menu definition ' + menu_item_def_name) continue # don't download obsolete menu_item_def = adm.get_menu_item_def_from_repo_by_name(menu_item_def_name) adm.write_other_menu_item_def_files(menu_item_def)