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