def main(): args = parse_args() oer2go_mod_name = args.module dated_oer2go_cat = adm.read_json_file(CONST.oer2go_catalog_file) oer2go_mod = dated_oer2go_cat['modules'][oer2go_mod_name] mv_src = CONST.rachel_working_dir + oer2go_mod_name mv_dest = CONST.iiab_modules_dir + oer2go_mod_name if not os.path.isdir(mv_src): print('Module working directory not found. Exiting.') sys.exit(1) if not os.path.isdir(mv_dest): # only mv is target not exist shutil.move(mv_src, mv_dest) is_downloaded, has_menu_def = adm.get_module_status(oer2go_mod) if not has_menu_def: print('Generating Menu Definition') working_dir = adm.CONST.rachel_working_dir + str(uuid.uuid4()) + "/" os.mkdir(working_dir) menu_item_name = adm.create_module_menu_def(oer2go_mod, working_dir, incl_extra_html=False) shutil.rmtree(working_dir) print('Adding to Home Page Menu') adm.update_menu_json(oer2go_mod_name, no_lang=False)
def main(): print('Updating Home Page Menu') print('Updating kiwix menu items') adm.put_kiwix_enabled_into_menu_json() print('Updating iiab installed services\' menu items') adm.put_iiab_enabled_into_menu_json() print('Updating installed OER2Go menu items') mod_list = adm.get_module_list(adm.CONST.iiab_modules_dir) for module in mod_list: adm.update_menu_json(module, no_lang=False)
def main(): try: adm.get_map_catalog() except: print("OSM Vector Maps are not installed. Exiting.") sys.exit(1) map_menu_def_list = adm.get_map_menu_defs() previous_idx = adm.read_vector_map_idx() installed_maps = adm.get_installed_regions() adm.write_vector_map_idx(installed_maps) # For installed regions, check that a menu def exists, and it's on home page for fname in installed_maps: region = adm.extract_region_from_filename(fname) if region == 'maplist': # it is the splash page, display only if no others menu_item_name = 'en-map_test' map_item = { "perma_ref" : menu_item_name } if len(installed_maps) == 1: adm.update_menu_json(menu_item_name) return elif region not in adm.map_catalog['regions']: print("Skipping unknown map " + fname) continue else: map_item = adm.map_catalog['regions'][region] menu_item_name = map_item['perma_ref'] if not (menu_item_name in map_menu_def_list): print('Creating menu def for %s'%menu_item_name) adm.create_map_menu_def(region, menu_item_name, map_item) # if autoupdate allowed and this is a new region then add to home menu if adm.fetch_menu_json_value('autoupdate_menu') and menu_item_name not in previous_idx: print('Auto-update of menu items is enabled. Adding %s'%region) adm.update_menu_json(menu_item_name) # redirect from box/maps to an installed map rather than test page with open(adm.CONST.map_doc_root + '/index.html','w') as fp: outstr = """<head> \n<meta http-equiv="refresh" content="0; URL=/osm-vector-maps/en-osm-omt_%s " />\n</head>"""%fname fp.write(outstr)
def main(): global verbose oer2go_catalog = {} args = parse_args() if args.verbose: verbose = True # make sure we have menu js_menu_dir if args.menu true if args.menu: if not os.path.isdir(adm.CONST.js_menu_dir): sys.stdout.write( "GET-OER2GO-CAT ERROR - iiab-menu not installed and --menu option given\n" ) sys.stdout.flush() sys.exit(99) # for now we will assume that old modules are still in the current catalog # get new oer2go catalog unless told not to if not args.no_download: try: url_handle = urllib.request.urlopen(adm.CONST.oer2go_cat_url) oer2go_catalog_json = url_handle.read() url_handle.close() except (urllib.error.URLError) as exc: sys.stdout.write("GET-OER2GO-CAT ERROR - " + str(exc.reason) + '\n') sys.stdout.flush() sys.exit(1) try: url_handle = urllib.request.urlopen(adm.CONST.iiab_module_cat_url) iiab_catalog_json = url_handle.read() url_handle.close() except (urllib.error.URLError) as exc: sys.stdout.write("GET-OER2GO-CAT ERROR - " + str(exc.reason) + '\n') sys.stdout.flush() sys.exit(2) # now try to parse try: oer2go_catalog = json.loads(oer2go_catalog_json) iiab_catalog = json.loads(iiab_catalog_json) except: sys.stdout.write("GET-OER2GO-CAT ERROR - " + str(sys.exc_info()[0]) + "," + str(sys.exc_info()[1]) + '\n') sys.stdout.flush() sys.exit(3) # merge iiab_catalog.json if was downloaded otherwise assume was previously merged for item in iiab_catalog: moddir = item['moddir'] id = item['module_id'] module = item iiab_oer2go_catalog[moddir] = module else: local_oer2go_catalog = adm.read_json(adm.CONST.oer2go_catalog_file) oer2go_catalog = local_oer2go_catalog['modules'] working_dir = adm.CONST.rachel_working_dir + str(uuid.uuid4()) + "/" os.mkdir(working_dir) #os.mkdir(iiab_menu_download_dir) for item in oer2go_catalog: # structure of local and remote catalogs is different if args.no_download: # local moddir = item module = oer2go_catalog[moddir] module_id = module['module_id'] else: # remote moddir = item['moddir'] module_id = item['module_id'] module = item if moddir is None: # skip items with no moddir continue menu_item_name = moddir if module_id not in dup_list: is_downloaded, has_menu_def = adm.get_module_status(module) if args.menu and is_downloaded: if not has_menu_def: menu_item_name = adm.create_module_menu_def( module, working_dir, incl_extra_html=False) msg = "Generating menu files" if verbose: print("%s %s %s" % (msg, module_id, moddir)) adm.update_menu_json( menu_item_name) # only adds if not already in menu else: msg = "Skipping module not needed by Internet in a Box" if verbose: print("%s %s %s" % (msg, module_id, moddir)) continue iiab_oer2go_catalog[moddir] = module # no need to write catalog if not downloaded as we don't need wip and other extra menu def fields if not args.no_download: dated_oer2go_cat = {} dated_oer2go_cat['download_date'] = time.strftime("%Y-%m-%d.%H:%M:%S") dated_oer2go_cat['modules'] = iiab_oer2go_catalog with open(adm.CONST.oer2go_catalog_file, 'w') as outfile: json.dump(dated_oer2go_cat, outfile, indent=2) shutil.rmtree(working_dir) sys.stdout.write("SUCCESS") sys.stdout.flush() sys.exit(0)
def main (): global verbose global download_flag oer2go_catalog = {} err_num = 0 err_str = "SUCCESS" args = parse_args() if args.verbose: verbose = True if args.no_download: download_flag = False # make sure we have menu js_menu_dir if args.menu true if args.menu: if not os.path.isdir(adm.CONST.js_menu_dir): sys.stdout.write("GET-OER2GO-CAT ERROR - iiab-menu not installed and --menu option given\n") sys.stdout.flush() sys.exit(99) # always get our catalog # failure is fatal try: url_handle = urllib.request.urlopen(adm.CONST.iiab_module_cat_url) iiab_catalog_json = url_handle.read() url_handle.close() iiab_catalog = json.loads(iiab_catalog_json) except (urllib.error.URLError) as exc: sys.stdout.write("GET-OER2GO-CAT ERROR - " + str(exc.reason) +'\n') sys.stdout.flush() sys.exit(2) # for now we will assume that old modules are still in the current catalog # get new oer2go catalog unless told not to if download_flag: err_num, err_str, oer2go_catalog = get_oer2go_cat() if err_num != 0: download_flag = False if not download_flag: # get local copy local_oer2go_catalog = adm.read_json(adm.CONST.oer2go_catalog_file) oer2go_catalog = local_oer2go_catalog['modules'] # start with iiab_catalog.json for item in iiab_catalog: moddir = item['moddir'] id = item['module_id'] module = item iiab_oer2go_catalog[moddir] = module working_dir = adm.CONST.rachel_working_dir + str(uuid.uuid4()) + "/" os.mkdir(working_dir) #os.mkdir(iiab_menu_download_dir) for item in oer2go_catalog: # structure of local and remote catalogs is different if not download_flag: # local moddir = item module = oer2go_catalog[moddir] module_id = module['module_id'] else: # remote moddir = item['moddir'] module_id = item['module_id'] module = item if moddir is None: # skip items with no moddir continue menu_item_name = moddir if str(module_id) in dup_list: msg = "Skipping module not needed by Internet in a Box" if verbose: print("%s %s %s" % (msg, module_id, moddir)) continue if module.get('type') != 'html': continue is_downloaded, has_menu_def = adm.get_module_status (module) #if args.menu and is_downloaded: if args.menu: if not has_menu_def: menu_item_name = adm.create_module_menu_def(module, working_dir, incl_extra_html = False) msg = "Generating menu files" if verbose: print("%s %s %s" % (msg, module_id, moddir)) if is_downloaded: adm.update_menu_json(menu_item_name) # only adds if not already in menu iiab_oer2go_catalog[moddir] = module # write catalog even if not downloaded as our could have changed dated_oer2go_cat = {} dated_oer2go_cat['download_date'] = time.strftime("%Y-%m-%d.%H:%M:%S") dated_oer2go_cat['modules'] = iiab_oer2go_catalog adm.write_json_file(dated_oer2go_cat, adm.CONST.oer2go_catalog_file) shutil.rmtree(working_dir) sys.stdout.write(err_str) sys.stdout.flush() sys.exit(err_num)
def main (): args = parse_args() adm.update_menu_json(args.module, no_lang=False)