diff --git a/.gitignore b/.gitignore index 146e3f0..df52134 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ build *.backup /.venv /.vscode -/conf.d \ No newline at end of file +/conf.d +/test.py \ No newline at end of file diff --git a/app.py b/app.py index 51f37c0..148cf09 100644 --- a/app.py +++ b/app.py @@ -51,8 +51,22 @@ def print_info(hash_to_files_list: list = runing_data.hash_to_files): for fp in runing_data.hash_to_files[t]: print("\t", fp) print() - print(common.safe_format(config.l10n_data.get_text("info_print_info_duplicate_msg"), (size_total-size_if_one)//1024, size_total//1024)) - print(common.safe_format(config.l10n_data.get_text("info_print_info_if_size-flag_duplicate_msg"), config.flag_size, (print_size_total-print_size_if_one)//1024, print_size_total//1024)) + if size_total == size_if_one: + print(config.l10n_data.get_text("info_print_info_not_duplicate_msg")) + + size_duplicate = size_total - size_if_one + print_size_duplicate = print_size_total - print_size_if_one + + size_total = common.add_unit(size_total) + size_duplicate = common.add_unit(size_duplicate) + print_size_total = common.add_unit(print_size_total) + print_size_duplicate = common.add_unit(print_size_duplicate) + print(config.l10n_data.get_text("info_print_info_duplicate_msg"), end="\t") + print(f"\t{size_duplicate} / {size_total}") + + if config.flag_size > 0: + print(common.safe_format(config.l10n_data.get_text("info_print_info_if_size-flag_duplicate_msg"), config.flag_size), end="\t") + print(f"\t{print_size_duplicate} / {print_size_total}") def reg_opts(): diff --git a/common.py b/common.py index 1ddc28b..df12f8d 100644 --- a/common.py +++ b/common.py @@ -3,11 +3,11 @@ import config def formatting_path(path: str) -> str: - path = path.strip() - path = path.replace("\\", "/") - if path[-1] != "/": - path += "/" - return path + path = path.strip() + path = path.replace("\\", "/") + if path[-1] != "/": + path += "/" + return path def get_exe_dir(): if getattr(sys, "frozen", False): @@ -30,7 +30,7 @@ def get_config(config_key: str): config.configdir_path = formatting_path(configdir_path) config_path = config.configdir_path + config_key if not (os.path.isfile(config_path)): - return None + return None with open(config_path, "r", encoding="utf-8") as conf: conf_v = conf.read().strip() return conf_v @@ -39,4 +39,13 @@ def get_config(config_key: str): def safe_format(fmt_str: str, *args) -> str: try: return fmt_str.format(*args) - except: return "__langerr__" \ No newline at end of file + except: return "__langerr__" + +def add_unit(num: int) -> str: + for unit in config.unit_list: + if num >= 1024: + num //= 1024 + else: + num = str(num) + break + return num+unit \ No newline at end of file diff --git a/config.py b/config.py index de3d810..6b80a2c 100644 --- a/config.py +++ b/config.py @@ -10,4 +10,8 @@ lang: str = "zh_cn" l10n_data: I18n.I18nText configdir_path: str = None + +unit_list = ["Byte", "KiB", "MiB", "GiB", "TiB"] + + import I18n \ No newline at end of file diff --git a/lang/zh_cn.lang b/lang/zh_cn.lang index 608e0c4..d7f79f9 100644 --- a/lang/zh_cn.lang +++ b/lang/zh_cn.lang @@ -2,5 +2,6 @@ help_fsize = 只打印文件大小大于fsize Byte的重复文件 tip_traverse_dir = 正在遍历文件ing... info_traverse_dir = 完成 总计 {} 个文件 tip_hash_files_from_glist = 正在计算文件散列ing... -info_print_info_duplicate_msg = 重复部分占用/总占用: {}KiB / {}KiB -info_print_info_if_size-flag_duplicate_msg = 占用大于 {} Byte 的文件中,重复部分占用/总占用: {}KiB / {}KiB \ No newline at end of file +info_print_info_duplicate_msg = 重复部分占用/总占用: +info_print_info_if_size-flag_duplicate_msg = 占用大于 {} Byte 的文件中,重复部分占用/总占用: +info_print_info_not_duplicate_msg = 没有找到重复文件 \ No newline at end of file