Drop XDG functions
This commit is contained in:
-231
@@ -614,216 +614,6 @@ def genMacOSPlist(args: argparse.Namespace) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================================== #
|
|
||||||
# General Installers
|
|
||||||
# =============================================================================================== #
|
|
||||||
|
|
||||||
##
|
|
||||||
# XDG Installation (xdg-install)
|
|
||||||
##
|
|
||||||
|
|
||||||
def xdgInstall(args: argparse.Namespace) -> None:
|
|
||||||
"""Will attempt to install icons and make a launcher."""
|
|
||||||
print("")
|
|
||||||
print("XDG Install")
|
|
||||||
print("===========")
|
|
||||||
print("")
|
|
||||||
|
|
||||||
# Find Executable(s)
|
|
||||||
# ==================
|
|
||||||
|
|
||||||
exOpts = []
|
|
||||||
|
|
||||||
testExec = shutil.which("novelWriter")
|
|
||||||
if testExec is not None:
|
|
||||||
exOpts.append(testExec)
|
|
||||||
|
|
||||||
testExec = shutil.which("novelwriter")
|
|
||||||
if testExec is not None:
|
|
||||||
exOpts.append(testExec)
|
|
||||||
|
|
||||||
testExec = ROOT_DIR / "novelWriter.py"
|
|
||||||
if testExec.is_file():
|
|
||||||
exOpts.append(str(testExec))
|
|
||||||
|
|
||||||
useExec = ""
|
|
||||||
nOpts = len(exOpts)
|
|
||||||
if nOpts == 0:
|
|
||||||
print("Error: No executables for novelWriter found.")
|
|
||||||
sys.exit(1)
|
|
||||||
elif nOpts == 1:
|
|
||||||
useExec = exOpts[0]
|
|
||||||
else:
|
|
||||||
print("Found multiple novelWriter executables:")
|
|
||||||
print("")
|
|
||||||
for iExec, anExec in enumerate(exOpts):
|
|
||||||
print(" [%d] %s" % (iExec, anExec))
|
|
||||||
print("")
|
|
||||||
intVal = int(input("Please select which novelWriter executable to use: "))
|
|
||||||
print("")
|
|
||||||
|
|
||||||
if intVal >= 0 and intVal < nOpts:
|
|
||||||
useExec = exOpts[intVal]
|
|
||||||
else:
|
|
||||||
print("Error: Invalid selection.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
print("Using executable: %s " % useExec)
|
|
||||||
print("")
|
|
||||||
|
|
||||||
# Create and Install Launcher
|
|
||||||
# ===========================
|
|
||||||
|
|
||||||
# Generate launcher
|
|
||||||
desktopFile = ROOT_DIR / "novelwriter.desktop"
|
|
||||||
desktopData = readFile(SETUP_DIR / "data" / "novelwriter.desktop")
|
|
||||||
desktopData = desktopData.replace("Exec=novelwriter", f"Exec={useExec}")
|
|
||||||
writeFile(desktopFile, desktopData)
|
|
||||||
|
|
||||||
# Remove old desktop icon
|
|
||||||
exCode = subprocess.call(
|
|
||||||
["xdg-desktop-icon", "uninstall", "novelwriter.desktop"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Install application launcher
|
|
||||||
exCode = subprocess.call(
|
|
||||||
["xdg-desktop-menu", "install", "--novendor", "novelwriter.desktop"]
|
|
||||||
)
|
|
||||||
if exCode == 0:
|
|
||||||
print("Installed menu launcher file")
|
|
||||||
else:
|
|
||||||
print(f"Error {exCode}: Could not install menu launcher file")
|
|
||||||
|
|
||||||
# Install MimeType
|
|
||||||
# ================
|
|
||||||
|
|
||||||
exCode = subprocess.call([
|
|
||||||
"xdg-mime", "install", "setup/data/x-novelwriter-project.xml"
|
|
||||||
])
|
|
||||||
if exCode == 0:
|
|
||||||
print("Installed mimetype")
|
|
||||||
else:
|
|
||||||
print(f"Error {exCode}: Could not install mimetype")
|
|
||||||
|
|
||||||
# Install Icons
|
|
||||||
# =============
|
|
||||||
|
|
||||||
iconRoot = "setup/data/hicolor"
|
|
||||||
sizeArr = ["16", "24", "32", "48", "64", "128", "256"]
|
|
||||||
|
|
||||||
# App Icon
|
|
||||||
for aSize in sizeArr:
|
|
||||||
exCode = subprocess.call([
|
|
||||||
"xdg-icon-resource", "install", "--novendor", "--noupdate",
|
|
||||||
"--context", "apps", "--size", aSize,
|
|
||||||
f"{iconRoot}/{aSize}x{aSize}/apps/novelwriter.png",
|
|
||||||
"novelwriter"
|
|
||||||
])
|
|
||||||
if exCode == 0:
|
|
||||||
print(f"Installed app icon size {aSize}")
|
|
||||||
else:
|
|
||||||
print(f"Error {exCode}: Could not install app icon size {aSize}")
|
|
||||||
|
|
||||||
# Mimetype
|
|
||||||
for aSize in sizeArr:
|
|
||||||
exCode = subprocess.call([
|
|
||||||
"xdg-icon-resource", "install", "--noupdate",
|
|
||||||
"--context", "mimetypes", "--size", aSize,
|
|
||||||
f"{iconRoot}/{aSize}x{aSize}/mimetypes/application-x-novelwriter-project.png",
|
|
||||||
"application-x-novelwriter-project"
|
|
||||||
])
|
|
||||||
if exCode == 0:
|
|
||||||
print(f"Installed mime icon size {aSize}")
|
|
||||||
else:
|
|
||||||
print(f"Error {exCode}: Could not install 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")
|
|
||||||
|
|
||||||
# Clean up
|
|
||||||
desktopFile.unlink(missing_ok=True)
|
|
||||||
|
|
||||||
print("")
|
|
||||||
print("Done!")
|
|
||||||
print("")
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
# XDG Uninstallation (xdg-uninstall)
|
|
||||||
##
|
|
||||||
|
|
||||||
def xdgUninstall(args: argparse.Namespace) -> None:
|
|
||||||
"""Will attempt to uninstall icons and the launcher."""
|
|
||||||
print("")
|
|
||||||
print("XDG Uninstall")
|
|
||||||
print("=============")
|
|
||||||
print("")
|
|
||||||
|
|
||||||
# Application Menu Icon
|
|
||||||
exCode = subprocess.call(
|
|
||||||
["xdg-desktop-menu", "uninstall", "novelwriter.desktop"]
|
|
||||||
)
|
|
||||||
if exCode == 0:
|
|
||||||
print("Uninstalled menu launcher file")
|
|
||||||
else:
|
|
||||||
print(f"Error {exCode}: Could not uninstall menu launcher file")
|
|
||||||
|
|
||||||
# Desktop Icon
|
|
||||||
# (No longer installed)
|
|
||||||
exCode = subprocess.call(
|
|
||||||
["xdg-desktop-icon", "uninstall", "novelwriter.desktop"]
|
|
||||||
)
|
|
||||||
if exCode == 0:
|
|
||||||
print("Uninstalled desktop launcher file")
|
|
||||||
else:
|
|
||||||
print(f"Error {exCode}: Could not uninstall desktop launcher file")
|
|
||||||
|
|
||||||
# Also include no longer used sizes
|
|
||||||
sizeArr = ["16", "22", "24", "32", "48", "64", "96", "128", "256", "512"]
|
|
||||||
|
|
||||||
# App Icons
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================================== #
|
# =============================================================================================== #
|
||||||
# Process Command Line
|
# Process Command Line
|
||||||
# =============================================================================================== #
|
# =============================================================================================== #
|
||||||
@@ -988,26 +778,5 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
cmdBuildMacOSPlist.set_defaults(func=genMacOSPlist)
|
cmdBuildMacOSPlist.set_defaults(func=genMacOSPlist)
|
||||||
|
|
||||||
# General Installers
|
|
||||||
# ==================
|
|
||||||
|
|
||||||
# Linux XDG Install
|
|
||||||
cmdXDGInstall = parsers.add_parser(
|
|
||||||
"xdg-install", help=(
|
|
||||||
"Install launcher and icons for freedesktop systems. Run as root or with sudo for "
|
|
||||||
"system-wide install, or as user for single user install."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
cmdXDGInstall.set_defaults(func=xdgInstall)
|
|
||||||
|
|
||||||
# Linux XDG Uninstall
|
|
||||||
cmdXDGUninstall = parsers.add_parser(
|
|
||||||
"xdg-uninstall", help=(
|
|
||||||
"Remove the launcher and icons for the current system "
|
|
||||||
"as installed by the 'xdg-install' command."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
cmdXDGUninstall.set_defaults(func=xdgUninstall)
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
args.func(args)
|
args.func(args)
|
||||||
|
|||||||
Reference in New Issue
Block a user