def present_fs_info(self, info): total_str = "?" if info["total"] is None else sizeof_fmt(info["total"]) used_str = "?" if info["used"] is None else sizeof_fmt(info["used"]) free_str = "?" if info["free"] is None else sizeof_fmt(info["free"]) text = ("Storage space on this drive or filesystem:\n\n" " total: %s\n" % total_str + " used: %s\n" % used_str + " free: %s\n" % free_str) if info.get("comment"): text += "\n" + info["comment"] messagebox.showinfo("Storage info", text)
def pick_transfer_items(prepared_items: List[Dict], existing_target_items: Dict[str, Dict], master) -> List[Dict]: if not existing_target_items: return prepared_items errors = [] overwrites = [] for item in prepared_items: if item["target_path"] in existing_target_items: target_info = existing_target_items[item["target_path"]] if item["kind"] != target_info["kind"]: errors.append( "Can't overwrite '%s' with '%s', because former is a %s but latter is a %s" % (item["target_path"], item["source_path"], target_info["kind"], item["kind"])) elif item["kind"] == "file": size_diff = item["size"] - target_info["size"] if size_diff > 0: replacement = "a larger file (%s + %s)" % ( sizeof_fmt(target_info["size"]), sizeof_fmt(size_diff), ) elif size_diff < 0: replacement = "a smaller file (%s - %s)" % ( sizeof_fmt(target_info["size"]), sizeof_fmt(-size_diff), ) else: replacement = "a file of same size (%s)" % sizeof_fmt( target_info["size"]) overwrites.append("'%s' with %s" % (item["target_path"], replacement)) if errors: showerror("Error", format_items(errors), master=master) return [] elif overwrites: if askokcancel( "Overwrite?", "This operation will overwrite\n\n" + format_items(overwrites), master=master, ): return prepared_items else: return [] else: return prepared_items
def present_fs_info(self, info): total_str = "?" if info["total"] is None else sizeof_fmt(info["total"]) used_str = "?" if info["used"] is None else sizeof_fmt(info["used"]) free_str = "?" if info["free"] is None else sizeof_fmt(info["free"]) text = tr("Storage space on this drive or filesystem") + ":\n\n" " %s: %s\n" % ( tr("total space"), total_str, ) + " %s: %s\n" % (tr("used space"), used_str) + " %s: %s\n" % ( tr("free space"), free_str, ) if info.get("comment"): text += "\n" + info["comment"] messagebox.showinfo(tr("Storage info"), text, master=self)
def show_properties(self): node_id = self.get_selected_node() if node_id is None: self.notify_missing_selection() return values = self.tree.set(node_id) text = tr("Path") + ":\n " + values["path"] + "\n\n" if values["kind"] == "dir": title = tr("Directory properties") else: title = tr("File properties") size_fmt_str = sizeof_fmt(int(values["size"])) bytes_str = str(values["size"]) + " " + tr("bytes") text += ( tr("Size") + ":\n " + ( bytes_str if size_fmt_str.endswith(" B") else size_fmt_str + " (" + bytes_str + ")" ) + "\n\n" ) if values["modified"].strip(): text += tr("Modified") + ":\n " + values["modified"] + "\n\n" messagebox.showinfo(title, text.strip(), master=self)
def _cmd_get_fs_info(self, cmd): result = self._evaluate( dedent( """ try: from os import statvfs as __thonny_statvfs __thonny_stat = __thonny_statvfs(%r) __thonny_total = __thonny_stat[2] * __thonny_stat[0] __thonny_free = __thonny_stat[3] * __thonny_stat[0] __thonny_used = __thonny_total - __thonny_free __thonny_sizes = None del __thonny_statvfs del __thonny_stat except ImportError: import os as __thonny_helper.os __thonny_sizes = [__thonny_helper.os.size(name) for name in __thonny_helper.listdir()] __thonny_used = None __thonny_total = None __thonny_free = None __thonny_helper.print_mgmt_value({ "total" : __thonny_total, "used" : __thonny_used, "free": __thonny_free, "sizes": __thonny_sizes }) del __thonny_total del __thonny_free del __thonny_used del __thonny_sizes """ ) % cmd.path ) if result["sizes"] is not None: if self._connected_to_microbit(): comment = "Assuming around 30 kB of storage space for user files." else: comment = "Don't know the size of storage space on this device." files_total_size = sum(result["sizes"]) # TODO: compute number of used blocks if files_total_size > 0: comment += "\n\n" + "At least %s of it is used by %d file(s)." % ( sizeof_fmt(files_total_size), len(result["sizes"]), ) result["comment"] = comment del result["sizes"] return result