Add xdg-uninstall option to setup

This commit is contained in:
Veronica K. B. Olsen
2021-04-02 15:50:20 +02:00
parent a3c4d7c7b6
commit b391d47a40
+67
View File
@@ -641,6 +641,64 @@ def xdgInstall():
return
##
# XDG Uninstallation (xdg-uninstall)
##
def xdgUninstall():
"""Will attempt to uninstall icons and make a launcher.
"""
print("")
print("XDG Uninstall")
print("=============")
print("")
exCode = subprocess.call(
["xdg-desktop-menu", "uninstall", "novelwriter.desktop"]
)
if exCode == 0:
print("Uninstalled menu desktop file")
else:
print(f"Error {exCode}: Could not uninstall menu desktop file")
sizeArr = ["16", "22", "24", "32", "48", "64", "96", "128", "256", "512"]
# App Icon
for aSize in sizeArr:
exCode = subprocess.call([
"xdg-icon-resource", "uninstall", "--noupdate",
"--context", "apps", "--size", aSize, "novelwriter"
])
if exCode == 0:
print(f"Uninstalled app icon size {aSize}")
else:
print(f"Error {exCode}: Could not uninstall app icon size {aSize}")
# Mimetype
for aSize in sizeArr:
exCode = subprocess.call([
"xdg-icon-resource", "uninstall", "--noupdate",
"--context", "mimetypes", "--size", aSize,
"application-x-novelwriter-project"
])
if exCode == 0:
print(f"Uninstalled mime icon size {aSize}")
else:
print(f"Error {exCode}: Could not uninstall mime icon size {aSize}")
# Update Cache
exCode = subprocess.call(["xdg-icon-resource", "forceupdate"])
if exCode == 0:
print("Updated icon cache")
else:
print(f"Error {exCode}: Could not update icon cache")
print("")
print("Done!")
print("")
return
##
# WIN Installation (win-install, launcher)
##
@@ -873,6 +931,7 @@ if __name__ == "__main__":
" install.\n"
" xdg-install Install launcher and icons for freedesktop systems. Run as root or \n"
" with sudo for system-wide install, or as user for single user install.\n"
" Running 'xdg-uninstall' will remove the icons.\n"
" win-install Install desktop and start menu icons for Windows systems.\n"
)
@@ -932,6 +991,14 @@ if __name__ == "__main__":
else:
xdgInstall()
if "xdg-uninstall" in sys.argv:
sys.argv.remove("xdg-uninstall")
if hostOS == OS_WIN:
print("ERROR: Command 'xdg-uninstall' cannot be used on Windows")
sys.exit(1)
else:
xdgUninstall()
if "win-install" in sys.argv:
sys.argv.remove("win-install")
if hostOS == OS_WIN: