File indexing completed on 2024-11-24 05:01:55

0001 #!/usr/bin/env python3
0002 
0003 # SPDX-FileCopyrightText: 2024 Nicolas Fella <nicolas.fella@gmx.de>
0004 # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 
0006 import re
0007 import io
0008 import subprocess
0009 
0010 # removes the full path from calendar plugin entries and only stores the plugin id, e.g.
0011 # /usr/lib64/qt5/plugins/plasmacalendarplugins/holidaysevents.so -> holidaysevents
0012 
0013 proc = subprocess.Popen(
0014     [
0015         "qtpaths",
0016         "--locate-file",
0017         "ConfigLocation",
0018         "plasma-org.kde.plasma.desktop-appletsrc",
0019     ],
0020     stdout=subprocess.PIPE,
0021 )
0022 for line in io.TextIOWrapper(proc.stdout, encoding="utf-8"):
0023     appletsrcPath = line.removesuffix("\n")
0024 
0025 if len(appletsrcPath) == 0 or not appletsrcPath.endswith("appletsrc"):
0026     # something is wrong
0027     exit()
0028 
0029 with open(appletsrcPath, "r+") as appletsrc:
0030     inputLines = appletsrc.readlines()
0031 
0032     outputLines = []
0033     pattern = re.compile("^\\/.*\\/(.*).so$")
0034 
0035     for line in inputLines:
0036         if not line.startswith("enabledCalendarPlugins="):
0037             outputLines += line
0038             continue
0039 
0040         inputPlugins = line.removeprefix("enabledCalendarPlugins=").split(",")
0041 
0042         outputPlugins = []
0043 
0044         for plugin in inputPlugins:
0045             match = pattern.match(plugin)
0046 
0047             if match:
0048                 outputPlugins.append(match.group(1))
0049             else:
0050                 outputPlugins += plugin
0051 
0052         outputLines += "enabledCalendarPlugins=" + ",".join(outputPlugins) + "\n"
0053 
0054     appletsrc.truncate(0)
0055     appletsrc.seek(0)
0056 
0057     appletsrc.writelines(outputLines)