from _in_package import * import config def formatting_path(path: str) -> str: path = path.strip() path = path.replace("\\", "/") if path[-1] != "/": path += "/" return path def get_exe_dir(): if getattr(sys, "frozen", False): exe_dir = os.path.dirname(os.path.abspath(sys.executable)) else: exe_dir = os.path.dirname(os.path.abspath(__file__)) return formatting_path(exe_dir) def get_config(config_key: str): if config.configdir_path == None: match platform.system(): case "Linux": if os.path.isfile(config.exe_dir + "conf.dir"): with open(config.exe_dir + "conf.dir") as cpf: configdir_path = cpf.read().strip() else: configdir_path = "/etc/check_duplicate_files/" case "Windows": if os.path.isfile(config.exe_dir + "conf.dir"): with open(config.exe_dir + "conf.dir") as cpf: configdir_path = cpf.read().strip() else: configdir_path = config.exe_dir + "conf.d/" config.configdir_path = formatting_path(configdir_path) config_path = config.configdir_path + config_key if not (os.path.isfile(config_path)): return None with open(config_path, "r", encoding="utf-8") as conf: conf_v = conf.read().strip() return conf_v def safe_format(fmt_str: str, *args) -> str: try: return fmt_str.format(*args) 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