python自动产生版本号,版本号+1

发布时间:2024年01月15日
def get_new_version():
    # 读取文件内容
    with open("xxx.desktop", "r") as file:
        content = file.read()

    # 使用正则表达式查找版本号
    version_match = re.search(r"Version=(\d+\.\d+\.\d+)", content)

    # 提取当前版本号
    current_version = version_match.group(1)
    # 将版本号加1
    current_version_items = current_version.split(".")
    int_version_items = [int(item) for item in current_version_items]

    if int_version_items[2] + 1 >= 10:
        int_version_items[2] = 0
        if int_version_items[1] + 1 >= 10:
            int_version_items[1] = 0
            int_version_items[0] = int_version_items[0] + 1
        else:
            int_version_items[1] = int_version_items[1] + 1
    else:
        int_version_items[2] = int_version_items[2] + 1

    latest_version = ".".join([str(v) for v in int_version_items])
    content = content.replace(current_version, latest_version)

    # 将修改后的内容写回文件
    with open("xxx.desktop", "w") as file:
        pass
        file.write(content)

    return latest_version
[Desktop Entry]
Version=1.0.0
Name=Appliaction Name
Exec=/home/orangepi/app/start.sh
Icon=/home/orangepi/app/logo.png
Type=Application
Terminal=true
MimeType=application/x-desktop;text/uri-list;inode/directory;
StartupNotify=true

文章来源:https://blog.csdn.net/weixin_36878452/article/details/135597747
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。