Provision desktop file with Jinja to put in version number

This way the Desktop file for the AppImage knows the version number, and the appimage itself knows it too.

Contributes to issue CURA-9409.
This commit is contained in:
Ghostkeeper 2022-06-30 14:42:14 +02:00
parent c2f3161fb6
commit 047d7b1b19
No known key found for this signature in database
GPG key ID: 68F39EA88EEED5FF
2 changed files with 28 additions and 3 deletions

View file

@ -2,6 +2,7 @@
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import argparse # Command line arguments parsing and help. import argparse # Command line arguments parsing and help.
from jinja2 import Template
import os # Finding installation directory. import os # Finding installation directory.
import os.path # Finding files. import os.path # Finding files.
import shutil # Copying files. import shutil # Copying files.
@ -12,7 +13,7 @@ def build_appimage(dist_path, version):
""" """
Creates an AppImage file from the build artefacts created so far. Creates an AppImage file from the build artefacts created so far.
""" """
copy_metadata_files(dist_path) copy_metadata_files(dist_path, version)
appimage_filename = f"Ultimaker-Cura_{version}.AppImage" appimage_filename = f"Ultimaker-Cura_{version}.AppImage"
try: try:
@ -24,13 +25,12 @@ def build_appimage(dist_path, version):
sign_appimage(dist_path, appimage_filename) sign_appimage(dist_path, appimage_filename)
def copy_metadata_files(dist_path): def copy_metadata_files(dist_path, version):
""" """
Copy metadata files for the metadata of the AppImage. Copy metadata files for the metadata of the AppImage.
""" """
copied_files = { copied_files = {
"cura-icon_256x256.png": "cura-icon.png", "cura-icon_256x256.png": "cura-icon.png",
"cura.desktop": "cura.desktop",
"cura.appdata.xml": "cura.appdata.xml", "cura.appdata.xml": "cura.appdata.xml",
"AppRun": "AppRun" "AppRun": "AppRun"
} }
@ -41,8 +41,18 @@ def copy_metadata_files(dist_path):
shutil.copyfile(os.path.join(packaging_dir, source), os.path.join(dist_path, dest)) shutil.copyfile(os.path.join(packaging_dir, source), os.path.join(dist_path, dest))
# Ensure that AppRun has the proper permissions: 755 (user reads, writes and executes, group reads and executes, world reads and executes). # Ensure that AppRun has the proper permissions: 755 (user reads, writes and executes, group reads and executes, world reads and executes).
print("Changing permissions for AppRun")
os.chmod(os.path.join(dist_path, "AppRun"), stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) os.chmod(os.path.join(dist_path, "AppRun"), stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
# Provision the Desktop file with the correct version number.
template_path = os.path.join(packaging_dir, "cura.desktop.jinja")
desktop_path = os.path.join(dist_path, "cura.desktop")
print("Provisioning desktop file from", template_path, "to", desktop_path)
with open(template_path, "r") as f:
desktop_file = Template(f.read())
with open(desktop_path, "w") as f:
f.write(desktop_file.render(cura_version = version))
def generate_appimage(dist_path, appimage_filename): def generate_appimage(dist_path, appimage_filename):
appimage_path = os.path.join(dist_path, appimage_filename) appimage_path = os.path.join(dist_path, appimage_filename)
command = ["appimagetool", "--appimage-extract-and-run", f"{dist_path}/", appimage_path] command = ["appimagetool", "--appimage-extract-and-run", f"{dist_path}/", appimage_path]

View file

@ -0,0 +1,15 @@
[Desktop Entry]
Name=Ultimaker Cura
Name[de]=Ultimaker Cura
GenericName=3D Printing Software
GenericName[de]=3D-Druck-Software
GenericName[nl]=3D-Print Software
Comment=Cura converts 3D models into paths for a 3D printer. It prepares your print for maximum accuracy, minimum printing time and good reliability with many extra features that make your print come out great.
Exec=Ultimaker-Cura %F
Icon=cura-icon
Terminal=false
Type=Application
MimeType=model/stl;application/vnd.ms-3mfdocument;application/prs.wavefront-obj;image/bmp;image/gif;image/jpeg;image/png;text/x-gcode;application/x-amf;application/x-ply;application/x-ctm;model/vnd.collada+xml;model/gltf-binary;model/gltf+json;model/vnd.collada+xml+zip;
Categories=Graphics;
Keywords=3D;Printing;
X-AppImage-Version={{ cura_version }}