def get_cache_size_and_free_space(build_folder, cache_folder): """ shortcut to query both cache folder size and build-dir free space """ return ( get_folder_size(cache_folder), len(os.listdir(cache_folder)), get_free_space_in_dir(cache_folder), )
def run_installation_button_clicked(self, button): all_valid = True project_name = self.component.project_name_entry.get_text() allowed_chars = set(string.ascii_uppercase + string.ascii_lowercase + string.digits + '-') condition = len(project_name) >= 1 and len(project_name) <= 64 and set( project_name) <= allowed_chars validate_label(self.component.project_name_label, condition) self.component.project_name_constraints_revealer.set_reveal_child( not condition) all_valid = all_valid and condition language_id = self.component.language_combobox.get_active() language = data.ideascube_languages[language_id][0] condition = language_id != -1 validate_label(self.component.language_label, condition) all_valid = all_valid and condition timezone_id = self.component.timezone_combobox.get_active() timezone = self.component.timezone_tree_store[timezone_id][0] condition = timezone_id != -1 validate_label(self.component.timezone_label, condition) all_valid = all_valid and condition if self.component.wifi_password_switch.get_state(): wifi_pwd = None condition = True else: wifi_pwd = self.component.wifi_password_entry.get_text() condition = len(wifi_pwd) <= 31 and set( wifi_pwd) <= set(string.ascii_uppercase + string.ascii_lowercase + string.digits) self.component.wifi_password_constraints_revealer.set_reveal_child( not condition) validate_label(self.component.wifi_password_label, condition) all_valid = all_valid and condition if not self.component.admin_account_switch.get_state(): admin_account = None login_condition = True pwd_condition = True else: admin_account = { "login": self.component.admin_account_login_entry.get_text(), "pwd": self.component.admin_account_pwd_entry.get_text(), } login_condition = len(admin_account["login"]) <= 31 and set( admin_account["login"]) <= set(string.ascii_uppercase + string.ascii_lowercase + string.digits) pwd_condition = len(admin_account["pwd"]) <= 31 and set( admin_account["pwd"]) <= set(string.ascii_uppercase + string.ascii_lowercase + string.digits) self.component.admin_account_login_constraints_revealer.set_reveal_child( not login_condition) self.component.admin_account_pwd_constraints_revealer.set_reveal_child( not pwd_condition) validate_label(self.component.admin_account_login_label, login_condition) validate_label(self.component.admin_account_pwd_label, pwd_condition) all_valid = all_valid and pwd_condition and login_condition zim_install = [] for zim in self.component.zim_list_store: if zim[8]: zim_install.append(zim[0]) output_size = self.get_output_size() if self.component.output_stack.get_visible_child_name() == "sd_card": sd_card_id = self.component.sd_card_combobox.get_active() condition = sd_card_id != -1 validate_label(self.component.sd_card_label, condition) all_valid = all_valid and condition if sd_card_id == -1: sd_card = None else: device_index = sd_card_info.get_device_index() sd_card = self.component.sd_card_list_store[sd_card_id][ device_index] else: sd_card = None condition = output_size > 0 validate_label(self.component.size_label, condition) all_valid = all_valid and condition condition = self.update_free_space() >= 0 validate_label(self.component.free_space_name_label, condition) all_valid = all_valid and condition kalite_active_langs = [ lang for lang, button in self.iter_kalite_check_button() if button.get_active() ] if len(kalite_active_langs) != 0: kalite = kalite_active_langs else: kalite = None wikifundi_active_langs = [ lang for lang, button in self.iter_wikifundi_check_button() if button.get_active() ] if len(wikifundi_active_langs) != 0: wikifundi = wikifundi_active_langs else: wikifundi = None aflatoun = self.component.aflatoun_switch.get_active() edupi = self.component.edupi_switch.get_active() logo = self.component.logo_chooser.get_filename() favicon = self.component.favicon_chooser.get_filename() css = self.component.css_chooser.get_filename() build_dir = self.component.build_path_chooser.get_filename() condition = build_dir != None validate_label(self.component.build_path_chooser_label, condition) all_valid = all_valid and condition # Check if there is enough space in build_dir to build image if build_dir != None: free_space = get_free_space_in_dir(build_dir) remaining_space = free_space - output_size if remaining_space < 0: self.component.space_error_image_location_label.set_text( build_dir) self.component.space_error_total_space_required_label.set_text( human_readable_size(output_size)) self.component.space_error_space_available_label.set_text( human_readable_size(free_space)) self.component.space_error_space_missing_label.set_text( human_readable_size(-remaining_space)) self.component.space_error_window.show() all_valid = False if all_valid: def target(): run_installation(name=project_name, timezone=timezone, language=language, wifi_pwd=wifi_pwd, kalite=kalite, wikifundi=wikifundi, aflatoun=aflatoun, edupi=edupi, zim_install=zim_install, size=output_size, logger=self.logger, cancel_event=self.cancel_event, sd_card=sd_card, logo=logo, favicon=favicon, css=css, build_dir=build_dir, admin_account=admin_account, done_callback=lambda error: GLib.idle_add( self.installation_done, error)) self.component.window.hide() self.reset_run_window() self.component.run_window.show() threading.Thread(target=target, daemon=True).start()
space=" " * (longest - len(name)))) # check disk space collection = get_collection( edupi=args.edupi == "yes", edupi_resources=args.edupi_resources, nomad=args.nomad == "yes", mathews=args.mathews == "yes", packages=args.zim_install, kalite_languages=args.kalite, wikifundi_languages=args.wikifundi, aflatoun_languages=["fr", "en"] if args.aflatoun == "yes" else [], ) cache_folder = get_cache(args.build_dir) # how much space is available on the build directory? avail_space_in_build_dir = get_free_space_in_dir(args.build_dir) try: # how much space do we need to build the image? space_required_to_build = get_required_building_space( collection, cache_folder, args.output_size) # how large should the image be? required_image_size = get_required_image_size(collection) except FileNotFoundError as exp: print("Supplied File Not Found: {}".format(exp.filename), file=sys.stderr) sys.exit(1) base_image_size = get_content("hotspot_master_image")["expanded_size"] if args.size < base_image_size: print( "image size can not be under {size}".format( size=human_readable_size(base_image_size, False)),
set_config(config, args) if args.catalog: for catalog in catalogs: print(yaml.dump(catalog, default_flow_style=False, default_style='')) exit(0) if args.admin_account: admin_account = { "login": args.admin_account[0], "pwd": args.admin_account[1] } else: admin_account = None build_free_space = get_free_space_in_dir(args.build_dir) if build_free_space < args.size: print("Not enough space available at {} to build image".format( args.build_dir), file=sys.stderr) exit(1) space_required = compute_space_required(catalog=catalogs, zim_list=args.zim_install, kalite=args.kalite, wikifundi=args.wikifundi, aflatoun=args.aflatoun, edupi=args.edupi) if args.size < space_required: print("image size ({}) is not large enough for the content ({})".format( args.size, space_required),