Пример #1
0
def remove_suffix(name):
    if util.is_reply(name):
        return util.remove_reply_suffix(name)
    else:
        if util.is_dump(name):
            return util.remove_suffix(name, util.dump_suffix)
        else:
            return name
Пример #2
0
def remove_suffix(name):
    if util.is_reply(name):
        return util.remove_reply_suffix(name)
    else:
        if util.is_dump(name):
            return util.remove_suffix(name, util.dump_suffix)
        else:
            return name
Пример #3
0
def decompress_file_with_lzma(compressed_7z_filepath: str, filepath: str = ""):
    if filepath == "":
        from util import remove_suffix
        filepath = remove_suffix(compressed_7z_filepath, ".7z")

    compressed_7z_filepath = realpath(compressed_7z_filepath)
    filepath = realpath(filepath)

    # 解压缩
    logger_func(f"开始解压缩 {compressed_7z_filepath} 为 文件 {filepath}")

    # 先解压缩到临时文件
    temp_target_path = f"{filepath}.decompressed"
    with lzma.open(f"{compressed_7z_filepath}", "rb") as file_in:
        with open(f"{temp_target_path}", "wb") as file_out:
            file_out.writelines(file_in)

    # 解压缩完成后再替换到目标文件,减少目标文件不可用的时长
    os.replace(temp_target_path, filepath)
Пример #4
0
def test_remove_suffix():
    assert remove_suffix("test_suffix", "_suffix") == "test"
    assert remove_suffix("test_suffix", "not_exist_suffix") == "test_suffix"