File indexing completed on 2024-05-12 17:09:12

0001 #!/bin/env python3
0002 
0003 import os
0004 import sys
0005 import xml.dom.minidom
0006 from xml.dom.minidom import parse
0007 
0008 ########
0009 # This application loops through installed applets and extracts the config XML file
0010 # Output is then presented in mediawiki format for copying and pasting to https://userbase.kde.org/KDE_System_Administration/PlasmaDesktopScripting#Configuration_Keys
0011 
0012 # app should be kept flexible enough to port to a different format in future
0013 
0014 
0015 #set plasmoid installation path manually if applicable
0016 xdg_data_dir = ""
0017 
0018 if not xdg_data_dir:
0019     xdg_data_dirs = os.getenv("XDG_DATA_DIRS").split(":")
0020     xdg_data_dirs.append("/usr/share")
0021     xdg_data_dir = xdg_data_dirs[0]
0022 
0023 
0024 
0025 root = xdg_data_dir + "/plasma/plasmoids"
0026 
0027 plasmoids = os.listdir(root)
0028 plasmoids.sort()
0029 for plasmoid in plasmoids:
0030     configPath = "/contents/config/main.xml"
0031     path  = root + "/" + plasmoid + configPath
0032     try:
0033         dom = xml.dom.minidom.parse(path).documentElement
0034 
0035         print ("===" + plasmoid + "===")
0036         for group in dom.getElementsByTagName("group"):
0037             groupName = group.getAttribute("name")
0038             print ("======" + groupName + "======")
0039             for entry in group.getElementsByTagName("entry"):
0040                 name = entry.getAttribute("name")
0041                 type = entry.getAttribute("type")
0042                 default = ""
0043                 description = ""
0044 
0045                 if entry.hasAttribute("hidden") and entry.getAttribute("hidden") == "true":
0046                     continue
0047 
0048                 defaultTags = entry.getElementsByTagName("default")
0049                 if (defaultTags.length > 0 and defaultTags[0].childNodes.length > 0):
0050                     default = defaultTags[0].childNodes[0].data
0051 
0052                 if (default == ""):
0053                     if (type == "Bool"):
0054                         default = "false"
0055                     elif (type == "Int"):
0056                         default = "0"
0057                     elif (type == "StringList"):
0058                         default = "empty list"
0059                     elif (type == "String"):
0060                         default = "empty string"
0061                     else:
0062                         default = "null"
0063 
0064                 labelTags = entry.getElementsByTagName("label")
0065                 if (labelTags.length > 0 and labelTags[0].childNodes.length > 0):
0066                     description = labelTags[0].childNodes[0].data
0067 
0068 
0069                 print ("* '''%s''' (''%s'', default ''%s'') %s" % (name , type, default, description))
0070     except IOError:
0071         sys.stderr.write("No config in " + plasmoid +"\n")
0072     #abort on other errors so we can find them