def init(logger): """ verify that the CATALOGS and CONTENTS list are populated (not empty) """ logger.step("initializing...", end="") nb_contents = len(CONTENTS) nb_packages = sum([len(c["all"]) for c in get_catalogs(logger)]) nums = "({}+{})".format(nb_contents, nb_packages) if not nb_contents or not nb_packages: logger.err("FAILED. Check your internet connection. {}".format(nums)) sys.exit(1) logger.succ("OK {}".format(nums))
def package_is_latest_version(fpath, fname, logger): """ whether a package (ZIM or ZIP) is in the current catalog """ for catalog in get_catalogs(logger): for (package_id, package) in catalog["all"].items(): package.update({"ext": "zip" if package["type"] != "zim" else "zim"}) package.update({"langid": package.get("langid") or package_id}) rfname = "package_{langid}-{version}.{ext}".format(**package) if rfname == fname and get_checksum(fpath) == package["sha256sum"]: return "{ext}: {fname}".format( fname=package["langid"], ext=package["ext"].upper() ) return False
def run_phase_one(machine, extra_vars, secret_keys, homepage, logo=None, favicon=None, css=None): """ run ansiblecube in machine to configure requested softwares """ tags = ["rename", "reconfigure"] # copy homepage machine.put_file(homepage, "/tmp/home.html") # copy branding files if set branding = {"favicon.png": favicon, "logo.png": logo, "style.css": css} has_custom_branding = False for fname, item in [(k, v) for k, v in branding.items() if v is not None]: has_custom_branding = True machine.put_file(item, "/tmp/{}".format(fname)) extra_vars.update({"has_custom_branding": has_custom_branding}) # save YAML catalogs into local files inside VM for use by ideascube for index, catalog in enumerate(CATALOGS): with tempfile.NamedTemporaryFile(suffix=".yml", delete=False) as fd: yaml.safe_dump( get_catalogs(machine._logger)[index], fd, default_flow_style=False, allow_unicode=True, encoding="utf-8", ) machine.put_file(fd.name, catalog["local_url"].replace("file://", "")) try: os.unlink(fd.name) except Exception as exp: machine._logger.err(str(exp)) run(machine, tags, extra_vars, secret_keys)
def get_package_content(package_id): """ content-like dict for packages (zim file or static site) """ for catalog in get_catalogs(CLILogger()): try: package = catalog["all"][package_id] package.update( {"ext": "zip" if package["type"] != "zim" else "zim"}) package.update({"langid": package.get("langid") or package_id}) return { "url": package["url"], "name": "{langid}.{ext}".format(**package), "checksum": package["sha256sum"], "archive_size": package["size"], # add a 10% margin for non-zim (zip file mostly) "expanded_size": package["size"] * 1.1 if package["type"] != "zim" else package["size"], } except KeyError: continue
nargs="*") parser.add_argument("-z", "--zim-install", help="install zim", nargs="*") parser.add_argument("-r", "--resize", help="resize image in GiB (5)", type=float, default=5) parser.add_argument("-c", "--catalog", help="print zim catalog", action="store_true") parser.add_argument("-s", "--sd", help="sd card device to put the image onto") args = parser.parse_args() if args.catalog: for catalog in catalog.get_catalogs(): print(yaml.dump(catalog, default_flow_style=False, default_style='')) exit(0) run_installation(name=args.name, timezone=args.timezone, wifi_pwd=args.wifi_pwd, kalite=args.kalite, zim_install=args.zim_install, size=args.resize, logger=Logger, cancel_event=CancelEvent(), sd_card=args.sd, output_file=not args.sd)
self.update_free_space() def choosen_zim_clicked(self, tree_view, path, column): tree_view.get_model()[path][8] = False tree_view.get_selection().unselect_all() self.update_free_space() def zim_done_button_clicked(self, widget): self.component.zim_window.hide() def zim_filter_func(self, model, iter, data): return model[iter][10] and not model[iter][8] def choosen_zim_filter_func(self, model, iter, data): return model[iter][8] try: catalog = catalog.get_catalogs() except Exception as exception: dialog = ShortDialog( None, (Gtk.STOCK_OK, Gtk.ResponseType.OK), "Catalog downloads failed, you may check your internet connection") dialog.run() print(exception, file=sys.stderr) dialog.destroy() exit(1) Application(catalog) Gtk.main()
setif(arg_key, value) # bool contents (switch) for key in ("edupi", "aflatoun", "nomad", "mathews"): if config["content"].get(key) is not None: vl = "yes" if config["content"][key] in ("yes", True) else "no" setif(key, vl) # edupi resources if config["content"].get("edupi_resources") is not None: rsc = config["content"]["edupi_resources"] setif("edupi_resources", rsc if isremote(rsc) else os.path.abspath(rsc)) if get_catalogs(logger) is None: print("Catalog downloads failed, you may check your internet connection") sys.exit(2) zim_choices = [] for catalog in get_catalogs(logger): for (key, value) in catalog["all"].items(): zim_choices.append(key) languages = [code for code, language in data.hotspot_languages] defaults = { "name": "Kiwix", "timezone": str(tzlocal.get_localzone()), "language": "en", "size": "8GB",